Commit Graph
6 Commits
Author SHA1 Message Date
Niko1221 07f611c755 Merge f-agent-cap 33648fef1 into f-p4-int (STRATA_SERVE_STOP_SKIP, default on: a decode window that finishes after the server's STOP is dropped whole)
One commit on 5aa7f1d88 (in this branch). Owner: OK to take it (11-12). Lane gates as relayed: cmake-cpu 78 / 0 / 4, device code 3,852 functions
identical on sm_86, decode speed ratio median 0.998, stop turns left with unreturned tokens 49 of 56 -> 37 of 56, cap rows 0 of 19, pipelined
stop turns identical 18 of 18 on / off. No conflict, nothing changed by hand.
2026-11-12 08:33:02 +01:00
Niko1221 33648fef1e serve: a decode window that finishes after the server's STOP is dropped whole
When the server ends a pass (a stop string, a client that left, a repeat or loop stop) it sends STOP and throws away every token that comes after it. The engine
sees STOP only at the end of a window, so the window that was running had already committed its rows: the session ended one or two windows past the tokens the
client was sent, and the next request of the conversation could not continue from it (the state is recurrent and cannot be cut back) and fell back to the newest
checkpoint, reading the cut reply again.

A window that finishes with STOP already set is now neither committed nor printed, in the serial loop and in the pipelined loop (a front stage that the speculative
window ran on goes back to the snapshot taken before the dropped window, with no replay). Not dropped: a merged window, the request's first window, and a window
whose state the one-token path advanced itself (Verifier::commit_deferred()). A request that ends by its cap or by EOS never sets the flag and takes the path it
took before; the cost in the loop is one flag read per window. The tokens a client receives do not change: the rows dropped were never sent.

STRATA_SERVE_STOP_SKIP=0 turns it off (research switch, on by default; register entry added). The decision is a pure function in serve_stop_bound.hpp with a unit
test (decision table and a ledger of the loop).

Part of lane AGENT-CAP (candidate C).
2026-11-12 05:52:51 +01:00
Niko1221 b92075d924 serve: the thinking budget's hold on --batch engines (BGEN slots)
P2 ended the budget's first pass exactly at the budget for a solo request; a --batch engine kept the old behaviour (the server sent no hold to it), so there the second pass still read the whole reasoning again in 8-9 of 21-24 budget turns (p1004, --batch 2: base 9 of 24, head 8 of 21, PERF-AUDIT's R9700 and l620 runs the same shape).

Engine (src/program/generate.cpp, include/strata/core/serve_stop_bound.hpp): a slot carries the hold (SlotHold: on / n / id). BGEN hold=N:ID is parsed by the GEN path the admission runs; at the handover the slot takes the hold unless the admission's one token was </think>, and an admission whose hold is that one token ends there (DONE hold, no slot). In the slot windows the rows a window may commit stop at the hold (slot_cap(), in the MTP window, the pipelined MTP window's proposal count and the DFlash2 draft count), a slot ends with BDONE hold after exactly N emitted tokens unless ID was emitted first, and its sessions then hold exactly the tokens it fed, as in the solo case. The cap is the conservative one for a window that might emit ID: it stops at the hold and the next window goes on. READY says "stop hold holdb"; "holdb" is a protocol token only (no user-visible line, no setting).

Server (serve/server.py): the budget sends the hold to a --batch engine only when its READY says holdb (can_hold_batch); generate_batched adds the key per leg with the tokens the pass has already sent taken off (a solo leg promoted to a slot continues with hold=N-k, none once </think> was sent), and a leg that ends with finish "hold" ends the pass.

Tests: tests/core/serve_stop_bound_test.cpp (slot windows of changing width against a per-token reference over a whole reply: 75,360 cases; same tokens, same finish, no row committed past what was emitted, the hold ending at exactly N unless ID came first); serve/test_thinking_hold_batch.py (a fake --batch engine with the hold: solo path, a request admitted into a slot, a solo leg promoted to a slot with the count falling, first-N tokens of the unheld reply for N = 1 ... 53, hold ended by its token); serve/test_thinking_hold.py (stub engine with holdb).

The slot-model case failed on its first run (first=0 hold=1 max_new=3 id_at=0: got 7777 101 103, reference 7777 101 102). The test model was wrong, not the engine: it read a window's rows with `produced`, which it increments while the window is emitted, so it skipped a row; the engine emits from fixed arrays (outb[first + j]). Fixed in the test with a base index; the engine code was not changed by that run.

