huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
132.17k stars 26.33k forks source link

GenerationConfig is not handled correctly when saving multi-task models #33398

Closed B-Step62 closed 6 hours ago

B-Step62 commented 1 week ago

System Info

Who can help?

@ArthurZucker @Rocketknight1

Information

Tasks

Reproduction

  1. Load T5 model.

    model = T5ForConditionalGeneration.from_pretrained("t5-small")
  2. Construct a pipeline from it for inference

    pipe = transformers.pipeline(
    model=model,
    tokenizer=transformers.T5TokenizerFast.from_pretrained("t5-small", model_max_length=100), 
    task="translation_en_to_de"
    )
  3. Save the pretrained weight locally (typically after fine-tuning but doing it immediately for quick reproducing purpose)

    model.save_pretrained("/tmp/transformers/t5")
  4. The saved config.json file contains "early_stopping": null. This does not present in the original config.json file in the T5 model repository.

    {
    "_name_or_path": "t5-small",
    ...
    "early_stopping": null,
    }
  5. Model loading fails due to this null value.

    T5ForConditionalGeneration.from_pretrained("/tmp/transformers/t5")
    # >  ValueError: `early_stopping` must be a boolean or 'never', but is None.

A few side notes

Expected behavior

The saved config.json file should not contain the "early_stopping" key at top-level. It should be only defined under the task_specific_params like the original config.

LysandreJik commented 1 week ago

cc @gante regarding the generation config

gante commented 5 days ago

Hi @B-Step62 👋 Thank you for opening this issue!

Indeed, there are multiple issues here:

The question of the task_specific_params is a bit more tricky: the generation config is meant to replace them, but we do not have the authority to update all hub models :) Inside the pipeline code, we already load all task parameters into model.generation_config