Skip to content

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

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

davidnichols-ops wants to merge 3 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 3 commits July 11, 2026 22:57
…types (#46962)

PR #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 #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>
The previous CI run had 0 test failures out of 152,657 tests. The only
failing job was examples_torch, which exited with code 137 (OOM kill)
during test_generation — a runner memory issue unrelated to this PR.

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: 29203277893:2
Result: success | Jobs: 15 | Tests: 170,764 | Failures: 0 | Duration: 14h 27m

@davidnichols-ops
davidnichols-ops deleted the fix/qwen3-create-masks-return-type-46962 branch July 13, 2026 12:53
@davidnichols-ops

davidnichols-ops commented Jul 13, 2026 •

Copy link
Copy Markdown
Author

Thanks for taking a look. Could you share the reason for closing this? If there’s a technical issue with the approach or if it doesn’t align with project policy, I’d appreciate the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants