-
Notifications
You must be signed in to change notification settings - Fork 31.2k
Fix incorrect batching audio index calculation for Phi-4-Multimodal #38103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
| speech_inputs = [floats_list((1, x))[0] for x in range(800, 1400, 200)] | ||
| np_speech_inputs = [np.asarray(speech_input) for speech_input in speech_inputs] | ||
| pt_speech_inputs = [torch.tensor(speech_input) for speech_input in speech_inputs] | ||
|
|
||
| # Test feature size | ||
| input_features = feature_extractor(np_speech_inputs, return_tensors="np").audio_input_features | ||
| max_audio_len = (1200 - feature_extractor.win_length) // feature_extractor.hop_length + 1 | ||
| self.assertTrue(input_features.ndim == 3) | ||
| self.assertTrue(input_features.shape[-1] == feature_extractor.feature_size) | ||
| self.assertTrue(input_features.shape[-2] == max_audio_len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have confirmed this test can cover the original bug without fix, so I didn't add extra regression test:
> masked_frames = frames[to_mask_batch_idxs, offset_idx:max_idx].masked_fill_(mask, 0)
E RuntimeError: The size of tensor a (3) must match the size of tensor b (4) at non-singleton dimension 1
src/transformers/models/phi4_multimodal/feature_extraction_phi4_multimodal.py:312: RuntimeError
================================================================== short test summary info ==================================================================
FAILED tests/models/phi4_multimodal/test_feature_extractor_phi4_multimodal.py::Phi4MultimodalFeatureExtractionTest::test_call - RuntimeError: The size of tensor a (3) must match the size of tensor b (4) at non-singleton dimension 1
Signed-off-by: Isotr0py <2037008807@qq.com>
ArthurZucker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, let's be explicit as python can hold surprises!
src/transformers/models/phi4_multimodal/feature_extraction_phi4_multimodal.py
Outdated
Show resolved
Hide resolved
…4_multimodal.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
What does this PR do?
Fixes #38098 (issue)
Just notice there is no feature extractor test for Phi-4-MM, let me add one for it, so mark this as draft currently.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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.