Skip to content

fix: replace bare except with specific exception types in load_my_state_dict#185

Open
Mr-Neutr0n wants to merge 1 commit intonetease-youdao:mainfrom
Mr-Neutr0n:fix/load-state-dict-bare-except
Open

fix: replace bare except with specific exception types in load_my_state_dict#185
Mr-Neutr0n wants to merge 1 commit intonetease-youdao:mainfrom
Mr-Neutr0n:fix/load-state-dict-bare-except

Conversation

@Mr-Neutr0n
Copy link
Copy Markdown

Summary

  • Replace bare except: with except (RuntimeError, ValueError) as e: in PromptTTS.load_my_state_dict()
  • Log the actual exception message when a parameter fails to load

Problem

The load_my_state_dict() method in models/prompt_tts_modified/model_open_source.py uses a bare except: clause that:

  1. Catches all exceptions, including KeyboardInterrupt and SystemExit, making it impossible to interrupt the loading process with Ctrl+C
  2. Silently swallows shape mismatches — if a tensor has the wrong shape (e.g., due to an architecture change), the weight is quietly skipped with only a generic "{name} is not loaded" message and no details about why it failed
  3. The model then runs with randomly initialized weights for those layers, producing degraded outputs with no actionable warning

Fix

# Before
try:
    own_state[name].copy_(param)
except:
    print(f"{name} is not loaded")

# After
try:
    own_state[name].copy_(param)
except (RuntimeError, ValueError) as e:
    print(f"Warning: {name} is not loaded: {e}")

This change:

  • Only catches RuntimeError (shape mismatches from copy_()) and ValueError (dtype issues), allowing KeyboardInterrupt, SystemExit, and other unexpected exceptions to propagate normally
  • Includes the actual error message in the output so users can diagnose why a parameter was not loaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant