Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions tests/test-fast-greedy-log.sh
Original file line number Diff line number Diff line change
@@ -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 <bin dir>}
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() { # <env assignments...> -- <cli args...>; 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