Skip to content

Stamp weight dtype on GQA PackQKV Concat/Transpose intermediates - #435

Draft
justinchuby with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-concat-transpose-dtype
Draft

Stamp weight dtype on GQA PackQKV Concat/Transpose intermediates#435
justinchuby with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-concat-transpose-dtype

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

The PackQKVForGQA / PackQKVWithBiasForGQA rewrites build the packed weight with op.Concat / op.Transpose, whose output values carry no declared type. When those intermediates are later folded into initializers there is no declared dtype to inherit, so an fp16 model could end up with fp32 packed weights — the drop that #351 mitigated downstream.

The issue asked whether this still reproduces. It does. On main, a CPU-EP llama build gives:

Concat    node_Concat_0    [FLOAT, FLOAT, FLOAT] -> None
Transpose node_Transpose_1 [None]                -> None

Changes

  • _group_query_attention.py — new _propagate_dtype(source, *targets) helper resolves the source parameter's dtype through the existing initializer_dtype() (declared type, const_value fallback, fail-closed on mismatch) and stamps it on the rewrite-created values.
  • PackQKVForGQA.rewrite — stamps packed_w / packed_wt from q_w.
  • PackQKVWithBiasForGQA.rewrite — same, plus packed_bias from bias_q. The bias Concat folds into an initializer too and had the identical untyped-output problem, so it is covered here rather than left for a follow-up.
  • Tests — parameterized fp32/fp16 regression tests for both rewrite paths, asserting the Concat/Transpose/bias-Concat outputs declare the model dtype. They fail on unmodified source (assert None == FLOAT16).
packed_w = op.Concat(q_w, k_w, v_w, axis=0)
packed_wt = op.Transpose(packed_w, perm=[1, 0])
# Concat/Transpose outputs have no declared type; carry the weight dtype
# forward so the folded packed initializer keeps the model dtype.
_propagate_dtype(q_w, packed_w, packed_wt)

The #351 fold-pass stamping and const_value fallback are left untouched as defense-in-depth.

Note: the onnxruntime_easy collection blocker cited as the reason this was deferred from #351 no longer applies — it ships in the testing extra, so src/mobius/rewrite_rules/_group_query_attention_test.py runs directly.

Copilot AI review requested due to automatic review settings July 30, 2026 05:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

The PackQKV rewrite built the packed QKV weight with `op.Concat` /
`op.Transpose`, whose output values carry no declared type. When those
intermediates were folded into initializers, there was no declared dtype
to inherit, so fp16 weights could be widened to fp32 (mitigated
downstream in #351 by const_value fallback + fold-pass stamping).

Verified the issue still reproduces on main (packed Concat/Transpose
outputs had `dtype is None`) and fixed it at the source: propagate the
projection weight dtype (and bias dtype for the biased path) onto the
new intermediates in both PackQKV rewrite sites. The downstream
mitigation is kept as defense-in-depth.
Copilot AI review requested due to automatic review settings July 30, 2026 05:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI changed the title [WIP] Fix dtype declaration for Concat/Transpose intermediates in PackQKV rewrite Stamp weight dtype on GQA PackQKV Concat/Transpose intermediates Jul 30, 2026
Copilot AI requested a review from justinchuby July 30, 2026 05:13
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.

GQA PackQKV rewrite leaves Concat/Transpose intermediates without a declared dtype

4 participants