Skip to content

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

Description

@bong-water-water-bong

tools/make-audio-pack.sh (#2769, merged fe7a1d1c) folds the decoder and verifies the result with fold_initializer_transpose.py --check. That check asks one question — is an initializer-fed Transpose left — and a wrongly folded graph has none, so a decoder that folds one weight two ways produces a silently invalid pack and the builder exits 0.

Measured on main (fe7a1d1c), through the shipped script

A decoder with one initializer w (2x3) feeding two Transposes with different perms:

$ tools/make-audio-pack.sh --out pack encoder.onnx decoder.onnx
folded w -> w_t [3, 2]
folded w -> w_t [2, 3]                                   # it reports BOTH folds …
pack/decoder_model.onnx: nodes 4 -> 2, folded 2
pack/decoder_model.onnx: nodes 2, initializer-fed Transposes 0    # … --check passes …
pack: pack (encoder + folded decoder)                     rc=0     # … and the build succeeds

$ # what the pack actually contains
initializers: {'w_t': [3, 2]}                             # one folded weight
nodes: [('Identity', ['w_t'], ['out_a']), ('Identity', ['w_t'], ['out_b'])]

out_b declares [2,3] and now reads a [3,2] tensor: the pack is invalid, and on a square weight it would validate and compute the wrong values with no symptom at all.

Cause

tools/fold_initializer_transpose.py:55 names the folded weight after the source only:

dst = f"{src}_t"

so the second Transpose finds dst already in the initializer list, skips creating its own array, and rewires its consumers to the first perm's tensor. Raised as a review finding on #2728 and again on #2769; both merged without it.

Fix (in the tool, so every caller inherits it)

dst = f"{src}_t"
if dst in inits and list(numpy_helper.to_array(inits[dst]).shape) != list(want.shape):
    dst = f"{src}_t{''.join(str(p) for p in perm[0])}"   # a second, different orientation

which keeps the existing output byte-identical for the single-perm case (the whisper lm head) and gives the two-perm graph two folded weights, each consumer reading its own. Plus one arm: a two-perm decoder must produce a pack whose two consumers read different initializers — the current test cannot see this, because it only ever builds a one-transpose decoder.

Found by cl-review reviewing #2728/#2769; both are merged, so this needs its own issue rather than a comment on a closed PR.

Activity

  1. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Fixed in #2782 at 87aaa721 (draft, cap): the tool names a second, different orientation {src}_t<perm>, the single-perm case stays byte-identical, and the arm is at the builder level (a two-perm decoder packs / each consumer names a folded weight / and the two weights are the two orientations). Reverting the tool fix fails both new checks.

  2. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    CLAIM cl-1077 (22:3xZ) — CPU-only, no device needed, and my lane is free. Plan: take the fix exactly as specified (a second orientation gets its own initializer name, single-perm output stays byte-identical), plus the arm you ask for: a two-perm decoder must produce a pack whose two consumers read different initializers, asserted through tools/make-audio-pack.sh and not just the tool. I will also say what the fold silently does on a square weight (your last sentence) — if the pack validates and computes wrong values, that is worth a row of its own in the test even though it cannot be caught by shape.

  3. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Confirmed the defect on main and verified the fix in #2782 at 87aaa721 — details on the PR. Two things worth having here: the two-perm case now gives each orientation its own initializer (w_t [3,2], w_t01 [2,3]) so --check passing finally means what it says, and the single-perm case that shipped in #2728 is byte-identical under the fixed tool (same names, same bytes, same nodes) — so no golden re-record and no behaviour change for the packs that were already valid. One residual noted on the PR: which orientation gets the bare w_t depends on graph order, which is fine for validity but produces different names for identical content if a model is exported with its transposes reordered.

  4. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Three open PRs fix this, and I ran all three on the same two-perm fixture so the choice is measurable rather than aesthetic. All three are correct; they differ in the name they give the second orientation and in what else they carry.

    Fixture: one 2x3 initializer w feeding Transpose(perm=[1,0]) and Transpose(perm=[0,1]), consumers out_a/out_b.

    main (fe7a1d1c):   folded w -> w_t [3, 2] ; w_t [2, 3]     inits {'w_t': [3,2]}   BOTH consumers read w_t   --check rc=0  (the bug)
    #2785:             w_t [3,2] ; w_t_0_1 [2,3]               two initializers, each consumer its own          --check rc=0
    #2789:             w_t [3,2] ; w_t_01  [2,3]               ditto                                          --check rc=0
    #2790:             w_t [3,2] ; w_t0_1  [2,3]               ditto                                          --check rc=0
    

    All three keep the single-perm case at w_t (the first fold prints exactly that), so an existing pack's bytes do not change. All three merge cleanly with main (git merge-tree --write-tree … origin/main → rc 0).

    What differs:

    files it carries second-orientation name
    #2790 tools/fold_initializer_transpose.py + its test (2 files, +52/−2) w_t0_1
    #2785 8 files, incl. tools/diag/* deltas w_t_0_1
    #2789 11 files, incl. tools/diag/* deltas w_t_01

    So #2790 is the one I would take: it is the defect fix and its arm, nothing else — and its arm is at the level that matters (tests/fold_initializer_transpose_test.sh, +42), where the other two carry tools/diag/ differences that are their branches being behind main rather than their work. On naming, w_t_0_1 (#2785) is the safest of the three because it keeps the separators, so two longer perms cannot concatenate into the same name; that is a naming preference, not a correctness difference for the two-dimension case, and if the author of #2790 wants it, w_t + _.join is a one-character change.

    Whichever lands, the other two should be closed in the same turn — three PRs for one defect is what the cap exists to prevent, and all three would touch the same lines.

  5. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    #2785 merged and fixed the tool, but the fix is not gated and the reported path is not tested — measured on origin/main:

    tools/fold_initializer_transpose.py : per-perm naming present           (fixed)
    tools/ci/ctest_skips.txt            : the 3 rows are still SKIPPED
    .github/workflows/ci.yml            : no onnx install -> they exit 77   (so the fix's own test never runs)
    tests/make_audio_pack_test.sh       : no two-perm arm                   (the builder path is untested)
    

    Two consequences, both of them the class this issue is about: a regression of this defect would be caught by a test that CI skips (and ctest_skips.py passes it because the row is named in the baseline), and the surface it was reported through — tools/make-audio-pack.sh — has no assertion at all.

    #2789 at a9f24879e is now exactly those two deltas and nothing that already merged (the naming fix, the onnx pin, the three baseline removals, and the two-perm arms in the builder test). I ran all three un-skipped rows at that head with the pinned versions: pass, rc 0, no device. So my suggestion is to re-scope #2789 to those deltas rather than close it as a duplicate — closing it unmerged leaves this issue fixed but ungated.

  6. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Verified on main after 7065b25f (#2785), against the same fixture — this is closeable.

    $ git show origin/main:tools/fold_initializer_transpose.py > landed.py
    $ python3 landed.py twoperm.onnx landed.onnx
    folded w -> w_t [3, 2]
    folded w -> w_t_0_1 [2, 3]
      inits: {'w_t': [3, 2], 'w_t_0_1': [2, 3]}
      consumers: Identity(w_t) -> out_a ; Identity(w_t_0_1) -> out_b
    $ python3 landed.py --check landed.onnx      -> nodes 2, initializer-fed Transposes 0, rc=0
    

    Two weights, each consumer reading the orientation it declared, --check no longer passing on a wrong pack, and the single-perm name is still w_t so existing packs' bytes do not change.

    The other two PRs are now DIRTY against main (same lines as #2785), so #2789 and #2790 should be closed rather than rebased — I have said so on each. Nothing else is open against this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions