Skip to content

fix: restore dict return type in create_masks_for_generate (#46962)#47267

Open
davidnichols-ops wants to merge 2 commits into
huggingface:mainfrom
davidnichols-ops:fix/qwen3-create-masks-return-type-46962
Open

fix: restore dict return type in create_masks_for_generate (#46962)#47267
davidnichols-ops wants to merge 2 commits into
huggingface:mainfrom
davidnichols-ops:fix/qwen3-create-masks-return-type-46962

Conversation

@davidnichols-ops

@davidnichols-ops davidnichols-ops commented Jul 12, 2026

Copy link
Copy Markdown

CI

Summary

  • PR Fix several bugs in cache_implementation=static #46446 added an early return return attention_mask in create_masks_for_generate when any layer_type is not in LAYER_PATTERN_TO_MASK_FUNCTION_MAPPING. This broke the dict return type contract that models like Qwen3, Cohere2, Bamba, DeepseekV32, etc. rely on via isinstance(attention_mask, dict), causing unnecessary mask recomputation and performance regression (issue [Qwen3] create_masks_for_generate return type change after #41251 #46962).
  • Replaced the early return with inline handling: unmapped types get the raw attention_mask as their dict value, so the model still receives a dict and can use pre-computed masks for mapped types while deferring to the model for unmapped types.
  • Net-negative: 2 insertions, 4 deletions.

Deleted: the early return if any(layer_type not in ...): return attention_mask (3 lines) — replaced with a .get() + conditional in the existing loop, preserving the dict return type contract that all hybrid models depend on.

Test plan

  • Single layer type (all full_attention) → returns dict with full_attention key (was bare value before)
  • Mixed layer types (full_attention + sliding_attention) → returns dict with both keys
  • No layer_types attribute → returns bare value (unchanged behavior)
  • Full Qwen3 model test suite (requires GPU)

Generated with Devin

davidnichols-ops and others added 2 commits July 11, 2026 22:57
…types (huggingface#46962)

PR huggingface#46446 added an early return `return attention_mask` when any layer_type
is not in LAYER_PATTERN_TO_MASK_FUNCTION_MAPPING. This broke the dict return
type contract that models like Qwen3 rely on via `isinstance(attention_mask,
dict)`, causing unnecessary mask recomputation and performance regression.

Replace the early return with inline handling: unmapped types get the raw
attention_mask as their dict value, so the model still receives a dict and
can use pre-computed masks for mapped types.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The test expected the old bare-tensor return when any layer_type was
unmapped, but PR huggingface#47267 changed create_masks_for_generate to always
return a dict when layer_types exists (preserving the contract that
hybrid models rely on via isinstance(attention_mask, dict)). Update the
assertions to verify the dict has the correct keys, unmapped types
defer the raw mask, and mapped types get pre-computed masks.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 29197596016:2
Result: failure | Jobs: 15 | Tests: 152,657 | Failures: 0 | Duration: 14h 1m

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.

1 participant