Repository navigation
hrx: the shortlist refine reads its exact logits back after a global barrier (engine #2150) - #330
Conversation
…barrier (engine ggml-org#2150) ggml_mul_mat_q6_k_packed_selected_refine_token1 computes each candidate's exact logit in the body, stores it to %exact_output (global memory, the candidate_values slice), and then has a different workitem load it and publish it to the output row. The two were separated by kernel.barrier<workgroup>, which fences workgroup (LDS) memory only: the AMDGPU lowering emits the release/acquire for global memory only for the <global> form. A publishing workitem could therefore read the slot before the body's store was visible and publish what it held before - the reduce kernel's coarse score for that candidate - as the exact logit. Use kernel.barrier<global> scope(workgroup) ordering(acq_rel). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gml-org#2150) One compute samples the refine kernel's publish window once, which is why the wrong refined logit showed up about once in fifty suite runs and never on demand. mul_mat.q6_k.token1_shortlist.repeat recomputes the same graph and requires every run's refined logits to stay within 1 % of the CPU; HRX_OPS_SHORTLIST_REPEATS raises the count for a stress run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
ready for review at ccb204c |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- the fence was scoped to the wrong memory space, and this is the second race in this family that produces "same input, different reply"
The diagnosis is exact and it is the kind that hides for weeks: the body computes each candidate's exact logit, stores it to %exact_output -- global memory, the candidate_values slice -- and a different workitem loads it back to publish it. The store and the load were separated by kernel.barrier<workgroup>, which in the AMDGPU lowering fences LDS only, so a reader could see the slot's previous contents -- the reduce kernel's coarse score -- and publish that as if it were the refined logit. A wrong value, not a crash, and only sometimes. kernel.barrier<global> scope(workgroup) ordering(acq_rel) is the correct form, and it is written with scope and ordering explicit rather than relying on a default.
The arm is the right shape for a race: 200 repeats. run_q6_k_token1_shortlist_case(1.0f, Ordinary, 200) recomputing the same graph and requiring every run's refined logits to match. A single run samples the window once, which is exactly how a race survives a green test suite; 200 runs of the same graph is the cheapest honest way to make the window observable.
Worth saying out loud in the body, because it is the same symptom twice: engine#328 fixed a race in hip_top_k_f32's selection levels whose consequence was an index set that differed per run, and this is a global-memory ordering defect whose consequence is a score that can be stale. Both are "identical input, different reply" -- the exact shape of engine#2159's report (two NaN and three distinct hashes in three identical 18.8k requests) and of ggml-org#2146's. A reader chasing that symptom should see both fixes named together, because fixing one leaves the other's signature intact.
One process note, same as #67/#329: the delivery path is the engine pin bump that carries this ("Fixes ggml-org#2150"), so the two should be read together -- a kernel fix that lands in llama.cpp is not in the product until the pin moves, and the body already says so, which is the right way round.
Nothing else to raise: the change is one barrier in the kernel plus the arm, the comment states the failure mode in the terms a future reader needs (LDS vs global, store and load in different workitems), and the fix is strictly stronger than the bug it replaces.
|
VERDICT: READY at The mechanism, stated as a sampling window
That is the clearest description of this class I have read: the test could not reproduce it because reproduction depends on where in the window the compute lands, and a fresh process per suite run gives one sample. Recomputing the same graph 200 times in a single process turns a 1-in-50 event into a certainty — and The assertion is the right one for a "reads its own logits back" claim"requires every run's refined logits to stay within 1 % of the CPU" — the reference is the CPU value, not the previous run's, so a kernel that is deterministically wrong fails too. A drift check against itself would pass while being consistently off, which is the failure ggml-org#2150 is about (one wrong refined logit), not a floating wobble. Two asks
|
…lishes its exact logits, not a stale coarse score (#2150) (#2300) Carries 1bit-MONSTER/llama.cpp#330 (the refine kernel reads its exact logits back after a global barrier, plus the .repeat test arm) and #329 (tests only). docs/hrx.md: the #2150 paragraph says what it was and what fixed it. registry/architectures.json follows the pin. Fixes #2150 Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
|
The fix is right and the arm is the right shape. One dead hook, one comment that says something different from what the code does. The diagnosis matches the mechanism exactly: a store to 1. static void run_q6_k_token1_shortlist_case(float branch_scale, ShortlistArm arm, int repeats = 1) {
if (const char * env = std::getenv("HRX_OPS_SHORTLIST_REPEATS"); env != nullptr && repeats > 1) {
repeats = std::max(2, std::atoi(env));The guard requires if (const char * env = std::getenv("HRX_OPS_SHORTLIST_REPEATS")) {
repeats = std::max(2, std::atoi(env)); // the whole point is to enable repeats from outside
}2. The comment and the code disagree about what is compared. The comment says "requires every run's refined logits to stay as close to the CPU as the first run's"; the code compares every run against Not verified by running: this needs the HRX backend and the Loom kernel corpus compiled, which I cannot do in this lane's tree, so I am reviewing the fence and the arm rather than its output. If the 200-repeat arm costs meaningfully in CI, the body should say the number ( |
…ugh #333, #330 included) Per ORCH 11-13 10:10Z, onto this branch. Conflicts: - dispatch-gated-delta-net: ggml-org#1925's append_covered_pattern_node beside AMD's norm matcher - ggml-hrx.cpp: ggml-org#856's file-mapped model buffer (AMD's duplicate host-pointer buffer removed); mmap_support follows the same switch - command-program-executor: AMD's main_write and ggml-org#2137's weight-copy trace - tests/CMakeLists.txt: both lines' tests (test-hrx-ops is restored in its own commit) - test-backend-ops: AMD's test_mul_mat_id plus ggml-org#2167's activation_scale as the trailing parameter; the four scaled calls pass m_v/ids_offset/skip first so the scale is not read as m_v Also: ggml-org#856's mapped buffer type uses designated initialisers (the merged ggml interface added alloc_buffer_n / get_alloc_size_n). tests/test-hrx-ops.cpp stays deleted here and comes back in the next commit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs 1bit-MONSTER/engine#2150 (the engine pin bump that carries this says Fixes ggml-org#2150).
What was wrong
ggml_mul_mat_q6_k_packed_selected_refine_token1(the draft head's logits step) computes each candidate's exact logit in its body, stores it to%exact_output, which is global memory (thecandidate_valuesslice), and then a different workitem loads it and publishes it to the output row. The store and the load were separated bykernel.barrier<workgroup>, which fences workgroup (LDS) memory only: in hrx-system's AMDGPU lowering (loom/src/loom/target/arch/amdgpu/lower/sync.c,loom_amdgpu_lower_kernel_barrier) the device-scope release before the barrier and the acquire after it are emitted only forkernel.barrier<global>. So a publishing workitem could read its slot before the body's store was visible, and publish what the slot held before: the reduce kernel's coarse score for that candidate, times the 2^6 rescale.That accounts for every property in the issue:
host-memory.cpp, the absmax/7 activation quantiser) gives 24.1202 for token 39071; 64 x 24.1202 = 1543.69, observed 1543.491 (0.013 %)..large_activation) is row mod 404 = 287, the top coarse class; it has ~162 rows, more than the 128 slots, so every candidate holds the same coarse score.The change
One line:
kernel.barrier<global> scope(workgroup) ordering(acq_rel), with a comment. And a test arm,mul_mat.q6_k.token1_shortlist.repeat, that recomputes the same graph 200 times in one process and requires every run's refined logits to stay within 1 % of the CPU (HRX_OPS_SHORTLIST_REPEATSraises the count). One compute samples the window once, which is why this showed up about once in fifty suite runs.Measured (strixhalo, gfx1151, one gpu-hold ticket per batch, before/after alternated)
Same test binary;
before= fork tipc762975a0library,after= this branch's library (strings-checked: onlyaftercarries the new corpus text;lddshows each side loading its own library).The rate depends on how busy the box is: in the first batch the two processes that failed were the slow ones (4.9 s and 6.3 s against 1.4 to 2.8 s for the rest), and in the second batch every process took 2.3 s and neither side failed. The
afterprocesses in the first batch ran interleaved with the failingbeforeones, in the same ticket, and were clean. So this measures the defect and the fix's effect on it; the root cause rests on the lowering and on the coarse-score prediction above, which the failures match to four digits.Cold-JIT runs of the plain case alone (10 + 10, fresh
GGML_HRX_JIT_CACHE_DIReach) all passed on both sides: a cold compile alone is not the trigger.Full
test-hrx-opssuite, same build, before vs after: 217 passed / 53 failed on both, the same 53 by name (commof the two lists is empty). The 53 are this build's HIP add-on taking dispatches the suite expects on Loom kernels (missing expected kernel: loom_libs:...), not this change; all six shortlist arms pass on both. Logs:~/lb/cl-hrxkern/2150/on strixhalo.🤖 Generated with Claude Code