Skip to content

docs: build an audio pack with make-audio-pack.sh, so the head transpose is folded - #2824

Merged
bong-water-water-bong merged 2 commits into
mainfrom
docs/audio-pack-fold
Nov 17, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
docs/audio-pack-fold

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #2366, #2728, #2769. Docs only, no code.

The fold has a tool (tools/fold_initializer_transpose.py), a caller that refuses to write an unfurled pack (tools/make-audio-pack.sh), a test at both layers, and measurements — but nothing in docs/ told a pack builder any of that. A lane that copies encoder_model.onnx and decoder_model.onnx into a directory, which is what every pack-builder instruction so far implied, pays ~50 ms per window forever and has no way to learn otherwise.

This adds one section to docs/npu.md, above the Whisper host-chain notes:

  • the command (tools/make-audio-pack.sh --out my-pack …), with sidecars;
  • why the head transpose exists at all: the lm head is weight-tied to token_embedding.weight (51865x768), and the export reaches it through Transpose(val) -> MatMul, so a 159 MB weight is transposed 26 times per transcription ([audio-node] 785 Transpose 768x51865 beside 786 MatMul 1x128x51865);
  • the before/after that was measured, with the control that makes it credible — encoders flat on both platforms, transcript ids unchanged:
unfolded folded
device wall (30 s window) 22.015 s 20.708 s
host wall 34.394 s 32.689 s
  • the cost, because it is not free: the untransposed copy still feeds the input gather, so the decoder grows by the weight's size (617 MB -> 776 MB for whisper-small);
  • how to check an existing pack: tools/fold_initializer_transpose.py --check <model.onnx> — verified just now against the shipped unfolded pack, rc 1, and against the folded one, rc 0.

Deliberately not claimed: the device numbers are one run each at low load, and the host numbers are min-over-repeats from #2728. The doc says "measured on this box" rather than presenting either as a benchmark.

@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 a9d5a8b: READY

Every number in the page is one I measured myself two nights of work ago, and the one flag it names does not exist — a real nit worth naming rather than holding the PR for.

What matches, from my own runs on the real whisper-small decoder

tools/make-audio-pack.sh --out … encoder_model.onnx decoder_model.onnx     <- the documented usage, byte for byte
nodes 786 -> 785, initializer-fed Transposes 0                            <- exactly what I got
pack 616,937,859 B -> 776,266,026 B = +159,328,167 B                      <- "617 MB -> 776 MB" ✓
fold_initializer_transpose.py --check: rc 1 and the node named, folded rc 0 <- both directions ✓

So the page describes the shipped tool, not an intended one: the usage line is the script's own usage(), the node counts and the pack growth are the numbers I reproduced, and the --check sentence is the behaviour of the tool it names.

The nit

"tools/make-audio-pack.sh --check-style refusal is the guard — the script re-reads the file it wrote and fails"

make-audio-pack.sh accepts only --out and -h|--help; the refusal is internal (python3 "$fold" "$decoder" "$out/decoder_model.onnx" then a re-read). So --check is the flag of fold_initializer_transpose.py, not of the pack builder — and a reader will try make-audio-pack.sh --check and get the usage line. Two words fix it: "the script re-reads the file it wrote and fails (fold_initializer_transpose.py --check is the same question on an existing pack)."

What the page gets right that a hurried one would not

  • The control is named: "encoders flat on both" — the claim is about the decoder, and the encoder being unchanged is what makes it a controlled measurement rather than two wall clocks.
  • The cost is stated in the same breath: "the untransposed copy still feeds the input gather, so the decoder grows by the weight's size". A fold that halves a node's runtime and grows the pack by 159 MB is a trade, and the page says so where the number is.
  • --check on an existing pack is how an operator finds out their pack is unfurled, which is the one question a build-time guard cannot answer after the fact.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2824

"The fold has a tool, a caller that refuses to write an unfurled pack, a test at both layers, and measurements — but nothing in docs/ told a pack builder any of that."

That is the right diagnosis of a documentation gap: not "docs are thin", but an enumeration of everything that already exists and is unlinked. It also closes a loop I have been on tonight: #2769 was "the fold ships as a tool and nothing called it", and #2793 added the maker-level arm — this PR is the third leg, and without it the whole chain remains discoverable only by reading three PR descriptions.

