Fix GraniteMoeHybrid _update_mamba_mask crash on attention-only models#45514
Open
tianhaocui wants to merge 1 commit intohuggingface:mainfrom
Open
Fix GraniteMoeHybrid _update_mamba_mask crash on attention-only models#45514tianhaocui wants to merge 1 commit intohuggingface:mainfrom
tianhaocui wants to merge 1 commit intohuggingface:mainfrom
Conversation
When all layers are attention layers (no mamba layers), _update_mamba_mask calls past_key_values.has_previous_state() which tries to find a LinearAttentionCacheLayerMixin layer. Since none exist, it raises ValueError. Skip the has_previous_state check entirely when the model has no mamba layers, as the mamba mask optimization is irrelevant in that case. Fixes huggingface#45507
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: granitemoehybrid |
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.
Fixes #45507
Summary
GraniteMoeHybridModel._update_mamba_maskcallspast_key_values.has_previous_state()without checking whether the model actually has mamba layers. When all layers are attention-only (no mamba layers inconfig.layers_block_type),has_previous_state()fails to find aLinearAttentionCacheLayerMixinlayer and raisesValueError.Fix
Check
config.layers_block_typefor mamba layers before callinghas_previous_state(). If no mamba layers exist, return the attention mask as-is since the mamba mask optimization is irrelevant.Applied to both
modeling_granitemoehybrid.pyandmodular_granitemoehybrid.py.