Commit 3dc671c
Stamp weight dtype on GQA PackQKV Concat/Transpose intermediates (#435)
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`).
```python
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.
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #355
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>1 parent 95c442e commit 3dc671c
2 files changed
Lines changed: 72 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
52 | 73 | | |
53 | 74 | | |
54 | 75 | | |
| |||
364 | 385 | | |
365 | 386 | | |
366 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
367 | 391 | | |
368 | 392 | | |
369 | 393 | | |
| |||
487 | 511 | | |
488 | 512 | | |
489 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
490 | 517 | | |
491 | 518 | | |
492 | 519 | | |
493 | 520 | | |
| 521 | + | |
494 | 522 | | |
495 | 523 | | |
496 | 524 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
701 | 701 | | |
702 | 702 | | |
703 | 703 | | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
704 | 748 | | |
705 | 749 | | |
706 | 750 | | |
| |||
0 commit comments