You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 73dc483
Browse filesBrowse the repository at this point in the historyBrowse files
Fix EP-capability gating bypass in DeepSeek-V4 GQA fusion
The previous commit (d2d5596) unconditionally emitted
com.microsoft::GroupQueryAttention regardless of the target execution
provider, bypassing this codebase's established EP-capability gating
convention. mobius/_execution_providers.py deliberately declares
gqa_dtypes=frozenset() for "default" (used whenever no
execution_provider kwarg is passed -- essentially all existing tests
and consumers), "onnx-standard", "qnn", and "openvino" specifically to
guarantee their exported graphs stay free of com.microsoft custom ops.
Since build_from_module defaults to execution_provider="default", the
prior commit silently broke that portability contract for every
default-EP DeepSeek-V4 build.
Add _use_fused_gqa(), mirroring TextModel.forward's use_gqa gate
(mobius/models/base.py) via ep_capabilities()/get_build_dtype(), and
branch DeepSeekV4Attention.forward between the fused GroupQueryAttention
path (unchanged from d2d5596, used only when the active EP declares GQA
support for the build dtype) and a restored portable decomposed path
(manual Transpose/Concat/MatMul/Softmax + explicit attention_bias +
attention-sink Concat/slice, byte-identical to the pre-fusion
implementation). seqlens_k/total_seq_len (fused) and attention_bias
(decomposed) are threaded through DeepSeekV4DecoderLayer.forward,
DeepSeekV4TextModel.forward, and DeepSeekV4Mtp.forward, with exactly one
of the two computed per build based on _use_fused_gqa().
V4's gate omits base.py's caps.supports_fused_rope check: RoPE is
always applied explicitly in-graph via _rotate in both paths (do_rotary
stays at its default/off), so there's no fused-rotary mode being
requested that could be EP-unsupported.
Test changes in deepseek_v4_flash_test.py:
- test_tiny_graph_builds_v4_backbone,
test_csa_schedule_exports_compressor_and_indexer_tensors_with_dense_attention,
and test_mtp_sidecar_exports_official_block_and_hyper_connection_state
now assert GroupQueryAttention count == 0 under the default EP (in
addition to their original decomposed-path assertions), proving the
portability contract holds.
- Three new tests build the same tiny configs with
execution_provider="cpu" (whose gqa_dtypes={FLOAT} matches the tiny
config's default dtype) and assert the fused-GQA structural
properties previously (incorrectly) asserted unconditionally: node
count == num_hidden_layers, com.microsoft domain, 12-input arity with
attention_bias unset and head_sink populated, and halved Softmax count
(only the Hyper-Connection combination softmax remains).
Reviewed independently via a code-review sub-agent (verdict: APPROVE),
which byte-diffed both branches against the pre-fusion and prior-commit
implementations and confirmed plumbing/argument-order consistency and
that the new EP-gated tests genuinely exercise the fused path.
All 14 tests in deepseek_v4_flash_test.py pass; ruff check/format clean.
Co-authored-by: Copilot <[email protected]>
0 commit comments