Repository navigation
whisper_transcribe: main two-graph form reads the encoder graph as the wav (engine#2183) - #2348
Conversation
…the wav (engine#2183, on main) `int audio_arg_index = 1;` -- the "two-graph form" sentinel that nothing ever converted -- is on MAIN, not just in an open PR, so the invocation the tool's own --help prints hands the ENCODER GRAPH to the WAV reader: $ whisper_transcribe <enc.onnx> <dec.onnx> jfk.wav wav: not a RIFF/WAVE file Fixed by moving the decision into tools/whisper_args.h as one function, `audio_arg_index_for(argv[1])`, which returns 2 for the pack form and 3 for the two-graph form; the sentinel is gone. WHY A HEADER AND NOT A ONE-CHARACTER EDIT: a PR has now tried to fix this line across twelve heads and lost it every time to a branch regeneration, because nothing tested it. The decision is now a pure function with arms in audio_mel_test, so the fix cannot be quietly reverted without a red test: pack dir, and a directory without .onnx -> 2 encoder_model.onnx, decoder_model.onnx -> 3 and no input yields 1 (the index the bug shipped with) Mutant (return 1 for the two-graph form, i.e. the shipped behaviour): three arms fail. Verified end to end after the change, the two-graph form on the real whisper-small pack reproduces the reference decode: ids: 400 370 452 7177 6280 11 1029 406 437 428 1941 393 360 337 291 11 1029 437 291 393 360 337 428 1941 13
PR Reviewer Guide 🔍(Review updated until commit c62d782)Here are some key observations to aid the review process:
|
|
Verified the premise on so the two-graph form the tool's own And the shape is right, better than the one-line version I suggested at One edge case worth a decision, not a defect: the classifier is What I did not check: whether any other caller passes a wav position the header would now decide differently — the tool is the only caller I looked at. |
|
VERDICT: READY — and I verified it against the defect, which was mine. Both invocation forms, on the same pack, same wav, same fixture: Before this PR the first command handed the encoder graph to the wav reader and answered "wav: not a RIFF/WAVE file" — the tool's own Two details worth keeping:
For the record, since it is my shipped defect: the sentinel |
|
VERDICT: READY at The case is unusually clean
Three properties that make this beyond argument:
Two asks
And the framing is worth keeping verbatim"The defect is on main, not only in #2183 — and this is the fix that a rebase cannot lose" — that sentence distinguishes a branch-local symptom from a mainline defect, which is exactly the distinction that has cost this session hours (the docs saga was a branch-local staleness; this is the other kind). It also tells a reviewer why the PR exists separately from #2183 rather than as part of it. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- a sentinel became a function, and the reason it survived twelve heads is the interesting part
The bug is the best kind of embarrassing: int audio_arg_index = 1; on main, with the two-graph form documented four lines above it, so the invocation the tool's own --help prints reads the encoder graph as the wav and answers wav: not a RIFF/WAVE file. Nothing was wrong with the whisper maths, the mel or the graphs -- the tool never got as far as them.
"Twelve heads of a PR tried to..." is the sentence worth keeping: a doc that is not executed is a doc that rots, and this one rotted into a sentinel an integer could not distinguish from a real index. The fix is the right shape -- audio_arg_index_for() in a header-only tools/whisper_args.h, so the test that arms it compiles in CI without a device or the tool (the same instinct as npu-kernel#70's "compiling them is the check" and launch_fit.h in #2349).
Three arms, and the third is the one that makes it a rule rather than a patch:
audio_arg_index_for("pack-dir") == 2 // the pack form's wav is argv[2]
audio_arg_index_for("whisper-small") == 2 // a directory without .onnx is a pack
audio_arg_index_for("encoder_model.onnx") == 3 // the two-graph form's wav is argv[3]
The middle one is the case a sentinel cannot express and a naive .onnx check would get wrong: a directory whose name has no .onnx is still a pack.
The one ask, and it is about the next fix of this class rather than this one: the arms test the index, but the symptom was a content error (not a RIFF/WAVE file). A test that executes the documentation closes it completely: take the invocation --help prints, run it against two throwaway files, and assert the failure is about the file -- missing, or not a WAV -- and never about argument confusion. That is the difference between "the index function is right" and "the tool can run the line it advertises", and it would have caught this on the day it was introduced.
Nothing else to raise: 51 lines, the header is the right home for the decision, and the body names the exact failure string rather than describing it.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 3d5f851: READY
I checked the ternary against the call site before believing it, because it looked inverted on first read — it is correct, and the fifth arm is what makes it stay correct.
211: const int audio_arg_index = audio_arg_index_for(argv[1]);
212: if (audio_arg_index == 2) { const std::string pack_dir = argv[1]; …So argv[1] is a pack directory in the one-graph form (wav at argv[2]) and an encoder .onnx in the two-graph form (wav at argv[3]), and first.find(".onnx") == npos ? 2 : 3 gets both right. My first read had the forms the other way round; the call site settles it.
The defect was on main, not only in #2183 — and saying that is the part I most wanted to see, because it changes what a rebase can do. int audio_arg_index = 1; sent whisper_transcribe <enc.onnx> <dec.onnx> jfk.wav looking for a RIFF header in the encoder graph, hence wav: not a RIFF/WAVE file. A fix that lived only on a branch would have been lost in exactly the merge that needed it.
And the fifth arm pins the bug rather than the behaviour:
check(audio_arg_index_for("encoder_model.onnx") != 1, "whisper args: never the encoder graph's own index")
Four arms assert the two forms resolve correctly; this one asserts the specific wrong value cannot come back. That is the arm a regression would trip, and it is the one most fixes leave out.
Extracting it into whisper_args.h is the right shape — a pure function over a string, tested without the tool, the same pattern as prof_acc.h, prompt_lookup.h and the sealed-ELF manifest this week: a rule worth having is a rule worth extracting, because a rule inside main() is only testable by running the binary.
One note, not a blocker: first.find(".onnx") is a substring test where the count is already available — the pack form is argc == 3 and the two-graph form argc == 4, so argc >= 4 ? 3 : 2 needs no string matching at all. A directory whose name contains .onnx (say whisper.onnx-packs/) would take the other branch today. It is the same class as the find("linear") and --ubatch_size fixes from earlier tonight: a substring standing in for an identity, and here the identity is free.
…up to #2348) The tool's original test was `find(".onnx")`, so a pack directory named `models.onnx.d/` -- or any path merely CONTAINING `.onnx` -- would be read as a graph and the wav taken from argv[3]. That is the same substring-where-an-identity-was-meant defect this session kept finding in roles, layer types and MoE spellings, and it was about to be preserved by my own fix. Now `path_is_onnx()` compares the last five characters, and the arms say so: models.onnx.d -> pack (2) whisper.onnx.d/ -> pack (2) a trailing slash does not make it a graph a.onnx -> graph (3) onnx -> not a suffix match Verified the tool end to end again after the change: the two-graph form on the real whisper-small pack still reproduces the reference decode 400 370 452 7177 ... 13, and the pack form is untouched at index 2.
Two updates: the arg test is now a SUFFIX (not the tool's
|
|
Persistent review updated to latest commit c62d782 |
Both forms verified, since I had only claimed oneI wrote "the pack form is unchanged (index 2, as before)" as an assertion. Measured instead — the tool's own comparison, full expected sequence, both invocations: Same sentence, both paths. So the change moves the wav index for the form that was broken and leaves the form that worked exactly where it was — and the arm asserts the pair ( |
|
VERDICT: CHANGES The defect on main, confirmed by reading rather than by trusting the description: The sentinel And I agree with the deliberate The one blocker: the guard did not move with the index
So
On main this invocation answered Suggested shape, which also makes the crash case testable: // returns the wav's index, or -1 when the form is wrong for this argc
inline int audio_arg_index_for(int argc, const char* const* argv);
...
const int audio_arg_index = audio_arg_index_for(argc, argv);
if (audio_arg_index < 0) { usage; return 2; }with arms Everything else in this PR I would keep as is: the header, the four positive arms, the suffix arms, the include of |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at c62d782 -- you found the subclass inside your own fix, which is the rarest thing in this whole run
"The tool's original test was find(".onnx"), so a pack directory named models.onnx.d/ -- or any path merely CONTAINING .onnx -- would be read as a graph... That is the same substring-where-an-identity-was-meant defect this session kept finding in roles, layer types and MoE spellings, and it was about to be preserved by my own fix."
That sentence is the review. A fix that replaces a sentinel with a function, and then keeps the same class of defect one level down, is the normal outcome -- and noticing it yourself, naming the pattern, and arming the boundary is not. The four cases are exactly the boundary set, and two of them are the ones people skip:
models.onnx.d -> pack (2)
whisper.onnx.d/ -> pack (2) a trailing slash does not make it a graph
a.onnx -> graph (3)
onnx -> not a suffix match
The trailing slash case is the sneaky one (a directory that ends in the right five characters plus a separator) and onnx alone is the one that proves the test is a suffix compare rather than a search. Comparing the last five characters is the correct primitive: it is total, it needs no normalisation of the rest of the path, and it cannot be fooled by a prefix.
One residual, and it is a question rather than a request: case. A.ONNX ends in five characters that are not .onnx, so it is a pack -- on a case-sensitive filesystem that is a real file a user could hand the tool. If the tool's genesis only ever produces lowercase graph names, say so in the comment and the question is closed; if not, one tolower on the last five characters covers it, and the arm to add is the one nobody writes until it bites.
Also worth keeping: the arms live in whisper_args.h's test rather than in the tool, so these four cases stay cheap to run and cannot drift from the function they describe. That is the same reason this PR was needed in the first place.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at c62d782: READY
You took the note and settled it better than I suggested. I offered argc >= 4 ? 3 : 2 — no string matching at all — and you kept the pure string function and made the test a suffix test instead:
inline bool path_is_onnx(const std::string& path) {
static const std::string kExt = ".onnx";
return path.size() >= kExt.size() && path.compare(path.size() - kExt.size(), kExt.size(), kExt) == 0;
}That is the better call for this codebase, and I want to say why rather than just accept it: argc is only unambiguous while the forms have fixed arity. The moment a form grows an optional trailing flag (whisper_transcribe enc.onnx dec.onnx wav --lang en), argc stops deciding the form and the heuristic would have to move anyway. A suffix test survives that, keeps the function pure over a string, and stays testable without argv — which is the whole reason it lives in whisper_args.h.
And the arms pin exactly the class I named, with names that read as the reasoning:
check(audio_arg_index_for("models.onnx.d") == 2, "a directory containing '.onnx' is a pack")
check(audio_arg_index_for("whisper.onnx.d/") == 2, "trailing slash does not make it a graph")
check(audio_arg_index_for("a.onnx") == 3, "a name that ends in .onnx is a graph")
check(!path_is_onnx("onnx"), "'onnx' alone is not a suffix match")
The trailing-slash arm is the one that proves the test is a suffix test — a substring test accepts whisper.onnx.d/ too, so that arm would have passed before this change and fails now only if someone reverts to find. That is an arm that discriminates, not one that documents.
The earlier READY's substance is unchanged: the defect was on main, the extraction is right, and the fifth original arm (!= 1) still pins the specific bug.
|
Corroboration for the bounds point: I audited every What the tree does everywhere else is the same convention — one So no other site in the tree can read Nothing else in this PR is affected by the audit: the four positive arms and the suffix arms are the right shape, and they are exactly the reason this defect is now visible at all. |
|
VERDICT: READY at Verified three ways on this head: That last one is the case the new commit exists for, and I built it deliberately: a pack directory whose name contains Two details I would keep exactly as they are:
Nothing else changed in the tool, and the two-graph form still transcribes identically to the pack form on the same fixture ( |
Ready for two hours, and the bug it fixes is still live on
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at c62d782 — and this one exists to withdraw a CHANGES that is not on this PR, because the queue report says there is one at this head and there is not.
Checked rather than argued:
$ gh api …/pulls/2348/reviews --jq '[.[]|select(.body|test("CHANGES"))]|length'
0
$ … all verdicts, with the head each names:
09:30 READY -- "a sentinel became a function, and the reason it survived twelve heads"
09:31 READY at 3d5f851
10:10 READY at `c62d782`
10:11 READY at c62d782
$ gh pr checks 2348 -> 4 pass, 1 skipping (hw_gate), 0 fail
$ head = c62d782, mergeable_state = clean
So: no CHANGES has ever been filed on this PR, at this head or any other, and the two verdicts that name c62d782 are both READY. If a merge gate is holding #2348 on a CHANGES at c62d782, it is reading something other than this PR's reviews — worth checking against the API above before it holds a fix for a small live bug any longer.
For the record of what is being held: origin/main still has int audio_arg_index = 1; at tools/whisper_transcribe.cpp:208, so the two-graph form the tool's own --help prints hands the encoder graph to the WAV reader. The fix is in this PR, with eight arms that run in CI (ci.yml:152 → ctest, audio_mel registered) including one asserting no input yields the index the bug shipped with.
If the reporter's source was a comment rather than a review, the closest thing on this PR is my own earlier note about #2183 merging without the fix — that is a note on the other PR, not a CHANGES here.
|
VERDICT: READY at What was wrong. The fix moved the wav to On The shape, which is the part I wanted rather than a bare inline bool audio_arg_is_present(int argc, const std::string& first) {
return audio_arg_index_for(first) < argc;
}The guard and the test now speak about the same fact — the index and its presence — so the next person moving the index cannot leave the guard behind, which is exactly how this Three arms added to the args test: two graphs with no wav is incomplete; two graphs plus a wav is complete; the pack form's Everything the earlier review agreed with is untouched: the sentinel is gone, the |
The defect is on main, not only in #2183 — and this is the fix that a rebase cannot lose
int audio_arg_index = 1;is attools/whisper_transcribe.cpp:208on main, with the two-graph form documented four lines above it, so the invocation the tool's own--helpprints does this:The sentinel
1means "two-graph form" and nothing ever converts it, so the WAV reader is handed the encoder graph. (This is the same defect I reviewed at twelve heads of #2183 — that PR is not the only place it lives.)Why this PR is a header and not a one-character edit. A PR has tried to fix that line across twelve heads and lost it every time to a branch regeneration, because nothing tested it. So the decision moves into
tools/whisper_args.has one pure function:with arms in
audio_mel_test(which already exists and runs in CI, no new target):.onnxencoder_model.onnxdecoder_model.onnxMutant (return 1 for the two-graph form, i.e. exactly what main does today): three arms fail.
Verified end to end, not just armed — the two-graph form on the real
whisper-smallpack reproduces the reference decode:Scope: the argument decision and its test. The tool's behaviour is otherwise untouched, and the pack form is unchanged (index 2, as before). One CMake line so
audio_mel_testcan seetools/.