Repository navigation
Conversation
…perimental) With moe_cache_cpu >= 0, a batch served by the MoE cache no longer uploads every selected expert the cache does not hold. The experts are built twice: on the device from the cache, and on the CPU from the host weights. Each pass is weighted by the router only for the experts it holds (dev_mask, cpu_mask), so each row of their sum is exactly one of the two, and the CPU pass selects the cached experts with id -1, which ggml-cpu's mul_mat_id now treats as no expert (a zero row) instead of reading their host weights. At most moe_cache_cpu missing experts per layer and batch are still uploaded, the best scored first, so the cache keeps learning; those are read from the cache by the same batch. The copy callback plans the layer once per batch, on the first of its maps to be copied, and writes the maps after the plan: the slot map gives slot 0 to the experts computed on the CPU, cpu_ids gives -1 to the others. The maps are looked up on the device like the slot map, so they are read after the plan. llama_moe_cache_slots returns the cache's own slots, which tell a caller the experts whose host weights the batch does not read. -1, the default, keeps the upload of every missing expert. Llama 4 weights the input of the experts, so it keeps the uploads. The scheduler runs the CPU pass after the device pass, not alongside it. LLAMA_HAS_MOE_CACHE_CPU lets a caller build against a llama.cpp without it.
Owner
Author
|
Closing with Helldez/BigMoeOnEdge#433 and ggml-org#434: the CPU pass ran after the device pass, not beside it, and the measured gain did not justify a second fork commit. |
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.
Experimental, stacked on the slot-map PR (base branch
bmoe/moe-cache-slots). Off by default (moe_cache_cpu = -1).What
With
llama_context_params::moe_cache_cpu >= 0, the MoE cache no longer uploads every selected expert it does not hold.build_moe_ffnbuilds the experts twice: on the device from the cache bank, and on the CPU from the host weights (the CPUmul_mat_idis pinned tobackend_cpu).weights * dev_maskandweights * cpu_mask. Each row of the sum is therefore exactly one of the two (x + 0).-1. ggml-cpu'smul_mat_idtreats that as no expert and writes a zero row, so the host weights of a cached expert are never read.moe_cache_cpumissing experts per layer and batch are still uploaded, the best scored first, so the cache keeps learning. The same batch reads those from the cache.Measured
Limits
ggml_backend_schedruns the CPU pass after the device pass, not alongside it. Every split synchronizes when an eval callback is installed, and a split with no inputs synchronizes the previous backend. What this removes is the PCIe upload of the misses from the critical path. It does not overlap the two computations.MUL_MAT_IDid-1the same "zero row" meaning on CPU, Metal, Vulkan, OpenCL, SYCL and WebGPU (not CUDA yet). On a bump, this commit's ggml-cpu hunk is dropped in favour of upstream's.