ggml: treat experts as cache residents during MoE offloading - #2
Closed
avifenesh wants to merge 1 commit into
Closed
ggml: treat experts as cache residents during MoE offloading#2avifenesh wants to merge 1 commit into
avifenesh wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes Mixture of Experts (MoE) offloading by tracking which experts are already resident on the backend, ensuring only missing experts are copied during graph splits. This is achieved by introducing a tracking structure within the scheduler and refactoring the copy logic. Review feedback recommends adding null checks for memory allocations to ensure the scheduler remains robust under memory pressure.
|
|
||
| if (loaded->id_size != loaded_id_size) { | ||
| free(loaded->ids); | ||
| loaded->ids = (ggml_bitset_t *) calloc(loaded_id_size, sizeof(ggml_bitset_t)); |
| sched->hv_tensor_copies = (ggml_tensor **) malloc(sched->hash_set.size * sched->n_backends * sched->n_copies * sizeof(struct ggml_tensor *)); | ||
| const size_t tensor_copy_count = sched->hash_set.size * sched->n_backends * sched->n_copies; | ||
| sched->hv_tensor_copies = (ggml_tensor **) malloc(tensor_copy_count * sizeof(struct ggml_tensor *)); | ||
| sched->hv_tensor_moe_loaded = (ggml_backend_sched_moe_loaded *) calloc(tensor_copy_count, sizeof(sched->hv_tensor_moe_loaded[0])); |
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.
Overview
When MoE weights are offloaded from host memory, the scheduler already copies only the experts used by the current
GGML_OP_MUL_MAT_IDsplit. In long prompt-cache workloads, the same split-input staging tensor can be reused across turns, so many experts that were copied for earlier turns are still resident on the backend.This change tracks resident MoE experts per scheduler tensor copy and treats the split-input staging tensor as an expert cache:
ggml_bitset_tmissing_ids = used_ids & ~loaded_idsn_expert,expert_size, source data, or destination staging data changesThe change is internal to
ggml/src/ggml-backend.cpp. It does not add a user-facing flag, public API, or backend-specific implementation.Additional information
Benchmark setup:
upstream/masterat64b38b561build-cuda13-clean/bin/llama-server--cpu-moe-c 65536Validation:
git diff --checkcmake --build build-cuda13-clean --target llama-server test-backend-ops -j 10build-cuda13-clean/bin/test-backend-ops test -o MUL_MAT_ID764/764 tests passed2/2 backends passedCUDA error,OOM,ASSERT,Traceback,abort, or similar failure strings.Related upstream search:
Requirements