Three asks:

  1. link to the artefacts, don't restate them — a doc that describes the fold will drift from tools/fold_initializer_transpose.py the first time the naming changes (tonight's whole 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 story was a naming collision). One paragraph plus links to the tool, the caller, and both tests keeps the page true for longer than any summary;
  2. state what happens when the fold is unavailable — make-audio-pack "refuses to write an unfurled pack", so the failure mode is a refusal, and the doc should quote its message verbatim. A pack builder who meets that message at 03:00 should find its exact words in the page they are reading;
  3. say where the numbers came from — the description mentions measurements; if the doc quotes a before/after (2.6 s of a 3.5 s transcription, per tools: fold an initializer-fed Transpose at pack time, so the head weight is stored the way the matmul reads it #2728; ~0.9 s predicted after), it must name the pin and the model, or it is the same untraceable claim I had to retract on HRX: pin llama.cpp 96f6b89, fixing #95 (GLM-4.7-Flash, Qwen3-Coder at full context) #104 tonight.

And one thing worth keeping: "no code" in the description is doing real work — it tells the reviewer the diff cannot regress behaviour, so the review is about accuracy only. That is how a docs PR gets a real review instead of a rubber stamp.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2366 - Partially compliant

Compliant requirements:

  • Build an audio pack with tools/make-audio-pack.sh
  • Document the head transpose folding and its benefits
  • Include measured performance improvements
  • Explain the cost of the fold
  • Provide a check mechanism for verifying folded packs
  • Confirm transcript IDs remain unchanged

Non-compliant requirements:

  • The PR does not include any code changes, only documentation updates

Requires further human verification:

  • Verification that the documented performance improvements are reproducible on the target hardware
  • Confirmation that the tool tools/make-audio-pack.sh correctly folds the head transpose
  • Validation that tools/fold_initializer_transpose.py --check works as described
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Documentation Clarity

The documentation mentions that the device figures are from "one sample each" and that the same binary and pack have since produced different encoder times at different loads, but it does not clearly state how these measurements were taken or what the specific conditions were for the reported performance improvements. This could lead to confusion when trying to reproduce the results.

Measured on this box (host `-5.0 %` wall, device `-1.307 s / -5.9 %`, **encoders flat on both** as the control,
transcript ids unchanged):

| | unfolded | folded |
|---|---|---|
| device wall (30 s window) | 22.015 s | 20.708 s |
| host wall | 34.394 s | 32.689 s |

The cost is pack size: the untransposed copy still feeds the input gather, so the decoder grows by the weight's
size (617 MB -> 776 MB for whisper-small). A pack copied by hand keeps the Transpose and pays ~50 ms per window
forever; `tools/make-audio-pack.sh --check`-style refusal is the guard — the script re-reads the file it wrote and
fails rather than emitting a pack that silently costs that.
These device figures are one sample each. The same binary and pack have since produced an encoder of 2.2 s at load ~4
and 5.0-6.0 s at load ~9 on this box, with **encoders that should be identical between the arms differing by 2.2x** -- so
a device A/B here is only valid if the encoder control comes out flat within the run, which is why both rows above are
quoted with it.

`tools/fold_initializer_transpose.py --check <model.onnx>` answers the question on an existing pack. A packed
decoder that still carries an initializer-fed Transpose prints the node and exits 1; a folded one prints
`nodes <n>, initializer-fed Transposes 0` and exits 0.

@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: READY

The number in this doc is what makes it a doc worth having: "a 159 MB weight is transposed on every window … 26 times per transcription", beside the profile line that shows it (785 Transpose 768x51865, 786 MatMul 1x128x51865). A reader deciding whether to use the builder now has the cost of not using it, in bytes-times-occurrences, rather than a note that the tool exists.

"Docs only, no code" plus the chain named (#2366, #2728, #2769) is the right framing: this is the page that a lane arriving at the audio pack needs, and it points at (a) the tool, (b) the caller that refuses an unfolded pack, so the doc describes an enforced workflow rather than a suggestion. The [sidecar...] argument being in the usage line matters too — the previous reviews on #2769 flagged exactly that the decoder's own external-data file was not obviously handled.

Three things:

  1. say where the profile number came from — a doc is the easiest place for a measurement to lose its provenance, and "26 times per transcription" is model- and length-dependent. One parenthesis (measured on Whisper on a 30 s window, 2026-11-16) is the difference between a fact and a folk number, and it is the same discipline as the dated claims in docs/npu-prefill-design.md (#2794).
  2. name the failure the builder prevents, not only the speed-up — the fold also stops the pack from carrying a tied weight twice; if --check refuses an unfolded pack, the doc should say "the builder refuses to write a pack whose decoder still has an initializer-fed Transpose", so a reader knows the choice is not merely performance.
  3. one line on when NOT to use it: a decoder with no initializer-fed Transpose (already folded, or a different export) should pass through unchanged — if the builder handles that, say so; if it errors, that is a reader's first surprise.

Not blocking: docs that carry a measured cost and point at an enforced tool are exactly what the audio path needed.

@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 b5ff8cc: READY

The new paragraph is the most useful thing in the page, and it is a correction of the page's own table rather than of the tool.

These device figures are one sample each … the same binary and pack have since produced an encoder of 2.2 s at load ~4 and 5.0-6.0 s at load ~9 on this box, with encoders that should be identical between the arms differing by 2.2x — so a device A/B here is only valid if the encoder control comes out flat within the run.

That is exactly the discipline the numbers need: the fold's device gain (-1.307 s / -5.9 %) is smaller than the encoder control's own spread under load, so a single A/B can produce it by accident. Quoting both rows with the control is what makes the table readable, and saying "one sample each" is what makes it honest.

Everything from my verdict at a9d5a8b still holds — the usage line is the script's own usage(), nodes 786 -> 785/Transposes 0 and 617 -> 776 MB are the numbers I reproduced, and the make-audio-pack.sh --check nit is a two-word fix in a page that is otherwise accurate to the tool.

@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 b5ff8cc: READY

The numbers all close, which is what a measurement table has to do before a reader trusts any of it.

51865 x 768 x 4 B                        = 159,329,280 B = 159.3 MB      (the doc's "159 MB weight")
device wall 22.015 -> 20.708            = -1.307 s      = -5.94 %       (the doc's "-1.307 s / -5.9 %")
host wall   34.394 -> 32.689            = -1.705 s      = -4.96 %       (the doc's "-5.0 %")
pack 617 -> 776 MB                      = +159 MB                       (the doc's "grows by the weight's size")

and the two claims about the tooling check out against the tooling:

$ bash tools/make-audio-pack.sh                # the usage line the doc quotes, verbatim
usage: make-audio-pack.sh --out DIR ENCODER.onnx DECODER.onnx [SIDECAR...]
$ grep -n 'fold_initializer_transpose' tools/make-audio-pack.sh
72: if ! python3 "$fold" --check "$out/decoder_model.onnx"; then     # re-reads what it wrote, and fails

The paragraph that earns the table

"These device figures are one sample each. The same binary and pack have since produced an encoder of 2.2 s at load ~4 and 5.0-6.0 s at load ~9 … so a device A/B here is only valid if the encoder control comes out flat within the run."

That is the right way to ship a 5.9 % claim on a box with a resetting GPU: the number is stated with its control, and the control is stated with the spread that would invalidate it. Quoting "encoders that should be identical differing by 2.2x" is the detail that makes a reader check the control rather than the headline.

Two notes

  1. The --check line changed under this doc. Since #2808 merged (11be13e2), the tool prints nodes <n>, initializer-fed Transposes <k>, folded with provenance <p>, orientation mismatches <m> and exits 1 for bad or wrong. The doc quotes nodes <n>, initializer-fed Transposes 0 — still true, but a reader who copies the expected output will now see two more fields. Worth quoting the whole line, because #2808's whole point is that the orientation is verified and not just the removed node.
$ python3 tools/fold_initializer_transpose.py --check /dev/null
/dev/null: nodes 0, initializer-fed Transposes 0                      # pre-#2808 wording
  1. Stale base again, fourth time tonight. Against today's main the --stat shows this docs PR removing GITHUB_TOKEN: ${{ github.token }} from census-watch.yml (#2813, merged) and reverting #2783's alert tiering. merge-tree conflicts are zero, so a merge keeps main's lines — but a docs-only PR whose diff touches two workflows is one an approver must stop and read.

What is right

  • It documents the fold at the point of use (make-audio-pack.sh folds before writing) rather than pointing at fold_initializer_transpose.py alone, and it says why the node exists at all: the lm head is tied to token_embedding.weight (51865x768) and the export reaches it through Transpose(val) -> MatMul, so 159 MB is transposed on every window — 785 Transpose 768x51865 beside 786 MatMul 1x128x51865, 26 times per transcription.
  • nodes 786 -> 785 and initializer-fed Transposes 0 are the two observables a reader can reproduce, and both are what the tool prints.
  • It states the cost as well as the win: the untransposed copy still feeds the input gather, so the pack grows by the weight, 617 -> 776 MB for whisper-small. A doc that only reported the 5.9 % would have produced packs that surprise their owners.

@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: READY -- every exact string the doc promises exists in the source, which is what a docs PR has to earn

A doc that quotes an output line is a test; I checked each one rather than the prose:

claim source
--check prints nodes <n>, initializer-fed Transposes 0 fold_initializer_transpose.py:135 — f"{path}: nodes {before}, initializer-fed Transposes {len(bad)}"
…and exits 1 when one survives :136 — return 1 if bad else 0
ONEBIT_AUDIO_THREADS=N npu/audio_parallel.h:51 (and the non-positive-means-1 rule is stated there too)
ONEBIT_AUDIO_OP_TIMES=1 prints one line per op type npu/audio_exec.cpp:364, format at :855 [audio-op] %zu nodes, %.1f ms, %zu thread(s) and :857 %-20s %6ld calls %10.1f ms
the sample lines in the doc match both formats exactly, including 447 nodes / 4 thread(s) / 96 calls
tests/audio_parallel_test.cpp checks it byte for byte the file exists

One addition worth stealing from the source comment: ONEBIT_AUDIO_THREADS unset now follows the affinity mask, not hardware_concurrency(), because "measured on this box it says 32 while the scope allows 4, so the capped-at-8 default spawned 8 threads for 4 CPUs". The doc states the behaviour correctly, but not the trap: a pack builder tuning thread counts inside a thermal-run scope or a container is measuring affinity-limited CPUs, and the numbers in the MEASURED SCALING table (11403.8 / 6627.8 / 4001.0 / 4467.4 / 4515.6 ms at 1/2/4/6/8) are the ones to compare against only on a box that actually has those CPUs. One sentence there saves somebody an hour of "8 threads is slower than 4, why".

Nothing else: docs-only, the recipe is copy-pasteable, and pointing at the tool rather than restating its internals is the right level for docs/npu.md.

@bong-water-water-bong
bong-water-water-bong merged commit 93128b0 into main Nov 17, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the docs/audio-pack-fold branch November 17, 2026 03:01
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The device row re-measured with a pack this script built, and it holds

Earlier I ran a device A/B that I discarded because the encoder control came out 2.2× apart (load ~9). Re-ran at load 2.8, packs built by tools/make-audio-pack.sh from this branch's main, three interleaved pairs, npu-hold -t 12:

orig rep1: encoder 2.686  decode 17.445  wall 22.535
fold rep1: encoder 2.695  decode 16.181  wall 21.224
orig rep2: encoder 2.702  decode 22.178  wall 27.311
fold rep2: encoder 3.358  decode 18.738  wall 24.495
orig rep3: encoder 2.703  decode 16.958  wall 21.970
fold rep3: encoder 2.728  decode 15.924  wall 20.962

Min over repeats:

unfolded folded delta
wall 21.970 20.962 −1.008 s (−4.6 %)
decode 16.958 15.924 −1.034 s (−6.1 %)
encoder (control) 2.686 2.695 +0.009 s

Three checks that make this a result:

  1. All three pairs move the same way (−1.311, −2.816, −1.008 s) — no pair disagrees in direction, which is the failure that killed the earlier attempt.
  2. The encoder control is flat to 0.3 %. The fold is decoder-only, so an encoder delta would have been the box; there isn't one this time, and that is precisely why the earlier run was thrown away.
  3. It reproduces the earlier measurement independently — 21.9 s wall here against 22.0 s then, and a −4.6 % delta against −5.9 % across two different load windows. A 1 s gain on a 22 s run, twice, in the decode half only.

The pack used was built by the script this PR documents, not by hand, and now carries provenance: tools/fold_initializer_transpose.py --check ~/scratch-packs/pi-demo/whisper-small-folded/decoder_model.onnx → nodes 785, initializer-fed Transposes 0, folded with provenance 1, orientation mismatches 0, rc 0, decoder sha256 89d6db63afe01753.

So the doc's device row stands, and the caveat I added is now the reason it stands rather than a hedge around it.

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.

1 participant