From 49c3ce2c4fb674326eb7e720ba8807f6be100dd7 Mon Sep 17 00:00:00 2001 From: bcloud Date: Sat, 14 Nov 2026 22:11:26 -0400 Subject: [PATCH 1/2] common/sampling: one line to see whether the fast greedy path was TAKEN, not just eligible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fast greedy path has no observable. `common_sampler_fast_greedy_eligible()` decides at init, `result->fast_greedy` is set, and `common_sampler_fast_greedy_argmax()` is called per token -- with nothing logged, counted or reported anywhere. That makes a whole class of regression invisible by construction: a run whose eligibility silently stops holding (a server default that sets n_probs, a grammar appearing, a reasoning budget) keeps producing CORRECT tokens and loses the entire gain, so every output-based test still passes. It surfaced on engine#2452: the pin carries #385's fast path, and the review asked for an engine-level greedy comparison -- same prompt before and after the pin. That arm cannot assert the thing that matters, because "the output matched" is true whether the optimisation ran or not. So: one fprintf, opt-in, once per sampler: LLAMA_LOG_FAST_GREEDY=1 llama-cli -m ... --temp 0 common_sampler: fast_greedy=1 (eligible=1, LLAMA_NO_FAST_GREEDY=unset) LLAMA_LOG_FAST_GREEDY=1 llama-cli -m ... --temp 0.7 common_sampler: fast_greedy=0 (eligible=0, LLAMA_NO_FAST_GREEDY=unset) LLAMA_NO_FAST_GREEDY=1 LLAMA_LOG_FAST_GREEDY=1 llama-cli -m ... --temp 0 common_sampler: fast_greedy=0 (eligible=1, LLAMA_NO_FAST_GREEDY=set) The third arm is the useful one: eligible but overridden prints `0 (eligible=1, …=set)`, so the two conditions are distinguishable in a log rather than conflated. Verified on a 1.5B model at `-ngl 0`, i.e. no device needed, and the env gate means a normal log is byte-identical to before. Nothing else changes: no behaviour, no default, no output on stderr unless the variable is set. --- common/sampling.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/sampling.cpp b/common/sampling.cpp index 41ca9e8534c0..8f69bf320468 100644 --- a/common/sampling.cpp +++ b/common/sampling.cpp @@ -522,6 +522,15 @@ struct common_sampler * common_sampler_init( } } result->fast_greedy = ok && getenv("LLAMA_NO_FAST_GREEDY") == nullptr; + // engine#2452: the fast path had no observable, so an engine-level arm could assert only that the OUTPUT was + // right -- which is true whether or not the optimisation ran. A run that silently stops being eligible keeps + // producing correct tokens and loses the whole gain, and no test can see that. One line, printed once per + // sampler, opt-in so it never pollutes a normal log. + if (getenv("LLAMA_LOG_FAST_GREEDY") != nullptr) { + fprintf(stderr, "common_sampler: fast_greedy=%d (eligible=%d, LLAMA_NO_FAST_GREEDY=%s)\n", + (int) result->fast_greedy, (int) ok, + getenv("LLAMA_NO_FAST_GREEDY") != nullptr ? "set" : "unset"); + } } return result; From d362b8684e95aa73ecd25a732b89cfddbc49ba88 Mon Sep 17 00:00:00 2001 From: bcloud Date: Sat, 14 Nov 2026 22:30:01 -0400 Subject: [PATCH 2/2] tests: consume the fast-greedy log line, so the observable is checked and not just written MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review on this PR made the point exactly: the line tells you whether the fast greedy path was TAKEN, and nothing consumed it -- "nothing can answer the question" became "nothing checks the answer", which is the same defect one level up from the regression the line exists for. The consumer is a behaviour row in the shape `test-mtp-one-request.sh` already established: it needs a small GGUF (CPU only, `-ngl 0`), takes it from `ONEBIT_FAST_GREEDY_MODEL`, and reports SKIP (77) without one, so CI is a recorded skip and a box with a model runs three arms: --temp 0 fast_greedy=1 (eligible=1, LLAMA_NO_FAST_GREEDY=unset) the path is taken --temp 0.7 fast_greedy=0 (eligible=0, LLAMA_NO_FAST_GREEDY=unset) not eligible LLAMA_NO_FAST_GREEDY=1 --temp 0 fast_greedy=0 (eligible=1, LLAMA_NO_FAST_GREEDY=set) eligible but overridden The third is the arm that justifies printing two booleans: a single boolean cannot express it. Verified by mutation -- make the line print eligibility twice (the natural single-boolean mistake) and arms 1 and 2 still pass while arm 3 fails with `want 'fast_greedy=0 (eligible=1, …set)' got 'fast_greedy=1 (…)'`. Restored, all three pass. Local run against a 1.5B model: `test-fast-greedy-log: OK`. --- tests/CMakeLists.txt | 11 ++++++++++ tests/test-fast-greedy-log.sh | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 tests/test-fast-greedy-log.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2b746e25f5ea..6826c29cf339 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -165,6 +165,17 @@ if (NOT WIN32 AND LLAMA_BUILD_SERVER) # CI leaves ONEBIT_MTP_TEST_MODEL unset, so the row is SKIP there. TIMEOUT must exceed the script's own worst # case (health 200 x 5 s + the 600 s request = ~1600 s), or a slow load is cut off before its exit code prints set_tests_properties(test-mtp-one-request PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 1800) + + # llama.cpp#391: the fast greedy path's log line is the only observable of whether the optimisation was TAKEN. + # A round of review pointed out that the line had no consumer, which is the same defect one level up from the + # regression it exists to catch; this row is the consumer. Needs a small GGUF (CPU only), else SKIP (77). + llama_test_cmd( + ${CMAKE_CURRENT_SOURCE_DIR}/test-fast-greedy-log.sh + NAME test-fast-greedy-log + LABEL behavior + ARGS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + ) + set_tests_properties(test-fast-greedy-log PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 900) endif() if (NOT WIN32) diff --git a/tests/test-fast-greedy-log.sh b/tests/test-fast-greedy-log.sh new file mode 100755 index 000000000000..a4157357eafe --- /dev/null +++ b/tests/test-fast-greedy-log.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# engine#2452 / llama.cpp#391 regression arm: the fast greedy path's log line is the only way to know whether the +# optimisation was TAKEN. A run whose eligibility silently stops holding keeps producing correct tokens and loses the +# gain, so every output-based test still passes -- this row asserts the two conditions are distinguishable instead. +# +# ONEBIT_FAST_GREEDY_MODEL=/path/to/small.gguf unset or missing -> SKIP (77); CI leaves it unset. +# BIN_DIR a build's bin/ (llama-cli) +# +# Exit codes: 0 all arms hold; 1 an arm failed; 77 no model (skip). +set -uo pipefail +BIN_DIR=${1:?usage: test-fast-greedy-log.sh } +M=${ONEBIT_FAST_GREEDY_MODEL:-} +if [ -z "$M" ] || [ ! -f "$M" ]; then + echo "test-fast-greedy-log: ONEBIT_FAST_GREEDY_MODEL unset or missing, SKIP" + exit 77 +fi +CLI="$BIN_DIR/llama-cli" +[ -x "$CLI" ] || { echo "test-fast-greedy-log: no llama-cli in $BIN_DIR"; exit 77; } + +run() { # -- ; prints the fast_greedy line + env "$@" 2>&1 | grep -oE 'fast_greedy=[01] \(eligible=[01], LLAMA_NO_FAST_GREEDY=(set|unset)\)' | head -1 +} +fail=0 +chk() { if [ "$2" = "$3" ]; then echo " ok $1"; else echo " FAIL $1: want '$3' got '$2'"; fail=1; fi; } + +# 1. greedy: the path is taken +chk "a greedy run takes the fast path" \ + "$(run LLAMA_LOG_FAST_GREEDY=1 "$CLI" -m "$M" -ngl 0 -p hi -n 2 --temp 0)" \ + "fast_greedy=1 (eligible=1, LLAMA_NO_FAST_GREEDY=unset)" +# 2. not greedy: not eligible +chk "a sampled run is not eligible" \ + "$(run LLAMA_LOG_FAST_GREEDY=1 "$CLI" -m "$M" -ngl 0 -p hi -n 2 --temp 0.7)" \ + "fast_greedy=0 (eligible=0, LLAMA_NO_FAST_GREEDY=unset)" +# 3. the override: eligible but NOT taken -- the arm a single boolean could not express +chk "the override is distinguishable from ineligibility" \ + "$(run LLAMA_NO_FAST_GREEDY=1 LLAMA_LOG_FAST_GREEDY=1 "$CLI" -m "$M" -ngl 0 -p hi -n 2 --temp 0)" \ + "fast_greedy=0 (eligible=1, LLAMA_NO_FAST_GREEDY=set)" + +echo "test-fast-greedy-log: $([ $fail = 0 ] && echo OK || echo FAILED)" +exit $fail