Skip to content

Remove num_frames in ASR pipeline#43546

Merged
zucchini-nlp merged 7 commits intohuggingface:mainfrom
jiqing-feng:asr
Feb 3, 2026
Merged

Remove num_frames in ASR pipeline#43546
zucchini-nlp merged 7 commits intohuggingface:mainfrom
jiqing-feng:asr

Conversation

@jiqing-feng
Copy link
Copy Markdown
Contributor

Script:

import torch
from transformers import pipeline
from datasets import load_dataset

device = "cuda:0" if torch.cuda.is_available() else "cpu"
pipe = pipeline(
  "automatic-speech-recognition",
  model="openai/whisper-small",
  device=device,
)
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = ds[0]["audio"]
prediction = pipe(sample, batch_size=8)["text"]

error:

Traceback (most recent call last):
  File "/home/jiqing/HuggingFace/tests/workloads/test_whisper.py", line 16, in <module>
    prediction = pipe(sample, batch_size=8)["text"]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/automatic_speech_recognition.py", line 266, in __call__
    return super().__call__(inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/base.py", line 1266, in __call__
    return next(
           ^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/pt_utils.py", line 126, in __next__
    item = next(self.iterator)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/pt_utils.py", line 271, in __next__
    processed = self.infer(next(self.iterator), **self.params)
                           ^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 741, in __next__
    data = self._next_data()
           ^^^^^^^^^^^^^^^^^                                                                                                           File "/opt/venv/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 801, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/torch/utils/data/_utils/fetch.py", line 35, in fetch
    data.append(next(self.dataset_iter))
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/pt_utils.py", line 188, in __next__                                         processed = next(self.subiterator)
                ^^^^^^^^^^^^^^^^^^^^^^                                                                                                 File "/home/jiqing/transformers/src/transformers/pipelines/automatic_speech_recognition.py", line 486, in preprocess                   extra["num_frames"] = processed.pop("num_frames")
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen _collections_abc>", line 945, in pop
  File "/home/jiqing/transformers/src/transformers/feature_extraction_utils.py", line 90, in __getitem__
    return self.data[item]
           ~~~~~~~~~^^^^^^
KeyError: 'num_frames'

This change can fix this error by returning None if there is no num_frames in processors.

@jiqing-feng jiqing-feng changed the title fix asr pipeline pop fix processor pop in ASR pipeline Jan 28, 2026
@jiqing-feng jiqing-feng marked this pull request as ready for review January 28, 2026 07:44
@jiqing-feng
Copy link
Copy Markdown
Contributor Author

Hi @zucchini-nlp . Would you please review this PR? Thanks!

Comment thread src/transformers/pipelines/automatic_speech_recognition.py Outdated
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
@jiqing-feng jiqing-feng changed the title fix processor pop in ASR pipeline Remove num_frames in ASR pipeline Jan 29, 2026
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Comment thread src/transformers/pipelines/automatic_speech_recognition.py Outdated
Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The CI is a bit flaky, i'll retrigger and merge

@zucchini-nlp zucchini-nlp enabled auto-merge (squash) February 2, 2026 09:06
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@jiqing-feng
Copy link
Copy Markdown
Contributor Author

Hi @zucchini-nlp . The CI seems ok now.

@zucchini-nlp zucchini-nlp merged commit bdc583d into huggingface:main Feb 3, 2026
25 checks passed
@jiqing-feng jiqing-feng deleted the asr branch April 20, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants