Skip to content

Commit 8043c23

Browse files
committed
revert to better pad token handling logic
1 parent 40aa479 commit 8043c23

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

optimum/exporters/onnx/__main__.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,14 @@ def main_export(
409409
and getattr(model.config, "pad_token_id", None) is None
410410
)
411411

412-
if needs_pad_token_id:
413-
if pad_token_id is not None:
414-
model.config.pad_token_id = pad_token_id
415-
else:
416-
try:
417-
tok = AutoTokenizer.from_pretrained(model_name_or_path)
418-
model.config.pad_token_id = tok.pad_token_id
419-
except Exception:
420-
raise ValueError(
421-
"Could not infer the pad token id, which is needed in this case, please provide it with the --pad_token_id argument"
422-
)
412+
if needs_pad_token_id and pad_token_id is None:
413+
tok = AutoTokenizer.from_pretrained(model_name_or_path)
414+
pad_token_id = getattr(tok, "pad_token_id", None)
415+
if pad_token_id is None:
416+
raise ValueError(
417+
"Could not infer the pad token id, which is needed in this case, please provide it with the --pad_token_id argument"
418+
)
419+
model.config.pad_token_id = pad_token_id
423420

424421
model_type = "stable-diffusion" if "stable-diffusion" in task else model.config.model_type.replace("_", "-")
425422
if (

0 commit comments

Comments
 (0)