Skip to content
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

Fix case of nested tensors in BatchMixFeature #35063

Closed
wants to merge 9 commits into from

Conversation

Rocketknight1
Copy link
Member

@Rocketknight1 Rocketknight1 commented Dec 3, 2024

Huge kudos to @zucchini-nlp for figuring this one out - we were getting intermittent failures and I couldn't figure out why. The reason was that BatchMixFeature.to() was breaking the structure of some inputs, because it used a nested list comprehension that assumed a specific list depth that wasn't always respected by PixtralProcessor.

This PR replaces the slightly hacky .to() code with a recursion that should preserve nesting structure regardless of list depth.

TODO:

  • Compare against the VLLM implementation of Pixtral to see how they handle this (if their code supports batched?)

@qubvel
Copy link
Member

qubvel commented Dec 3, 2024

Hey @Rocketknight1! There is a PR that might be relevant in terms of how args/kwargs are propagated

P.S. didn't notice it's a model-related change only, so might be not relevant

@Rocketknight1
Copy link
Member Author

@qubvel thanks for letting me know regardless, since we might make the same change in BatchFeature! The two PRs shouldn't conflict much, though - if you merge yours first, I can just rebase and incorporate those changes afterwards.

@Rocketknight1
Copy link
Member Author

Note - this PR should not be merged yet, as I believe the issue in .to() was actually masking the fact that Processor outputs don't match the expectations of our Pixtral modelling code!

@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.

@Rocketknight1 Rocketknight1 force-pushed the pixtral_batchmixfeature_fix branch from b74f736 to 8e07742 Compare December 5, 2024 17:58
@Rocketknight1
Copy link
Member Author

cc @ArthurZucker @LysandreJik for core maintainer review, this one should be ready!

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

Copy link
Collaborator

Choose a reason for hiding this comment

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

these tests should be in the image processing / processing but alrights, thanks! 🤗

@@ -66,10 +66,24 @@ def to(self, *args, **kwargs) -> "BatchMixFeature":
Returns:
[`BatchFeature`]: The same instance after modification.
"""

def _recursive_to(obj, device, *args, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's actually cleaner!

@Rocketknight1
Copy link
Member Author

Closing because this change is included in #34801 instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants