From 9dc614abf6f55a3fea27a64bf77ef5d081b928e5 Mon Sep 17 00:00:00 2001 From: Anders Bjarby <102783063+fltman@users.noreply.github.com> Date: Mon, 24 Feb 2025 18:59:29 +0100 Subject: [PATCH] Update convert-h5-to-ggml.py improved handling of missing max_length --- models/convert-h5-to-ggml.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/models/convert-h5-to-ggml.py b/models/convert-h5-to-ggml.py index 5474d58613a..4d50af46428 100644 --- a/models/convert-h5-to-ggml.py +++ b/models/convert-h5-to-ggml.py @@ -85,9 +85,15 @@ def bytes_to_unicode(): 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())