Skip to content

T5 translation fails when the engine adds a translation prefix #385

Description

@ddaspit

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      🔖 Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions