From: Anders Bjarby Date: Mon, 17 Mar 2025 07:41:05 +0000 (+0100) Subject: convert : update convert-h5-to-ggml.py (#2840) X-Git-Tag: upstream/1.7.5~140 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=4854789751aa3eed3bbe605a789cc34701b44f10;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp convert : update convert-h5-to-ggml.py (#2840) improved handling of missing max_length --- diff --git a/models/convert-h5-to-ggml.py b/models/convert-h5-to-ggml.py index 5474d586..4d50af46 100644 --- a/models/convert-h5-to-ggml.py +++ b/models/convert-h5-to-ggml.py @@ -85,9 +85,15 @@ encoder_added = json.load((dir_model / "added_tokens.json").open( "r", encoding= 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) - +if "max_length" not in hparams or hparams["max_length"] is None: + hparams["max_length"] = hparams.get("max_target_positions", 448) # Default to 448 if missing +elif not isinstance(hparams["max_length"], int): + try: + hparams["max_length"] = int(hparams["max_length"]) # Convert if necessary + except ValueError: + print(f"Warning: Invalid max_length value '{hparams['max_length']}', using default 448.") + hparams["max_length"] = 448 + model = WhisperForConditionalGeneration.from_pretrained(dir_model) #code.interact(local=locals())