Skip to content

ggml-hrx: stop the sleeping wait from oversleeping decode after a prompt - #87

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-replay-keep
Oct 5, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-replay-keep

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Fixes the decode slowdown after a prompt run. The cause was the sleeping stream wait (#44), not graph recapture: the replay log shows only hits after the prompt.

Root cause (runtime/hrx-sleeping-wait.cpp, ours):

  • Oversleeping is recorded as work. The wait estimates each wait as the shortest of the last 4 at its call site and sleeps 80% of it above 20 ms. A wait that oversleeps records the sleep instead of the work, so the estimate can only shrink by 0.8x per wait.
  • One history for every graph. The history was a static shared by every replayed graph (wait_stream_commands in runtime/command-program-executor.cpp). So 98-123 ms prompt waits set the sleep for 13 ms decode tokens. Measured on Qwen3-4B after pp512, decode tokens slept 98, 78, 63, 50, 40, 32, 26, 21, 17 ms before settling. The 27B lost about 3.7 s per llama-bench rep.

Fix:

  • Oversleep guard: after sleeping, query the stream; if the work had already finished, forget the history.
  • Per-graph history: one thread-local history per replayed graph exec (wait_history_for(key), capped at 256 keys).
  • AMD file (2 lines): wait_stream_commands takes a key, and the replay call passes recorded.exec.

It is host-side only and allocates no GPU memory.

Checks (strixhalo gfx1151, performance mode):

  • Generated text: byte-identical before vs after for every server request: Qwen3-4B, 8B, 27B and ZAYA1-8B, 1/507/2002-token prompts, 4 runs each.

  • KLD: Qwen3-4B KLD vs before 0.000000; PPL 13.1187 both.

  • test-backend-ops -b HRX0: MUL_MAT, ADD, FLASH_ATTN_EXT, RMS_NORM, SOFT_MAX OK, run twice.

  • Memory: 50 mixed requests with GTT bounded: Qwen3-4B flat at 10.1 GiB; ZAYA bounded by the existing cap-64 program cache.

  • Decode, first llama-bench rep after the prompt:

    model before after
    Qwen3-4B after pp512 67.8 77.1
    Qwen3-8B after pp512 37.5 42.4
    Qwen3.8-27B after pp512 9.23 12.15
  • Server decode after a 2002-token prompt:

    model before after
    Qwen3-4B 48-51 54-58
    Qwen3-8B 31.3 35.7
    Qwen3.8-27B 9.0 11.55
  • Prompt speed: unchanged within noise.

🤖 Generated with Claude Code

The sleeping graph wait (fork #44) predicts a wait from the shortest of the
last four waits at its call site and sleeps 80% of it. Two faults:
- a wait still asleep when the work finished recorded the sleep, not the
  work, so the estimate could only shrink by 0.8x per wait;
- every replayed graph shared one history, so prompt graphs set the sleep of
  decode graphs.
After a prompt graph (98-123 ms waits on Qwen3-4B pp512) the 13 ms decode
tokens slept 98, 78, 63, 50, 40, ... ms, paid after every prompt. This was
the penalty blamed on "graph replay recapture": the replay log shows no
rebuild after the prompt (258 hits, 2 first builds), only the waits.

Fix (our file hrx-sleeping-wait.cpp; two-line hook in the replay wait):
- a wait that finds the work already done when it wakes forgets its history
  instead of recording the sleep, so the next wait blocks and measures;
- the graph replay wait keeps one history per replayed graph exec
  (wait_history_for, bounded at 256 keys).

Measured, performance mode (120 W), strixhalo, interleaved before/after.
llama-bench -fa 1 -r 3, tg128 samples after pp in the same process (2 rounds):
  Qwen3-4B    after pp512   [67.8 76.7 76.9][67.9 76.9 76.8] -> [77.1 77.1 77.1][76.4 76.9 77.0]
  Qwen3-4B    after pp2048  [67.6 77.2 77.2][67.3 76.7 76.7] -> [77.1 77.1 77.1][77.1 77.3 77.2]
  Qwen3-8B    after pp512   [37.5 42.4 42.4][37.5 42.4 42.4] -> [42.4 42.4 42.5][42.3 42.4 42.5]
  Qwen3.8-27B after pp512   [9.23 12.1 12.1][9.23 12.1 12.1] -> [12.2 12.1 12.1][12.1 12.1 12.1]
  hip-all ZAYA1-8B pp512    [82.9 91.3 94.6][82.9 91.2 92.3] -> [92.0 91.7 94.6][91.7 91.5 94.3]
  pp512/pp2048 unchanged within run-to-run spread (4B 4215-4221 vs 4172-4192,
  27B 354.5-357.0 vs 352.5-355.8, 8B 2360-2380 vs 2354-2397).
llama-server, decode tok/s per request after a 2002-token prompt (3 requests x 2 runs):
  Qwen3-4B 48.2-51.2 -> 54.2-57.6, Qwen3-8B 31.2-31.4 -> 35.6-35.7,
  Qwen3.8-27B 8.89-9.02 -> 11.51-11.59; 507-token prompts and 1-token
  prompts unchanged.
Correctness: generated text identical before/after (md5 per prompt, every
request), Qwen3-4B KLD vs before 0.000000 (100% same top token, 40 x 512),
test-backend-ops HRX0 MUL_MAT/ADD/FLASH_ATTN_EXT/RMS_NORM/SOFT_MAX OK x2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the ggml label Oct 5, 2026
@bong-water-water-bong
bong-water-water-bong merged commit f3c771f into 1bit/hrx-vulkan-patched Oct 5, 2026
9 of 24 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-replay-keep branch November 12, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant