Skip to content

Commit

Permalink
feat: added a friendlier error message when providing the wrong model…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
SamuelLarkin committed Oct 2, 2024
1 parent d42ee87 commit f9df18d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion fs2/cli/synthesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,16 @@ def synthesize( # noqa: C901

# Load checkpoints
print(f"Loading checkpoint from {model_path}", file=sys.stderr)
model: FastSpeech2 = FastSpeech2.load_from_checkpoint(model_path).to(device) # type: ignore

from pydantic import ValidationError

try:
model: FastSpeech2 = FastSpeech2.load_from_checkpoint(model_path).to(device) # type: ignore
except (TypeError, ValidationError) as e:
# TODO: should we print the following message only if there are more than X validation errors?
# e.error_count() > X
logger.error(f"Unable to load {model_path}: {e}")
sys.exit(1)
model.eval()

# get global step
Expand Down
11 changes: 10 additions & 1 deletion fs2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ def __init__(
""" """
super().__init__()
if not isinstance(config, FastSpeech2Config):
config = FastSpeech2Config(**config)
from pydantic import ValidationError

try:
config = FastSpeech2Config(**config)
except ValidationError as e:
logger.error(f"{e}")
raise TypeError(
"Unable to load config. Possible causes: is it really a FastSpeech2Config? or the correct version?"
)

if stats is not None and not isinstance(stats, Stats):
stats = Stats(**stats)
self.config = config
Expand Down

0 comments on commit f9df18d

Please sign in to comment.