Front end: leave the engine's 8-slot reserve out of max_new

The engine refuses a request unless prompt + max_new + 8 <= context, but
the front end sized max_new as context - prompt, so any client asking for
more tokens than remained (pi sends max_tokens 32768 on a 64K card) was
refused with "prompt (N) + max_new (M) exceeds the context" on every
prompt longer than context - max_tokens. Seen on the 1080 Ti Coder right
after a pi compaction left a 48K prompt.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Robert KarlandClaude Fable 5.1 committed 2026-10-12 19:27:36 -07:00
1 parent f07b81e08b
commit 121d23ac2e
1 file changed
+6 -2
+6 -2
View File
@@ -227,13 +227,17 @@ struct Server {
p.parser.parse_tool_calls = true;
if (!cp.parser.empty()) p.parser.parser.load(cp.parser);
// The engine refuses a request unless prompt + max_new + 8 <= context (generate.cpp, the GEN handler), so
// the slots it keeps back are not ours to promise. Without this a client that asks for "as much as fits"
// (pi sends max_tokens 32768 on a 64K card) was refused on every prompt longer than ctx - max_tokens.
constexpr long long kEngineReserve = 8;
const long long n = (long long) p.ids.size();
if (n + 1 > opt.ctx) {
if (n + 1 + kEngineReserve > opt.ctx) {
err = "the prompt is " + std::to_string(n) + " tokens, which does not fit the context of " +
std::to_string(opt.ctx);
return false;
}
long long max_new = opt.ctx - n;
long long max_new = opt.ctx - n - kEngineReserve;
for (const char* key : {"max_completion_tokens", "max_tokens"})
if (body.contains(key) && body.at(key).is_number()) {
const long long want = body.at(key).get<long long>();