Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: raise TypeError if config field does not match declared type #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

eginhard
Copy link
Member

@eginhard eginhard commented Jan 10, 2025

Currently field values are parsed even if their type doesn't match the field's declared type. This avoids errors, but doesn't allow correct parsing of union type fields (e.g. list[str] | list[list[str]]) which would rely on mismatched values to be rejected.

This PR enforces stricter parsing, thus allowing correct parsing of union type fields. It reveals some incorrectly declared types in Coqui configs, e.g. steps_to_start_discriminator: bool = 200000 that will be fixed in a PR before switching to the new Coqpit version. This results in some configs of pretrained models now having mismatched values, e.g. "steps_to_start_discriminator": true, in vocoder_models/en/ljspeech/multiband-melgan. Coqpit now recognises these mismatches and replaces the value with the field's default value, emitting a warning on the first use:

UserWarning: Type mismatch in MultibandMelganConfig
  Failed to deserialize field: steps_to_start_discriminator (<class 'int'>) = True
  Replaced it with field's default value: 200000
    self.deserialize(data)

This ensures that all pretrained Coqui models can still be used as is (https://github.com/idiap/coqui-ai-TTS/actions/runs/12724541599).

@eginhard eginhard force-pushed the union branch 2 times, most recently from 7c397c8 to b549b44 Compare January 11, 2025 13:13
This makes parsing stricter and could result in errors in some existing
configs. However, it allows for more precise deserialization, especially in case
of union types.
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