Repository navigation
Description
This is the residue #751's close deliberately deferred. #751 was closed documented, not fixed: --parallel 1 is
the reproducible configuration and docs/determinism.md says so. Its close comment recorded that option 2 — a width
gate on the kernels that must satisfy batch invariance, the way a deterministic-GEMM path pins its K-reduction tree —
"belongs in a new issue, not this one". This is that issue. Nothing below is a new claim about whether the effect
exists; it is the op-level inventory a fix would have to cover, plus an acceptance test that already ships.
What a user sees
Two byte-identical greedy requests served at the same time return different log-probabilities, and a request's numbers
depend on how many other sequences happen to decode with it on that step. Text usually survives; the numbers do not.
Measured on the shipped payload, Qwen3-0.6B-Q4_K_M, greedy, probe "Explain in one paragraph why the sky appears blue.":
| configuration | route | result |
|---|---|---|
| width 1, repeated, and after other prompts ran sequentially | cpu, hrx |
bit-exact, 0/12 trials moved (so: not cache state, not warm-up) |
| width 2 / 3 / 4 / 8 (probe + k-1 fillers in flight) | hrx |
moved 12/12, max |Δlogp| 9.0e-02 … 1.4e-01 at every width |
| two identical copies issued together, width 2 | hrx |
copies disagree with each other, 43-44 of 48 positions bit-moved |
| width 4, 4 rounds × 4 identical concurrent requests | cpu |
not repeatable: 6/12 round-to-round identical, 4 distinct states |
| width 8, 8 rounds × 8, same test | hrx |
0/24 round-to-round identical, 16 distinct states (all copies distinct) |
| any batched copy vs the solo answer | cpu, hrx |
0 of 104 copies equal solo |
So the gate is crossed once at width 2 and stays crossed — the displacement is the same order at 2, 3, 4 and 8 — and
the state is the per-step batch composition, not the --parallel configuration: one request against a --parallel 2
serve and against a --parallel 8 serve fingerprints identically.
Root cause, read off the pins this tree carries today
llama.cpp 4a375bf2d36f, hrx-system 82804197bcbe. Line numbers checked against those commits, not against
a build tree.
CPU, op 1 — the repacked Q4_K matmul walks output rows in 4-row blocks, then finishes the remainder one row at a
time. ggml/src/ggml-cpu/repack.cpp:4300 steps i11 in blocks of 4 through the repacked gemm;
:4305-4306 sends the surviving ne11 % 4 rows through the single-row path. The two paths accumulate K differently,
so the logits depend on ne11 % 4. Confirmed causally: an otherwise identical build with -DGGML_CPU_REPACK=OFF moved
0/12 trials at concurrency 2 and 4, against 11/12 with the repack path on.
CPU, op 2 — split-KV attention at decode. ggml/src/ggml-cpu/ops.cpp:9119:
use_split_kv_path = … && (neq1 == 1 && neq3 == 1) && … && nek1 >= 512 — literally "am I the only row in the batch",
so a solo decode is eligible and a batched decode is not. The KV axis is chunked by (nek1 + nth - 1) / nth and the
online-softmax partials are merged, which fixes an order that depends on the thread count as well as on the width.
Confirmed by its own two gates, single request, -np 1, varying only -t: KV 44 tokens (below the gate) is
bit-identical across -t 1/2/4/8; KV 652 tokens gives 5 distinct bit patterns across 5 thread counts, spread
2.07e-03. There is a third width switch next to it — ops.cpp:9176 use_tiled, gated on neq1 >= 64.
HRX — not attention, and not one op: two disjoint fused-kernel sets selected by token_count. A dispatch census
keyed on registration name + root-node shape, at width 1 vs width 2, shows no registration in common between the two
widths for 9 of them while common.flash_attention_decode_split_next_q8 is the same registration at both widths
(only its ne[2] differs). The width switch is in the fusions:
ggml/src/ggml-hrx/dispatch_registration/common/dispatch-kquant-decode.cpp:298-299 selects
kKQuantMulMatDecodeKernel when root.token_count == 1 and kKQuantMulMatDecodeTokensKernel otherwise (token path
compiles token_count in); dispatch-mul-mat.cpp:340 selects per-token-count split-K2 direct-dot kernels when
token_count <= 5; and there are further token-count-shaped gates at dispatch-mul-mat.cpp:575, :901, :1046,
:1058, :1153.
Six ablations, each verified by reading back the registration set that ran, all still displaced width 2 vs solo
(max |Δlogp|): unmodified 0.092 → hip.kquant_tokens off 0.132 → common.rmsnorm_binary_f32 off 0.045 →
hip.gemv_add_norm off 0.116 (which also moves solo by 0.121, i.e. the fused add+norm reassociates the residual
rather than decorating identical arithmetic) → all four width-1 fusions off 0.059. No single switch removes it, and
"both widths onto one kernel set" is not expressible today: hip.dense_kquant_swiglu has no fallback
(GGML_HRX_STRICT=1 puts 2 of 986 nodes back on the CPU).
grep -r 'atomicAdd\|__atomic' ggml-hrx returns 0 hits, and identical copies disagree with each other deterministically
(two of three width-2 trials produced the same two numbers), so this is a reproducible re-parameterisation per step, not
a race. That matters for the shape of the fix: a barrier or a mutex cannot fix it, only a fixed reduction order can.
What the fix has to guarantee
For a decode step, the reduction order for an output row must be a function of the row, not of the batch:
- the K-reduction tree of a quantised matmul must be identical at
ne11 = 1andne11 = N(op 1), or the width-1
path must be used for every row (mul_matper row, or a 1-row-block gemv everywhere); - attention must either never use the split-KV path at decode, or use it for every row with a thread-count-independent
chunking plus a fixed merge order (op 2); - on HRX the width-1 fused set must be made width-agnostic (accept
token_countcolumns with the same accumulation
order) rather than being swapped out attoken_count > 1.
Acceptance test — it already ships, so the fix can be checked without new tooling
Two tools are in tree and are the gate this issue should be closed against:
tools/batched_repeat.py— N byte-identical requests through a barrier for R rounds, one fingerprint per copy over
token ids + float32 logprob bits, plus--vs-solo(default--selftestcovers the comparator).tools/logprob_agree.py— drives served OpenAI endpoints, per-route run-to-run determinism and cross-route
agreement (--route LABEL=URL,--repeat,--thinking off).
Proposal for the done criterion, on cpu and on hrx:
tools/logprob_agree.py --route r=… --repeat 5stays bitwise-identical (it does today, solo).tools/batched_repeat.py --width 4 --rounds 4 --vs-soloreports copies identical to solo 4/4 per round and
1 distinct state across rounds (today:cpu4 states,hrxall copies distinct).- The same at width 8.
ggml-cputhread sweep at KV ≥ 512, single request: one bit pattern across-t 1/2/4/8(today: 5).
Cost and the parts that are not established
- Throughput.
-DGGML_CPU_REPACK=OFFis a working stop-gap for op 1 (0/12 moved) whose quantised-matmul cost
has not been measured here. The width-agnostic version will also cost something on HRX, where the fused width-1
set is the fast path. Whoever takes this needs alemonade bench chat-shortbefore/after oncpuandhrx. - HRX needs a real implementation, not a fallback (see
GGML_HRX_STRICTabove), so this is the larger half. - Third op not attributed.
ops.cpp:9176use_tiled(neq1 >= 64) was tested as a prediction in serve: identical requests served concurrently are not bit-reproducible on cpu and hrx (decode-batch width changes the logprobs; --parallel 4 default) #751 and failed
in both directions at the widths measured there; it is listed because it is the same class of switch, not because it
is proven to contribute. - Scope. This is a
llama.cppfork change (+ HRX) that lands by bumping the pin, not an engine-tree change; it
needs an owner decision on whether batch-invariant decoding is a promise the engine makes at all, given the cost.
Today's stop-gaps, for anyone hitting this
- Serve with
--parallel 1when the log-probabilities must be reproducible: verified bit-exact and history-free on
both routes at 0.6B (width 1 is the only width measured there, on both routes); at 4B the batched rows reproduce
the same verdict, but a 4B width-1 control was not run. - Prefer
--parallel Nonly for text, where batching still usually passes a greedy text gate and the numbers do not.
Activity
bong-water-water-bong commentedon Nov 5, 2026
The 4B width-1 control this issue says was never taken — now measured, both routes, on the shipping payload
When I filed this I corrected my own draft to say that "
--parallel 1is verified bit-exact at 0.6B and 4B" was not true as written: only the batched rows had been run at 4B. Taking that control was the missing piece, so here it is, with the fix's acceptance criterion now resting on evidence rather than on the 0.6B rows being assumed to carry over.Payload
lemonade-onebit-rc-2026-11-05-c26c(1bit4,692,512 B, 12:41 — what ships today), not the c24 payload the tables indocs/determinism.mdwere taken on. Qwen3-4B-Q4_K_M, same tool (tools/batched_repeat.py), same budget as the page's 4B row: 4 rounds × 32 tokens, greedy, 4 byte-identical concurrent copies released through a barrier,--parallel Nmatching the width, readiness by a real 1-token request (not/v1/health).cpuhrxcpuhrxSo: a 4B width-1 control is bit-exact on both routes, with a zero worst delta and a single fingerprint across all four rounds — the same result the 0.6B width-1 control gives (
3/3,1.000same-token,0.000e+00). The ladder appears only once a second request joins, and does not grow with width, which is the shape recorded in #751.Three details worth keeping:
hrxwidth 4 reproduces the page's 4B row digit for digit — 4/12 identical, 4 of 16 distinct, worst6.832e-02against the page's4/12,4 of 16,6.83e-02— even though the page's row was taken on c24 and this on c26c. Also0/3copies agreeing with copy0 in all four rounds, 4/4 distinct every round: no two copies of the same request ever coincide at that width.cpuwidth 4 moved — 2/12 and 8 of 16 here against the page's 4/12 and 7 of 16 — which is the page's own documented behaviour ("the exact counts move between runs because which sequences share a decode step moves… same verdict"), not drift. The verdict is the same on both generations.hrxthe four rounds produced only two worst-delta values (5.590e-02twice,5.131e-02twice) while the fingerprints stayed 4/4 distinct — consistent with the page's "deterministic re-parameterisation per step, not a chaotic race".Consequence for this issue's acceptance test: it stands as written. The done criterion is "copies identical to solo 4/4 per round and 1 distinct state at widths 4 and 8, and one bit pattern across
-t 1/2/4/8at KV ≥ 512" — the width-1 control is not the thing to fix, which is exactly what a control is for. No edit to the issue text is needed; this comment supplies the missing row so a fixer does not have to take it.Data:
~/wt/rlk-scratch/c24check/Qwen3-4B-Q4_K_M_{cpu,hrx}_batched_w{1,4}.json(cpu half re-taken today on c26c; the c24 originals preserved as*.c24.bak). Device cost: 31 s of GPU insidegpu-hold -l rlk-4bwidth(queued 79 min behind twelve tickets), 0 s of NPU. No code change, nothing merged.bong-water-water-bong commentedon Nov 6, 2026
The one cost this issue lists as unmeasured — now measured:
GGML_CPU_REPACK=OFFcosts 38 % of prefillThe "Cost" section above says it plainly: "
-DGGML_CPU_REPACK=OFFis a working stop-gap for op 1 (0/12 moved) whose quantised-matmul cost has not been measured here." Here it is, as PR #1228 (docs-only, one paragraph added todocs/determinism.mdwhere the flag is named).Where the cost lands is predicted by op 1's own mechanism, and that is what was measured
repack.cpp:4300-4306reaches the 4-row block only whenne11 >= 4, so the flag can only cost prompt processing, not one-token decode. Confirmed in that direction: the cost is all in prefill, and decode does not pay.Qwen3-0.6B Q4_K_M,
-t 8, 6 requests per arm, interleaved by round (the box was at load 23-45 with other lanes all night, so interleaving is what makes the ratio meaningful):Two independently run arms gave prefill ratios of 1.607× and 1.618×.
So the stop-gap is cheap exactly where the scoreboard does not look and expensive where a RAG-shaped request lives: free for chat-short, +43 % end-to-end on a 1183-token prompt. That is the number this issue's fix has to be traded against, and it is now in the tree rather than in a scratch directory.
The A/B had to be built twice, and the first one was a false negative worth recording
My inherited ON/OFF pair from #751 was not a valid A/B: same file sizes, but
libllama-server-impl.sodiffered in 2.3 M of 7.9 M bytes — those two builds were made ten minutes apart in different build dirs, so "only the flag differs" was not provable from them. Alsomd5sumover relative symlinks resolves against the cwd, so my first file-by-file table silently compared phantom paths.Rebuilt the strict way: one build dir, reconfigured, so build paths and every other flag are identical by construction; then built
libggml-cpuin each configuration and swapped that single .so into one otherwise byte-identical run directory (23 files, verified file by file on real paths — exactly one differs).Then the first measurement gave two identical arms, which was the tell, not a result: the launcher carries an absolute
DT_RUNPATHinto the build dir, andDT_RUNPATHoutranks nothing but is searched before the cwd — so withLD_LIBRARY_PATHunset both arms loaded the build's library. With the loader pointed at each arm, the harness now asserts via/proc/<pid>/mapsthat the mappedlibggml-cpuis the arm's own, and refuses to report otherwise.Causal check on the verified pair, reproducing #751's oracle on today's source: repack on → width-2
6/6moved, width-46/6moved, worst 2.953e-01; repack off →0/6and0/6, 0.000e+00. Digit-for-digit agreement with the pre-reboot figures, so op 1's finding still holds on the current tree.Deliberately not measured
The batched arm (width 4, four concurrent copies) is not reported. It was run and the per-slot timings were unusable — 1.7 tok/s decode readings and per-slot prefill spanning 42-657 tok/s — because four slots contending for 8 threads on a box at load 38 do not decompose into a defensible number. It needs a quiet box, and an unmeasured claim was already the defect in this issue's Cost section; inventing a second one to fill the table would be the worse outcome.
docs/determinism: an arm's evidence is its own family disappearing, n…
bong-water-water-bong commentedon Nov 6, 2026
Reproduced, inventoried, and a measured stop-gap — but the acceptance is not met, so this stays an engineering program rather than a fix PR.
Reproduction (shipped payload c26c, Qwen3-0.6B-Q4_K_M,
tools/batched_repeat.py, 16 tokens)-dev none)-ngl 99 -fa on)The op inventory (verified at fork tip
59d7f8284)ggml-cpu/repack.cppforward_mul_mat(src1 quantized in 4-row blocks, remainder per-row) andforward_mul_mat_one_chunk:nrows > 3uses gemm fornrows-(nrows%4)rows then per-row gemv for the remainder — gemm and gemv reduce K differently and the 4-row quantize differs fromfrom_float, so the reduction order depends on batch width, crossing at width 4.ggml-cpu/ops.cpp:9119use_split_kv_pathis solo-decode only (neq1==1 && neq3==1), KV chunked by(nek1+nth-1)/nththen merged;:9176use_tiledatneq1>=64— width- and thread-dependent.token_count(dispatch-mul-mat.cpp:903low-token contraction ≤5,:1063/:1171pack_rows ≤5,:1147token_count==1 final projection;dispatch-kquant-decodetoken-count-one kernels) — width 1 and batched use different K trees.Measured stop-gap, and what the real fix needs
GGML_CPU_REPACK=OFFremoves the CPU dependence: width-2 and width-4 probes become fully repeatable (1 distinct state) versus 7.02e-1 at width 2 with repack on. Cost on Qwen3-0.6B CPU (llama-bench -dev none -p512 -n128 -t8): pp512 662.77±152.94 → 645.07±28.12 (−2.7 %), tg128 128.52±2.76 → 125.43±11.95 (−2.4 %) — a few percent here, not the feared prefill multiple, but no large model was re-measured.The runtime width gate the issue asks for is the real work: the repack layout is chosen at load (
tensor_traits), so gatingwidth > 1needs either a second non-repacked layout or a per-op fallback, plus HRX needs width-invariant fused kernels (its width-2 still moves 7.7e-2).Disposition: parked as an unscheduled kernel program. The issue is reproduced and the inventory is now exact; closing it needs the runtime width gate + HRX width-invariant kernels, which is roadmap work with a measured cost baseline. Unpark: that program is scheduled; the acceptance test and the
batched_repeat.pyharness already exist.