HuggingFaceNmtEngine cannot translate with a T5 or mT5 model when it adds a translation prefix. The engine adds one when the model name starts with t5- or google/mt5- and src_lang and tgt_lang are set. Every translate call then raises a ValueError.
Affected: HuggingFaceNmtEngine and the translation pipeline in machine/translation/huggingface/hugging_face_nmt_engine.py.
Versions: reproduced on #363 (transformers 5.14.1, Python 3.10, Windows 11, huggingface extra). On main (transformers 4.47.1), I confirmed it by reading the source, not by running it.
Input:
engine = HuggingFaceNmtEngine(
"hf-internal-testing/tiny-random-T5ForConditionalGeneration", prefix="translate English to German: "
)
engine.translate("Hello world")
Expected: the prefix is added to the source text, and the segment is translated.
Actual: ValueError: The following model_kwargs are not used by the model: ['prefix']
Cause: _sanitize_parameters does not handle prefix, so it is forwarded to generate. The pipeline only reads its prefix from self.prefix, which comes from the model config. transformers 4.47.1 has the same gap.
Test: no test translates with a T5 model and a prefix. A test using the tiny T5 model with a prefix argument would catch it.
HuggingFaceNmtEnginecannot translate with a T5 or mT5 model when it adds a translation prefix. The engine adds one when the model name starts witht5-orgoogle/mt5-andsrc_langandtgt_langare set. Every translate call then raises aValueError.Affected:
HuggingFaceNmtEngineand the translation pipeline inmachine/translation/huggingface/hugging_face_nmt_engine.py.Versions: reproduced on #363 (transformers 5.14.1, Python 3.10, Windows 11,
huggingfaceextra). Onmain(transformers 4.47.1), I confirmed it by reading the source, not by running it.Input:
Expected: the prefix is added to the source text, and the segment is translated.
Actual:
ValueError: The following model_kwargs are not used by the model: ['prefix']Cause:
_sanitize_parametersdoes not handleprefix, so it is forwarded togenerate. The pipeline only reads its prefix fromself.prefix, which comes from the model config. transformers 4.47.1 has the same gap.Test: no test translates with a T5 model and a prefix. A test using the tiny T5 model with a
prefixargument would catch it.