Fix batched generation which is dependent on left padding - BREAKING! 😮💨#5
Open
vasqu wants to merge 1 commit into
Open
Fix batched generation which is dependent on left padding - BREAKING! 😮💨#5vasqu wants to merge 1 commit into
vasqu wants to merge 1 commit into
Conversation
…t's breaking the previous behaviour with the tokenizer also supports a special case for right padding --> return the correct last ssm state even within a batch
vasqu
commented
Sep 26, 2024
Comment on lines
+812
to
+817
| if ( | ||
| model_kwargs.get("use_cache", True) | ||
| and "cache_position" in model_kwargs | ||
| and model_kwargs["cache_position"] is not None | ||
| ): | ||
| model_kwargs["cache_position"] = model_kwargs["cache_position"][-1:] + num_new_tokens |
Owner
Author
There was a problem hiding this comment.
We could likely ignore cache_position as it's used for the cache to be torch compile compatible but since the mamba2 kernel can't really compile either way...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I will probably not merge this PR but keep it as is. It fixes a huge issue within mamba-related models: Generation with padding. This is due to the fact that the eos token is used as pad token which results in unwanted repeated influence of it.
This fix requires the tokenizer to be left padding. But, for right padding, there is an interesting use case to enable correct last ssm states even with padding. See the tests...