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; 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