Stamp weight dtype on GQA PackQKV Concat/Transpose intermediates - #435
Draft
justinchuby with Copilot wants to merge 2 commits into
Draft
Stamp weight dtype on GQA PackQKV Concat/Transpose intermediates#435justinchuby with Copilot wants to merge 2 commits into
justinchuby with Copilot wants to merge 2 commits into
Conversation
|
|
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
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
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.
The
PackQKVForGQA/PackQKVWithBiasForGQArewrites build the packed weight withop.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:Changes
_group_query_attention.py— new_propagate_dtype(source, *targets)helper resolves the source parameter's dtype through the existinginitializer_dtype()(declared type,const_valuefallback, fail-closed on mismatch) and stamps it on the rewrite-created values.PackQKVForGQA.rewrite— stampspacked_w/packed_wtfromq_w.PackQKVWithBiasForGQA.rewrite— same, pluspacked_biasfrombias_q. The biasConcatfolds into an initializer too and had the identical untyped-output problem, so it is covered here rather than left for a follow-up.Concat/Transpose/bias-Concatoutputs declare the model dtype. They fail on unmodified source (assert None == FLOAT16).The #351 fold-pass stamping and
const_valuefallback are left untouched as defense-in-depth.Note: the
onnxruntime_easycollection blocker cited as the reason this was deferred from #351 no longer applies — it ships in thetestingextra, sosrc/mobius/rewrite_rules/_group_query_attention_test.pyruns directly.