convert : handle max_target_positions (#2477)

as needed eg for
https://huggingface.co/primeline/whisper-large-v3-turbo-german/blob/main/config.json
This commit is contained in:
CrispStrobe 2024-10-14 09:46:33 +02:00 committed by GitHub
parent 746d173592
commit 06a1da9daf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,7 +82,11 @@ dir_out = Path(sys.argv[3])
encoder = json.load((dir_model / "vocab.json").open("r", encoding="utf8")) encoder = json.load((dir_model / "vocab.json").open("r", encoding="utf8"))
encoder_added = json.load((dir_model / "added_tokens.json").open( "r", encoding="utf8")) encoder_added = json.load((dir_model / "added_tokens.json").open( "r", encoding="utf8"))
hparams = json.load((dir_model / "config.json").open("r", encoding="utf8") ) hparams = json.load((dir_model / "config.json").open("r", encoding="utf8"))
# Add this block to handle missing 'max_length'
if "max_length" not in hparams:
hparams["max_length"] = hparams.get("max_target_positions", 448)
model = WhisperForConditionalGeneration.from_pretrained(dir_model) model = WhisperForConditionalGeneration.from_pretrained(dir_model)