huggingface / transformers

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

save_pretrained no longer works for AutomaticSpeechRecognitionPipeline #28162

Closed bruno-hays closed 10 months ago

bruno-hays commented 11 months ago

System Info

transformers-4.37.0.dev0

Who can help?

@Narsil

Information

Tasks

Reproduction

from transformers import pipeline

asr_pipeline = pipeline('automatic-speech-recognition',
                        model="openai/whisper-tiny")

asr_pipeline.save_pretrained("pipeline_save")

Gives this error:

Traceback (most recent call last):
  File "/Users/bruno/testing.py", line 6, in <module>
    asr_pipeline.save_pretrained("pipeline_save")
  File "/Users/bruno/venv/lib/python3.11/site-packages/transformers/pipelines/base.py", line 883, in save_pretrained
    if self.image_processor is not None:
       ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'AutomaticSpeechRecognitionPipeline' object has no attribute 'image_processor'

Expected behavior

The pipeline should be saved.

save_pretrained a pipeline is used by BentoML, as a result versions of transformers newer than 4.32.1 cannot be used to serve a AutomaticSpeechRecognitionPipeline with bentoML.

https://github.com/bentoml/BentoML/issues/4339

amyeroberts commented 11 months ago

Hi @Hubert-Bonisseur, thanks for raising this issue!

Indeed, this seems to be the result of two PRs - #25884 - which enables saving image processors in pipelines and #25438 which adapted ASR's pipeline's init.

cc @sanchit-gandhi who knows more about the decisions in #25438 and the reason for removing the super().__init__ call

sanchit-gandhi commented 10 months ago

Overriding the init was required to ensure we could correctly set ASR-specific decoding params when we instantiate the pipeline: https://github.com/huggingface/transformers/pull/25438#issuecomment-1676918766

Here's a PR to fix the save_pretrained functionality of the ASR pipeline: https://github.com/huggingface/transformers/pull/28486