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: Mamba2 generation mismatch between input_ids and inputs_embeds #32694

Merged
merged 2 commits into from
Aug 19, 2024

Conversation

vasqu
Copy link
Contributor

@vasqu vasqu commented Aug 14, 2024

What does this PR do?

Fixes the failing generation test in mamba2 comparing the generation between passing input ids or passing the embeds directly. The cause of the mismatch was a false calculation of past_len which can be solved by changing the if check slightly.

Fixes #32555

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.

@molbap @ArthurZucker

@vasqu
Copy link
Contributor Author

vasqu commented Aug 14, 2024

Lmk if there's a better way to do this but I think this should be ok. At least the cause of the issue is apparent now.

@molbap
Copy link
Contributor

molbap commented Aug 16, 2024

That's a nice fix, thanks! I wonder if we can use cache_position instead, it would be cleaner/more aligned with the rest of the lib, other that that LGTM

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.

Can you add a small test. They exist for other model in the Mixin, https://github.com/huggingface/transformers/blob/main/tests/test_modeling_common.py#L2777 should be tested for mamba models

if input_ids.shape[1] == 0:
past_len = inputs_embeds.shape[1]
if inputs_embeds is not None:
past_len = inputs_embeds.shape[1] + input_ids.shape[1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is no longer the past length, but the current length 😉 Otherwise as this is used to create the cache positions, this is valid 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough :p

@vasqu
Copy link
Contributor Author

vasqu commented Aug 16, 2024

@ArthurZucker Isn't it also tested for all mamba-related models already? I've run the mamba2 tests locally for example and the test you linked was included in them (can also be seen in the CI of this PR over here).

Maybe I've misunderstood something 😅 Could you clarify the test?

@ArthurZucker
Copy link
Collaborator

You are right I forgot that it was failing ever since we added it!

@ArthurZucker ArthurZucker merged commit 61d89c1 into huggingface:main Aug 19, 2024
21 checks passed
@ArthurZucker
Copy link
Collaborator

Thanks @vasqu for maintaining mamba2 😉

@vasqu vasqu deleted the mamba2-input-ids-embeddings-fix branch August 19, 2024 14:13
@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.

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.

Mamba2 has different generations from input_ids and input_embeds
4 participants