Repository navigation
Fix RecurrentGemma padded generation by declaring its layer_types
#50577
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
Changes from 1 commit
c9db053
6820072
c655463
ba5a0d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -652,13 +652,17 @@ def forward( | |
| position_ids = torch.arange(hidden_states.shape[1], device=hidden_states.device) + past_seen_tokens | ||
| position_ids = position_ids.unsqueeze(0) | ||
|
|
||
| causal_mask = create_sliding_window_causal_mask( | ||
| config=self.config, | ||
| inputs_embeds=inputs_embeds, | ||
| attention_mask=attention_mask, | ||
| past_key_values=past_key_values, | ||
| position_ids=position_ids, | ||
| ) | ||
| # It may already have been prepared by e.g. `generate` | ||
| if isinstance(attention_mask, dict): | ||
| causal_mask = attention_mask["sliding_attention"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If recurrent blocks ignore the mask and only the attention blocks need the sliding window, please say so in the comment — but I'd still use
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the model is so old, that it would require too much effort to fix it up properly imo some of your initial points are more theoretical issues which are not really important |
||
| else: | ||
| causal_mask = create_sliding_window_causal_mask( | ||
| config=self.config, | ||
| inputs_embeds=inputs_embeds, | ||
| attention_mask=attention_mask, | ||
| past_key_values=past_key_values, | ||
| position_ids=position_ids, | ||
| ) | ||
|
|
||
| hidden_states = hidden_states * self.normalizer.type(hidden_states.dtype) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,13 @@ def test_assisted_decoding_matches_greedy_search(self): | |
| def test_left_padding_compatibility(self): | ||
| pass | ||
|
|
||
| @unittest.skip( | ||
| "RecurrentGemma's recurrent block has no chunked-continuation support: a cached multi-token forward is " | ||
| "treated as a new prefill, so the split-vs-single comparison cannot match regardless of padding masking." | ||
| ) | ||
| def test_recurrent_layers_mask_padding_on_continued_forward(self): | ||
| pass | ||
|
|
||
|
Comment on lines
+184
to
+190
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was skipped before. I don't want to handle this in the current PR.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea its expected tbh |
||
| @pytest.mark.generate | ||
| @unittest.skip(reason="Relies on `past_key_values` returned by the model. Not supported with recurrent gemma") | ||
| def test_assisted_decoding_sample(self): | ||
|
|
||
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.
hmm why not changed it directly in layers block types instead? Id like to avoid having so many layer types living side by side