Repository navigation
moe-stream: routed experts streamed from the model file (opt-in) - #19
Merged
Merged
Conversation
…lots (1bit engine) A MoE layer's expert FFN (SwiGLU, separate gate/up, no biases or scales) runs on the CPU out of an expert cache: pinned slots filled by O_DIRECT reads, several in flight (moe-expert-cache, from the 1bit engine's moe/). Three custom ops per layer: pin the batch's experts and convert its inputs, gate/up/SwiGLU, down; the routing weights and the sum stay in the graph. Batches larger than ONEBIT_MOE_MAX_BATCH (prompts) keep the regular path. Enabled by ONEBIT_MOE_FILE (the GGUF) and ONEBIT_MOE_SLOTS; Linux only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each layer's pinned slots are imported as a device buffer (buffer_from_host_ptr; Strix Halo's GPU shares the memory) and viewed as strided gate/up/down tensors. A CPU op pins the batch's experts and maps their ids to slot indices; the regular MUL_MAT_ID path then runs on the GPU over the slots. The expert cache now keeps each part at a fixed offset in its slot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nary expert tensors Vulkan's MUL_MAT_ID takes the expert stride as ne00*ne01, not nb[2], so strided slots read garbage. The cache now keeps one packed array per part per list (part k of slot i at part_off[k] + i * part_bytes[k]); O_DIRECT reads go through each reader's aligned bounce buffer and are copied into place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The next MoE layer's router (F32, read from the file once) is applied to this layer's FFN input while this layer computes; its top-k experts are queued for reading. Single-token steps; ONEBIT_MOE_PREFETCH=0 turns it off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ost memory Vulkan MUL_MAT_ID on imported host memory ran at about 1 GB/s (6-14 ms per expert matmul on Strix Halo). On UMA, ggml-vulkan's device buffers are host-visible; the expert cache now takes a region per list from the caller, and GPU mode allocates each layer's slots as a Vulkan buffer and fills it through the host mapping. ggml-vulkan exposes the mapping through its registry's get_proc_address (ggml_backend_vk_buffer_get_host_ptr). Co-Authored-By: Claude Opus 5.5 <[email protected]>
bong-water-water-bong
merged commit Sep 26, 2026
57c22a3
into
1bit/vulkan-upstream
6 of 15 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Streams a MoE model's routed experts from the GGUF into a RAM cache during decode, so the experts need not all fit in memory (1bit engine, docs/moe-streaming.md).
Off by default. It is enabled with
ONEBIT_MOE_FILE(the model's GGUF) andONEBIT_MOE_SLOTS(experts held), and the expert tensors are loaded mmap-ed on the CPU (-ot exps=CPU). With the variables unset,build_moe_ffnis unchanged apart from one pointer check.How it works
O_DIRECTreads (several in flight, pinned bounce buffers);ONEBIT_MOE_DEVICE=cpu): three custom ops on the CPU's dot kernels.ONEBIT_MOE_PREFETCH, on by default, see below).Files. New:
src/llama-moe-stream.*, andsrc/moe-{expert-cache,gguf-index}.*(the engine'smoe/), Linux only. Changed:llama-graph.cpp: the hook inbuild_moe_ffn;src/CMakeLists.txt;ggml-vulkan.cpp:ggml_backend_vk_buffer_get_host_ptrthrough the registry'sget_proc_address, which was NULL.Correctness (Qwen3-Coder-30B Q4_K_M, perplexity over 512 tokens):
Speed (Strix Halo, shared box with load around 5, warm repetitions):
Open
Streaming off, all-Vulkan decode is unchanged (78.8 tok/s on this build under load).
🤖 Generated with Claude Code