Mixed versions, both covered: new server + old engine (an engine without hold, and one with hold but no holdb, get no key when they run --batch; the budget cuts and STOPs as before) in test_thinking_hold.py, and old server + new engine (the extra READY tokens change nothing it reads, a request without a key runs as before through the solo path and through a slot) in test_thinking_hold_batch.py. Real-engine cross runs of P2 (head engine + base server, base engine + head server) were done on p1004 before this commit.

Lane AGENT-TURN, P2b.
2026-11-11 21:22:34 +01:00
Niko1221 be101072ba serve: the thinking budget's hold (GEN hold=N:ID), so the wrap-up pass continues from the live session
At the thinking budget the server cut the stream, STOPped the engine and sent a second engine request: the same prompt + the tokens it kept + the wrap-up. The engine sees STOP only at a window's end and commits each window before sending it, so it often held one or more tokens past the cut; its live session was then not a prefix of the second request, which fell back to the checkpoint before the assistant turn, parked the live branch and read the whole reasoning again (lane PERF-AUDIT, R9700 0.1.59: 4 of 9 budget turns, 535 tokens, 849-1000 ms against 85-96 ms).

Engine: GEN key hold=N:ID ends the request after N emitted tokens unless token ID (</think>) came first; the commit is capped there (serve_hold_remaining() + serve_stop_bound(), tested against the emission loop in serve_stop_bound_test), DONE finish "hold", READY says "stop hold". Without the key nothing changes; an older engine skips the key.
Server: sends hold=<budget - thought>:<</think> id> (HOLD_KEY, its own key, never a client's) only to an engine that says hold in READY, has no --batch slots and is not a multi engine, and only when </think> is one token. At DONE hold it wraps up if the point is clean; if not (a character split across tokens, a tag held back) one more pass from the live session with a hold of the tokens left (at least one). The second pass then reads the last token and the wrap-up only. Tested with a windowed stub engine in serve/test_thinking_hold.py: the answer is the same with and without the hold for every budget; an engine that does not say hold gets no key; one that says it but ignores it gives the same answer.
--batch engines (BGEN slots) are a separate path: not covered here, no hold is sent to them.

Lane AGENT-TURN, P2.
2026-11-11 16:18:59 +01:00
Niko1221 7d4f78242c serve: the #4677 stop bound on every backend, not only HIP
serve_stop_bound() caps the accepted rows a decode window commits at the rows the request can still emit (max_new) and at the first EOS, so the conversation the session keeps is exactly what the client got and the next continuation reuses it instead of falling back to the older checkpoint. It was compiled for HIP only, where it was measured (4 x R9700: 4 of 16 continuations fell back without it, 0 of 16 with it). It changes no emitted token; on CUDA it now applies too. STRATA_SERVE_STOP_BOUND=0 still turns it off (serve_stop_bound_on(), tested in serve_stop_bound_test). Host code only (generate.cpp is compiled as C++). The register entry's backend is now cuda-hip.

Part of lane AGENT-TURN (P1); the thinking-budget hold (P2) needs the bound on every backend.
2026-11-11 15:35:46 +01:00
hanchengme 243fdb213c serve: a request commits only the rows it can emit, so the parked snapshot matches what the client got (#4677)
In the single-request speculative paths the accepted rows of a verify window were committed first and the output loop cut to max_new or EOS afterwards, so a request's last window could park a snapshot with tokens the client never received. conversation_prefix() needs the whole snapshot to be a prefix of the next prompt, so the snapshot was refused and the older checkpoint was used (about 6% of a 12K-token prompt read again).
serve_stop_bound() caps the accepted rows at the rows the request can still emit and ends at the first EOS, before pl_commit_async. Merged prompt windows keep committing every row. HIP only (STRATA_USE_HIP), where it was measured.
Patch and policy test (2,736 cases against the old loop) by hanchengme, from the issue's attachment. Two changes on our side: it is on by default, STRATA_SERVE_STOP_BOUND=0 turns it off; the test is registered in CMake.
Measured on 4 x R9700, Qwen3.8-Flash-Next IQ3_S, 2 replicas x 2 cards, --batch 8 --batch-groups 2, four 11-15K-token conversations with 768-token answers, conversations opened one at a time: 4 of 16 continuations fell back to the older checkpoint without it, 0 of 16 with it (reuse 98.36% against 99.74%). Opened together as batch rows both builds miss the same continuations (slot overwritten before it is parked); not changed here.
2026-11-01 12:21:56 +01:00