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..bb008f13d 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,22 @@ 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"); + // 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); return 1; diff --git a/tools/whisper_args.h b/tools/whisper_args.h new file mode 100644 index 000000000..2a518745c --- /dev/null +++ b/tools/whisper_args.h @@ -0,0 +1,43 @@ +// 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]: 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 path_is_onnx(first) ? 3 : 2; +} 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;