Open gcervantes8 opened 1 month ago
As a quick fix, add these lines right before saving the model:
del model.config.__dict__["max_length"]
del model.config.__dict__["suppress_tokens"]
del model.config.__dict__["begin_suppress_tokens"]
Fixing the problem in terms of design is a bit tricky. The main problem here is that WhisperForAudioClassification
still takes a more-than-necessary WhisperConfig
as input, which contains generation parameters too. Then, when it's time to save the model, the logic that takes care of raising errors in case of non-default generation parameters does not care about whether the model actually needs those parameters or not.
Here are some solutions I thought of:
WhisperForAudioClassification
take care of patching the config by removing the fields it does not need. Hacky but simple.WhisperEncoderConfig
that does not contain the generation fields. Would need to look into how this would relate to the existing WhipserConfig
class.Thanks the quick fix did fix the issue for me.
I'm not sure which of those 2 solutions is better for a long-term fix, but they both make sense.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Hey @gcervantes8, thanks for opening this issue. And thanks @niqodea for the quick fix and proposing some solutions.
I'm not sure the two proposed solutions will work here, notably because we don't want to introduce edge cases directly in the code, and because adding another config won't be backward compatible easily and will be too much of a hassle to be worth it.
The issue here happens because a model used for generation was used to initialize a model used for classification. It makes sense to log a warning, but I'm not sure to understand why we raise an error. @ArthurZucker or @Rocketknight1 , do you think we could/should raise a warning instead of an error?
cc @gante for a generation config question, I think!
System Info
transformers
version: 4.45.1Who can help?
Tagging Speech team: @ylacombe @eustlb and @gante since pull request #32863 seems very relevant, so they might have good insight
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
I'm trying to use the latest Transformers version (4.45.1) but I am getting an error when trying to save a
WhisperForAudioClassification
model.Here is an example of the code that fails.
This is the error that I am getting.
This is reproducible code that gives me this error. I am trying to actually fine-tune the model and when I use the Trainer to train, every time it tries to save the model, it fails.
The way I understand it, when I create/instantiate the model, it will get all get config and generationconfigs from the Whisper pretrained model. The Whisper Scoring model only uses the Encoder, so all the generationconfigs are useless to it, but I can't figure out how to remove them or never load them.
The other option I was thinking of was to somehow move them to model.generation_config by modifying the WhisperScoringModel class or to move them to a GenerationConfig and save it to a file, but I'm not sure how I would avoid the error with that.
Thank you for the help!
Expected behavior
Saving without an error.