Skip to content

Commit 4854789

Browse files
authored
convert : update convert-h5-to-ggml.py (#2840)
improved handling of missing max_length
1 parent e0f3c9d commit 4854789

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

models/convert-h5-to-ggml.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ def bytes_to_unicode():
8585
hparams = json.load((dir_model / "config.json").open("r", encoding="utf8"))
8686

8787
# Add this block to handle missing 'max_length'
88-
if "max_length" not in hparams:
89-
hparams["max_length"] = hparams.get("max_target_positions", 448)
90-
88+
if "max_length" not in hparams or hparams["max_length"] is None:
89+
hparams["max_length"] = hparams.get("max_target_positions", 448) # Default to 448 if missing
90+
elif not isinstance(hparams["max_length"], int):
91+
try:
92+
hparams["max_length"] = int(hparams["max_length"]) # Convert if necessary
93+
except ValueError:
94+
print(f"Warning: Invalid max_length value '{hparams['max_length']}', using default 448.")
95+
hparams["max_length"] = 448
96+
9197
model = WhisperForConditionalGeneration.from_pretrained(dir_model)
9298

9399
#code.interact(local=locals())

0 commit comments

Comments
 (0)