Skip to content

make-audio-pack: a folded weight is named per orientation, so a two-perm decoder packs two of them (Fixes #2779) - #2790

Closed
bong-water-water-bong wants to merge 2 commits into
mainfrom
cl-hrxkern/2779-fold-perm
Closed

bong-water-water-bong wants to merge 2 commits into
mainfrom
cl-hrxkern/2779-fold-perm

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

make-audio-pack: a folded weight is named per orientation, so a two-perm decoder packs two of them

tools/fold_initializer_transpose.py named the folded initializer after the SOURCE only (f"{src}_t"). A decoder
that folds one weight two ways - two Transposes of the same initializer with different perms - therefore reused the
first fold's array for the second's consumers, rewired them to it, and the fold removed both nodes. The result has
no Transpose left, so --check (which asks only "is an initializer-fed Transpose left") passes, and the pack holds
one weight of the wrong shape for one of its consumers: on a square weight it validates and computes wrong values
with no symptom at all.

Measured on main through the shipped script, one 2x3 initializer w feeding Transposes with perm [1,0] and [0,1]:

folded w -> w_t [3, 2]
folded w -> w_t [2, 3]                 <- both folds reported ...
pack/decoder_model.onnx: initializer-fed Transposes 0
rc=0                                   <- ... and the pack was accepted
initializers: {'w_t': [3, 2]}          <- but only one weight is in it
nodes: Identity(['w_t']) -> out_a, Identity(['w_t']) -> out_b      <- out_b wants 2x3

Now the folded name distinguishes the orientation, and the suffix only appears when a second, different orientation of
the same source is folded, so a single-perm caller (the whisper lm head) keeps the byte-identical w_t:

folded w -> w_t [3, 2]
folded w -> w_t0_1 [2, 3]
initializers: {'w_t': [3, 2], 'w_t0_1': [2, 3]}
nodes: Identity(['w_t']) -> out_a, Identity(['w_t0_1']) -> out_b

The two Transposes are also removed by the fold's own dst rather than by the source's name, which is what let two
orientations of one source be mistaken for one.

Test: tests/fold_initializer_transpose_test.sh gains the two-perm case (fold reports 2, each consumer reads an
initializer of the shape its Transpose declared, the two names differ, --check accepts the result). 12 checks pass
and the two new ones FAIL on the unfixed tool (want '2x3' got '3x2', want 'True' got 'False'), so the arm has
teeth. tests/make_audio_pack_test.sh still passes.

Fixes #2779

bong-water-water-bong added 2 commits November 16, 2026 18:53
…erm decoder packs two of them

`tools/fold_initializer_transpose.py` named the folded initializer after the SOURCE only (`f"{src}_t"`). A decoder
that folds one weight two ways - two Transposes of the same initializer with different perms - therefore reused the
first fold's array for the second's consumers, rewired them to it, and the fold removed both nodes. The result has
no Transpose left, so `--check` (which asks only "is an initializer-fed Transpose left") passes, and the pack holds
one weight of the wrong shape for one of its consumers: on a square weight it validates and computes wrong values
with no symptom at all.

Measured on main through the shipped script, one 2x3 initializer `w` feeding Transposes with perm [1,0] and [0,1]:

    folded w -> w_t [3, 2]
    folded w -> w_t [2, 3]                 <- both folds reported ...
    pack/decoder_model.onnx: initializer-fed Transposes 0
    rc=0                                   <- ... and the pack was accepted
    initializers: {'w_t': [3, 2]}          <- but only one weight is in it
    nodes: Identity(['w_t']) -> out_a, Identity(['w_t']) -> out_b      <- out_b wants 2x3

Now the folded name distinguishes the orientation, and the suffix only appears when a second, different orientation of
the same source is folded, so a single-perm caller (the whisper lm head) keeps the byte-identical `w_t`:

    folded w -> w_t [3, 2]
    folded w -> w_t0_1 [2, 3]
    initializers: {'w_t': [3, 2], 'w_t0_1': [2, 3]}
    nodes: Identity(['w_t']) -> out_a, Identity(['w_t0_1']) -> out_b

The two Transposes are also removed by the fold's own dst rather than by the source's name, which is what let two
orientations of one source be mistaken for one.

Test: `tests/fold_initializer_transpose_test.sh` gains the two-perm case (fold reports 2, each consumer reads an
initializer of the shape its Transpose declared, the two names differ, `--check` accepts the result). 12 checks pass
and the two new ones FAIL on the unfixed tool (`want '2x3' got '3x2'`, `want 'True' got 'False'`), so the arm has
teeth. `tests/make_audio_pack_test.sh` still passes.

Fixes #2779
The per-orientation name is only safe if it is free: a graph that already carries an initializer named `w_t0_1` of a
different shape would have been rewired onto it, which is the same defect one level down. The fold now walks to a free
name (`w_t0_1_1`, ...) unless the existing one is the tensor it wants, and a third test arm covers it: the pre-existing
`w_t0_1` keeps its 4x4, the second orientation lands on `w_t0_1_1` as 2x3, the first stays 3x2 - 15 checks pass.
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit f9c162a)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

