Skip to content

moe-stream: prefetch on a worker thread, N layers ahead; ONEBIT_MOE_STATS - #20

Merged
bong-water-water-bong merged 2 commits into
1bit/vulkan-upstreamfrom
1bit/moe-stream-stats
Sep 26, 2026
Merged

bong-water-water-bong merged 2 commits into
1bit/vulkan-upstreamfrom
1bit/moe-stream-stats

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Sep 26, 2026 •

Copy link
Copy Markdown

The gate-ahead scoring ran scalar inside the remap op, on the decode path. That cost about 0.15 ms per MoE layer, so prefetch made decode slower.

  • A worker thread scores the next ONEBIT_MOE_PREFETCH layers (default 1; 0 turns prefetch off) with an 8-lane dot. It skips any layer whose remap has already started.
  • ONEBIT_MOE_STATS=1 prints at exit: time in remap, time waiting for reads, time between remaps, and the cache counters.

Qwen3-Coder-30B Q4_K_M, llama-bench -n 64 -r 4, warm reps (tok/s):

slots no prefetch before (inline) depth 1 depth 2 depth 3
4608 42.2-42.3 28-29 43.5-43.8 43.0-44.8 40.8-42.4
1536 9.6-10.5 8.7-9.0 9.2-10.2 9.0-9.6

At 1536 slots, decode is bound by the drive: about 88 misses x 2.1 MB per token, ~2.4 GB/s effective. Prefetch cuts demand misses from 22.9% to 7%, but it adds wasted reads. The per-layer gap between remaps (0.37 ms, i.e. GPU work plus the host round trip) caps streamed decode at about 57 tok/s, against 80 resident.

Perplexity with prefetch 1 and 2 (1536 slots, batch 1): 21.1029, the same as all-Vulkan.

Also fixes the CI Test step, which was already red on 1bit/vulkan-upstream (PR #19 too), in a separate commit:

  • test-generate-models aborted on Zamba2, because the test gave it head size n_embd/n_head while its attention runs on the 2 * n_embd concat.
  • It then aborted on BlackMamba, which the test built dense, with no experts. With n_ff on every layer, the Mamba state also goes unused; the test now alternates Mamba and MoE layers like the real model.
  • test-save-load-state then failed on Zamba v1: the saver wrote ssm_n_group, which Zamba v1 keeps at 0. It now writes the head count from ssm_x.
  • ctest -L main on CPU: 52/52.

🤖 Generated with Claude Code

bong-water-water-bong and others added 2 commits September 26, 2026 14:11
…T_MOE_STATS

The gate-ahead scoring ran scalar inside the remap op, on the decode path: about 0.15 ms per
MoE layer, so prefetch lost (Qwen3-Coder-30B, 4608 slots: 28 tok/s against 40 without it).
A worker thread now scores the next ONEBIT_MOE_PREFETCH layers (default 1), skipping any whose
remap has started: 43.5-44.8 tok/s at depths 1-2 against 42.3 without. Perplexity unchanged
(21.1029, batch 1). ONEBIT_MOE_STATS=1 prints the time split and cache counters at exit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Zamba v1's head count

test-generate-models aborted on Zamba2 (head size n_embd/n_head, but its attention runs on the
2 * n_embd concat), then on BlackMamba (built dense, it has no experts; with n_ff on every
layer no Mamba layer uses the recurrent state), and test-save-load-state on Zamba v1 (the
saver wrote ssm_n_group, which Zamba v1 keeps at 0). The five tests after it never ran.
ctest -L main on CPU: 52/52.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong
bong-water-water-bong merged commit a29be7f into 1bit/vulkan-upstream Sep 26, 2026
9 of 11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/moe-stream-stats branch October 12, 2026 01:31
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