Skip to content

Conversation

@kho
Copy link
Contributor

@kho kho commented Nov 6, 2025

What does this PR do?

Correctly handle unbatched audio inputs in Gemma3nAudioFeatureExtractor

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@RyanMullins
Copy link
Contributor

Thanks for sending this fix @kho!

@RyanMullins
Copy link
Contributor

cc @zucchini-nlp @Rocketknight1 for a review to help us land this for Gemma 3n.

Comment on lines 308 to 314
if is_batched:
raw_speech = [np.asarray([rs]).T for rs in raw_speech]
elif not is_batched and not isinstance(raw_speech, np.ndarray):
raw_speech = np.asarray(raw_speech)

if not is_batched: # always return a batch
raw_speech = [np.asarray([raw_speech])]
raw_speech = [np.asarray([raw_speech]).T]
Copy link
Member

@zucchini-nlp zucchini-nlp Nov 7, 2025

Choose a reason for hiding this comment

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

not very related to this PR, but let's unify a bit these blocks for easier reading, maybe smth like below. Otherwise LGTM

        if not is_batched:
            raw_speech = [np.asarray(raw_speech)]
        raw_speech = [np.asarray([rs]).T for rs in raw_speech]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I just realized that we also don't need the np.asarray() call in the if statement. PTAL and thanks for reviewing!

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: gemma3n

Copy link
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.

LGTM

@zucchini-nlp zucchini-nlp enabled auto-merge (squash) November 10, 2025 08:36
@zucchini-nlp zucchini-nlp merged commit 926c37a into huggingface:main Nov 10, 2025
18 checks passed
@HuggingFaceDocBuilderDev

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.

Abdennacer-Badaoui pushed a commit to Abdennacer-Badaoui/transformers that referenced this pull request Nov 10, 2025
…or (huggingface#42076)

* Correctly handle unbatched audio inputs in Gemma3nAudioFeatureExtractor

* Simplify the logic for batching the unbatched speech input in Gemma3nAudioFeatureExtractor
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.

4 participants