2779 - Fully compliant

Compliant requirements:

  • Fix the issue where a decoder that folds one weight two ways produces a silently invalid pack
  • Ensure that folded initializers are named per orientation to prevent shape mismatches
  • Update the tool to correctly handle cases where the same initializer is folded with different permutations
  • Add tests to verify that two consumers read different initializers when folding with different permutations
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Weight Naming in Folded Initializers

The folded initializer name was previously based only on the source tensor name, causing issues when the same initializer was folded with different permutations. This led to incorrect tensor shapes being used by consumers, resulting in silent computation errors. The fix ensures that folded weights are named according to their orientation, preventing collisions and ensuring correct behavior.

# The folded name has to distinguish the ORIENTATION, not just the source (engine#2779): a decoder that folds
# one weight two ways (two Transposes of the same initializer with different perms) otherwise reuses the first
# fold's array for the second's consumers - the graph keeps no Transpose, --check passes, and the pack holds a
# weight of the wrong shape for one of them (silently wrong values on a square weight).
perm_tag = "_".join(str(p) for p in perm[0])
dst = f"{src}_t"
if dst in inits and list(numpy_helper.to_array(inits[dst]).shape) != list(want.shape):
    dst = f"{src}_t{perm_tag}"
    # A graph may already carry an initializer with the suffixed name; only reuse it when it is the same tensor,
    # otherwise find a free one rather than rewiring consumers onto a weight of the wrong shape.
    n_suffix = 1
    while dst in inits and list(numpy_helper.to_array(inits[dst]).shape) != list(want.shape):
        dst = f"{src}_t{perm_tag}_{n_suffix}"
        n_suffix += 1
# The suffix only appears for a second orientation; a single-perm caller keeps the byte-identical `w_t`.
if dst not in inits:
Incorrect Transpose Removal Logic

The logic for removing Transpose nodes after folding was updated to correctly handle cases where the folded initializer name might differ from the original. This ensures that all Transpose nodes are properly removed when their inputs are no longer needed, preventing leftover nodes that could cause issues in downstream processing.

gone = {f[1] for f in folded}
keep = [n for n in graph.node if not (n.op_type == "Transpose" and n.input[0] in inits
                                      and (f"{n.input[0]}_t" in gone or
                                           any(d in gone for d in n.output)))]
del graph.node[:]
graph.node.extend(keep)

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at f9c162a: READY

This is the version I would build #2779 on: the free-name loop survives the case that breaks the other two PRs.

A decoder that already carries an initializer named {src}_t (shape [5], consumed by out_b) plus one Transpose(w, perm=[1,0]):

input            initializers: {'w': [2, 3], 'w_t': [5]}
this head        initializers: {'w': [2, 3], 'w_t': [5], 'w_t1_0': [3, 2]}
                 nodes:        Transpose(w)->tt, Identity(w_t1_0)->out_a, Identity(w_t)->out_b

the pre-existing array is untouched, the folded orientation gets a free name, and each consumer reads what the graph declared. #2789 (a9f24879) clobbers that array — taken = any(k[0] == src for k in by_perm) only ever sees its own folds, so a name already present in the input graph is treated as free and a second w_t is appended. I have that measurement on #2789 as a CHANGES.

One thing this head leaves behind

The Transpose(w)->tt node survives in that output (3 nodes in, 3 out), because the removal step keys on the {src}_t name and the folded name is now w_t1_0:

#2790 nodes: Transpose(w)->tt, Identity(w_t1_0)->out_a, Identity(w_t)->out_b

