From 3d5f851a7242ae7acfb0763d151e13cc15438e18 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Fri, 13 Nov 2026 04:44:36 -0400 Subject: [PATCH 1/2] whisper_transcribe: main's two-graph form reads the encoder graph as 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 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 --- CMakeLists.txt | 2 +- tests/audio_mel_test.cpp | 12 ++++++++++++ tools/whisper_args.h | 34 ++++++++++++++++++++++++++++++++++ tools/whisper_transcribe.cpp | 9 ++++----- 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 tools/whisper_args.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 95dbd65d6..0fe0e5f76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1558,7 +1558,7 @@ add_executable(whisper_transcribe tools/whisper_transcribe.cpp) target_include_directories(whisper_transcribe PRIVATE npu/forward/include) target_link_libraries(whisper_transcribe PRIVATE onebit_npu) add_executable(audio_mel_test tests/audio_mel_test.cpp) -target_include_directories(audio_mel_test PRIVATE npu/forward/include) +target_include_directories(audio_mel_test PRIVATE npu/forward/include ${CMAKE_SOURCE_DIR}/tools) # engine#2183: whisper_args.h add_executable(audio_exec_test tests/audio_exec_test.cpp) target_link_libraries(audio_exec_test PRIVATE onebit_npu) # The executor's fork-join (npu/audio_parallel.h): MatMul bit-identical across ONEBIT_AUDIO_THREADS, and a throwing unit diff --git a/tests/audio_mel_test.cpp b/tests/audio_mel_test.cpp index e7c368443..1f326d5fa 100644 --- a/tests/audio_mel_test.cpp +++ b/tests/audio_mel_test.cpp @@ -23,6 +23,7 @@ #include #include +#include "whisper_args.h" #include "audio_mel.h" namespace { @@ -100,6 +101,17 @@ int main() { // bites and the scale gives (-10+4)/4 = -1.5. (My first expectation here said 1.0 -- the test caught its author again.) expect_close(smel[0], -1.5f, 1e-6, "silence lands on the log floor: (-10+4)/4 == -1.5"); + // engine#2183: WHERE the wav is. The tool carried a sentinel `int audio_arg_index = 1;` meaning "two-graph form" and never + // converted it, so the documented `whisper_transcribe enc.onnx dec.onnx file.wav` handed the ENCODER GRAPH to the wav reader + // and answered "wav: not a RIFF/WAVE file" for the invocation its own --help prints. Twelve heads of a PR tried to fix that + // line and lost it to rebases; this arm is the fix that a rebase cannot lose. + check(audio_arg_index_for("pack-dir") == 2, "whisper args: the pack form's wav is argv[2]"); + check(audio_arg_index_for("whisper-small") == 2, "whisper args: a directory without .onnx is a pack"); + check(audio_arg_index_for("encoder_model.onnx") == 3, "whisper args: the two-graph form's wav is argv[3]"); + check(audio_arg_index_for("decoder_model.onnx") == 3, "whisper args: either graph decides it"); + // the value the bug shipped with must be unreachable: no input yields the encoder-graph index 1 + check(audio_arg_index_for("encoder_model.onnx") != 1, "whisper args: never the encoder graph's own index"); + if (g_failures != 0) { std::printf("audio mel: %d failures\n", g_failures); return 1; diff --git a/tools/whisper_args.h b/tools/whisper_args.h new file mode 100644 index 000000000..6eb502c1d --- /dev/null +++ b/tools/whisper_args.h @@ -0,0 +1,34 @@ +// Copyright 2026 bong-water-water-bong +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// whisper_args.h -- where the wav sits on whisper_transcribe's command line (engine#1783, engine#2183). +// +// Two forms are documented in the tool's own usage block: +// +// whisper_transcribe ... the wav is argv[2] +// whisper_transcribe ... the wav is argv[3] +// +// The tool used to carry `int audio_arg_index = 1;` as a "sentinel" meaning "two-graph form", and nothing ever converted it, +// so the two-graph form read argv[1] -- the ENCODER GRAPH -- as the wav and answered "wav: not a RIFF/WAVE file" for the +// invocation its own --help prints. This function is that decision, in one place, so a test can hold it and a rebase cannot +// quietly lose it: the defect survived twelve heads of a PR that kept being regenerated from a base without the fix. +#pragma once + +#include + +// The index of the wav among argv. `first` is argv[1]: anything carrying `.onnx` is a graph, which means the two-graph form. +inline int audio_arg_index_for(const std::string& first) { + return first.find(".onnx") == std::string::npos ? 2 : 3; +} diff --git a/tools/whisper_transcribe.cpp b/tools/whisper_transcribe.cpp index 1657023ee..e9d8143e9 100644 --- a/tools/whisper_transcribe.cpp +++ b/tools/whisper_transcribe.cpp @@ -37,6 +37,7 @@ #include #include +#include "whisper_args.h" #include "audio_exec.h" #include "audio_pack.h" #include "whisper_ids.h" @@ -204,12 +205,10 @@ int main(int argc, char** argv) { std::string dec_path = (argc > 2) ? argv[2] : ""; std::string why; - // `1` means the two-graph form is in use and the wav is argv[3]; the pack form sets this to 2 after it discovers the graphs. - int audio_arg_index = 1; onebit::audio::MelConfig cfg; - // The pack form is decided by the first argument: a directory (or anything without `.onnx`) is a pack, and it also carries the - // mel-bin count, which has to be known before the wav is turned into a spectrogram. - if (argc >= 3 && std::string(argv[1]).find(".onnx") == std::string::npos) audio_arg_index = 2; + // Where the wav is: argv[2] for the pack form, argv[3] for the two-graph form. Decided once, in tools/whisper_args.h, so + // that a test can hold it -- the old sentinel `1` was never converted and made the two-graph form read the encoder graph. + const int audio_arg_index = audio_arg_index_for(argv[1]); if (audio_arg_index == 2) { const std::string pack_dir = argv[1]; onebit::audio::AudioPack pack; From c62d7821c5a31ff019a20e5586f00c251b8eb6a9 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Fri, 13 Nov 2026 05:31:35 -0400 Subject: [PATCH 2/2] whisper args: a SUFFIX test, not a substring one (engine#2183 follow-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. --- tests/audio_mel_test.cpp | 5 +++++ tools/whisper_args.h | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/audio_mel_test.cpp b/tests/audio_mel_test.cpp index 1f326d5fa..bb008f13d 100644 --- a/tests/audio_mel_test.cpp +++ b/tests/audio_mel_test.cpp @@ -111,6 +111,11 @@ int main() { check(audio_arg_index_for("decoder_model.onnx") == 3, "whisper args: either graph decides it"); // the value the bug shipped with must be unreachable: no input yields the encoder-graph index 1 check(audio_arg_index_for("encoder_model.onnx") != 1, "whisper args: never the encoder graph's own index"); + // and the test is a SUFFIX, not a substring: a directory whose name merely contains ".onnx" is still a pack + check(audio_arg_index_for("models.onnx.d") == 2, "whisper args: a directory containing '.onnx' is a pack"); + check(audio_arg_index_for("whisper.onnx.d/") == 2, "whisper args: trailing slash does not make it a graph"); + check(audio_arg_index_for("a.onnx") == 3, "whisper args: a name that ends in .onnx is a graph"); + check(!path_is_onnx("onnx"), "whisper args: 'onnx' alone is not a suffix match"); if (g_failures != 0) { std::printf("audio mel: %d failures\n", g_failures); diff --git a/tools/whisper_args.h b/tools/whisper_args.h index 6eb502c1d..2a518745c 100644 --- a/tools/whisper_args.h +++ b/tools/whisper_args.h @@ -28,7 +28,16 @@ #include -// The index of the wav among argv. `first` is argv[1]: anything carrying `.onnx` is a graph, which means the two-graph form. +// The index of the wav among argv. `first` is argv[1]: a path ENDING in `.onnx` is a graph, which means the two-graph form. +// +// The test is a suffix, not a substring, and that is deliberate: the tool used `find(".onnx")`, so a pack directory named +// `models.onnx.d/` or a file named `whisper.onnx.d/` would have been read as a graph and the wav taken from argv[3] -- the +// same substring-where-an-identity-was-meant defect that this session kept finding in roles, layer types and MoE spellings. +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; +} + inline int audio_arg_index_for(const std::string& first) { - return first.find(".onnx") == std::string::npos ? 2 : 3; + return path_is_onnx(first) ? 3 : 2; }