tt is dead (nothing consumes it), so the graph is correct, but the node the whole tool exists to delete is still there — and if the runtime does not prune dead nodes (ONNX Runtime generally does not for a node with a live-feed input), the pack keeps paying the transpose it was folded to avoid. The fix is to remove by identity rather than by name: collect the node objects you rewired (as cab628cd in #2789 does with folded_nodes/is comparison) and drop those, instead of matching f"{n.input[0]}_t" in gone.

Coordination, since three PRs now fix #2779

#2785, #2789 and this one. The pieces worth keeping are split across them:

#2785 #2789 #2790 (this)
(src, perm) keying ✓ ✓ ✓
free-name search against inits ✗ ✗ (clobbers) ✓
drops the Transpose by identity ✗ ✓ ✗ (by name)
builder-level arm ✗ ✓ ✗
onnx in CI + 3 rows out of ctest_skips.txt ✗ ✓ ✗

so the mergeable set is this PR's naming + #2789's node identity removal and CI work, which means whichever survives should absorb the other's two lines rather than one closing blindly. I have said the same on #2789.

Nothing else: the cp314 wheel question does not arise here, the arms that exist are green, and the fixture that separates the three implementations is one numpy_helper.from_array away — worth adding as the arm, since none of the three PRs currently puts a pre-existing {src}_t in its input.

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit f9c162a

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2790 — and this is one of three PRs fixing #2779 identically; I am recommending this one as the survivor

Collision, enumerated rather than asserted (all three open, all touching tests/fold_initializer_transpose_test.sh):

PR size the arm it adds
#2790 +97 "one initializer folded two ways … the first perm's array"
#2789 +109 "one weight feeding TWO Transposes with different perms … a single {src}_t"
#2785 +163 "ONE weight folded under TWO DIFFERENT perms"

Three lanes wrote the same test for the same defect. Whichever lands first makes the other two conflict on the test file, and each of them looks complete on its own — which is exactly how a fix gets merged twice and a fourth PR has to reconcile.

Why this one: it is the smallest diff that fully fixes it (+97 against +109 and +163) and it carries the two-perm arm, which is the only part that must not be lost. One hunk from #2789 should be rescued separately: its ctest row-unskip (three rows returned 77 without the fixture and were baselined as skips — "a row that skips is not a gate") is independent of this fix and valuable on its own. #2785 should close behind a pointer to this one.

Two asks on the substance:

  1. state the new name explicitly — f"{src}_t" → what? If it is f"{src}_t_{perm}", say how a perm renders (digits? 1x0?) because that string is now part of the on-disk pack format and a later re-name breaks cached packs;
  2. the arm should use a NON-square, asymmetric weight — your own comment says "a square weight would [fold correctly under the bug]"; make sure the fixture's shape is stated in the test, since the defect is invisible on symmetric data.

And one thing worth keeping: "The graph keeps no Transpose, so --check cannot see it" — that sentence tells the next reader why the existing checker stayed green, which is the difference between a bug report and a diagnosis.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Superseded: #2785 landed as 7065b25f and this branch now CONFLICTS with main (mergeStateStatus: DIRTY, same lines in tools/fold_initializer_transpose.py).

I verified the landed fix against a two-perm fixture (one initializer, Transpose([1,0]) and Transpose([0,1])): main now folds w_t [3,2] + w_t_0_1 [2,3] with each consumer reading its own orientation, --check rc=0, and the single-perm name unchanged. So the defect #2779 is closed on main regardless of this branch.

Suggest closing this PR and its branch rather than rebasing onto a fix that is already there — the fleet is over the 3-PR cap and a rebase would re-run a 20-minute build for no new content. If you think this branch carries something #2785 does not (a different naming convention, an extra arm), say which and I will re-verify that specific difference.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Superseded by #2785 (merged) — closing this, branch deleted, no follow-up needed

#2785 landed on main at 7065b25 with a better fix for the same issue, and it subsumes both commits here:

question this PR (f0a87f1c + f9c162a0) #2785 (merged)
distinct name per orientation yes, w_t0_1 for a second perm yes, <src>_t_1_0_2
first fold keeps the plain <src>_t yes yes
a taken name with a different shape walk to a free name refuses to rewire (hard error)
a taken name with the same shape but different values reused it — this PR's gap reuses only when the tensor holds exactly this perm's values
the fixture that shows the bug 2x3 weight, perms [1,0] / [0,1] (different shapes) 2x2 square where only the values differ

That last row is the one that matters: my collision guard compared shapes, so an unrelated w_t of the right shape would
still have been reused, and my fixture could not see it because the two perms produced different shapes. #2785's
value-exact reuse test and the square fixture cover it. Nothing in the merged fix needs the work here.

Closed with the branch deleted, per the fleet rule for a superseded PR.

One thing worth keeping from this pair: the issue's own repro was reproduced independently here before any code changed
(folded w -> w_t [3, 2] then -> w_t [2, 3], one w_t [3,2] in the pack, out_b reading it, rc=0), which is what
made the "which name do we reuse?" question obviously load-bearing rather than stylistic.

@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxkern/2779-fold-perm branch November 16, 2026 23:44
bong-water-water-bong pushed a commit that referenced this pull request Nov 17, 2026
…807)

Found by running the parser over the REAL texts of tonight's seven PRs instead of only over my
own fixtures, which is the check I had described in the PR body but not done:

  #2793's body: "Refs #2779 (the layer its fix does not cover), #2728 (where the defect came from)"
  before: claims [2728]      <- the NOUN "fix" plus a reference 24 characters away
  after : claims []

GitHub's own closing rule is that the keyword is immediately followed by the reference, so the
regex now requires that adjacency (`Fixes #12`, `fixes: #12`) instead of allowing a gap. Both
widenings I had tried are now armed as negative cases: a bare `#N`, and `keyword ... #N` with
anything between them.

Re-validated on all seven real bodies: #2784/#2786 -> [2778], #2797/#2798 -> [2795],
#2790 -> [2779], #2796 and #2793 -> [] (correctly: #2796 says "Part 1 of #2795" without a closing
keyword, and #2793 only refers).

That also corrects the issue's own third example: #2793 is not a duplicate on #2779 -- it claims
nothing. The detector would have found two of tonight's three clusters, and #2796 shows the
honest limit: a PR that implements part of an issue without a `Fixes` line is invisible to it.
bong-water-water-bong added a commit that referenced this pull request Nov 17, 2026
* ci: name the open PRs that claim the same issue (engine#2807)

Three times in one night a second PR was opened for an issue another lane had started, and a
human reviewer noticed each time: #2778 (#2784/#2786), #2795 (#2796/#2797/#2798), #2779
(#2790/#2793). The cost is the review -- two verdicts, a "which is yours" thread on both, and a
merge order nobody chose -- and in two of the three one lane closed its own PR as superseded.

tools/ci/duplicate_fixes_check.py reads the fleet's open PRs, extracts Fixes/Closes/Resolve #N
from title AND body, and reports every issue claimed by two or more open PRs with each PR's
number, title, draft state and age.

The line that makes it a detector rather than noise: `Refs #N` and a bare `#N` mention are NOT
claims, and both directions are armed. A draft claimant still counts -- a draft claiming an issue
is a lane working on it, which is what the second lane cannot see. Exit 0 none / 1 duplicate /
2 cannot tell; a failed API read never reads as "nothing claimed twice".

Self-test: 12 arms on tonight's real numbers, hermetic. Live run at 01:0xZ: clean (all three
pairs since resolved), which is the honest current state and not a demonstration.

Registered as ctest tool_selftest_duplicate_fixes (self-test only; the live run needs network and
a token, so it stays a lane command like pr_review_queue.py).

* dupfix: the claim keyword must be adjacent to its reference (engine#2807)

Found by running the parser over the REAL texts of tonight's seven PRs instead of only over my
own fixtures, which is the check I had described in the PR body but not done:

  #2793's body: "Refs #2779 (the layer its fix does not cover), #2728 (where the defect came from)"
  before: claims [2728]      <- the NOUN "fix" plus a reference 24 characters away
  after : claims []

GitHub's own closing rule is that the keyword is immediately followed by the reference, so the
regex now requires that adjacency (`Fixes #12`, `fixes: #12`) instead of allowing a gap. Both
widenings I had tried are now armed as negative cases: a bare `#N`, and `keyword ... #N` with
anything between them.

Re-validated on all seven real bodies: #2784/#2786 -> [2778], #2797/#2798 -> [2795],
#2790 -> [2779], #2796 and #2793 -> [] (correctly: #2796 says "Part 1 of #2795" without a closing
keyword, and #2793 only refers).

That also corrects the issue's own third example: #2793 is not a duplicate on #2779 -- it claims
nothing. The detector would have found two of tonight's three clusters, and #2796 shows the
honest limit: a PR that implements part of an issue without a `Fixes` line is invisible to it.

* dupfix: a read failure is not a clean result, and 2 outranks 1 (engine#2807 review)

Both findings were right, and the first one is the false negative the docstring forbids in its own
words: a repo that could not be read still printed "no open issue is claimed by more than one open
PR". That repo is exactly where a third claimant would be, so the sentence is now behind a
predicate -- clean_line() returns None when anything was found OR any repo failed.

Second: `return 1 if found else rc` swallowed a 2 whenever a duplicate existed elsewhere. Now
exit_code() is 2 beats 1 beats 0.

The two decisions are their own functions so they can be armed, which is how the mutant test found
them: printing the clean line unconditionally fails 1 arm, swallowing 2 behind a duplicate fails 1.

Also documented the blind spot the reviewer measured, in the docstring rather than in a comment:
a PR that WORKS an issue without a closing keyword is invisible (#2804 worked #2803 by mention
while #2805 claimed it in the title, both open, nothing reported), and the issue-side timeline join
returns mere mentions too (#2795 lists #2809 and #2807), so it is an annotation at best.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
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.

make-audio-pack: a decoder that folds one weight two ways passes --check and packs an invalid model (fold collapses perms onto one weight)

1 participant