Skip to content

graph : avoid huge warm-up graphs for MoE models - #14753

Merged
ggerganov merged 2 commits into
masterfrom
gg/context-reduce-min-nodes
Jul 18, 2025
Merged

ggerganov merged 2 commits into
masterfrom
gg/context-reduce-min-nodes

Conversation

@ggerganov

Copy link
Copy Markdown
Member

Just hot loading the experts for matrix multiplication is enough to heat-up the caches. No need to add extra GGML_OP_ADD nodes for aggregating the results.

@ggerganov
ggerganov force-pushed the gg/context-reduce-min-nodes branch from 4feb0bf to 4c1bacb Compare July 18, 2025 08:47
@ggerganov
ggerganov requested a review from slaren July 18, 2025 08:48
@ggerganov
ggerganov force-pushed the gg/context-reduce-min-nodes branch from 4c1bacb to 033b306 Compare July 18, 2025 08:55
Comment thread src/llama-context.cpp Outdated

uint32_t llama_context::graph_max_nodes() const {
return std::max<uint32_t>(65536u, 5u*model.n_tensors());
return std::max<uint32_t>(1024u, 6u*model.n_tensors());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably bump this up to 8u*model.n_tensors() just to be safe.

@slaren

slaren commented Jul 18, 2025

Copy link
Copy Markdown
Member

If I understand correctly, the motivation of this change was to ensure that all weights are loaded into memory when using mmap on a NUMA system. This would effectively revert #11571.

@ggerganov

ggerganov commented Jul 18, 2025 •

Copy link
Copy Markdown
Member Author

I think the experts are still mapped continue to be loaded because when we run the ggml_mul_mat_id() calls, we use the large n_expert_used == hparams.n_expert, instead of the original hparams.n_expert_used. So for example this call, during warmup would still load all the experts into memory and perform the warmup:

ggml_tensor * up = build_lora_mm_id(up_exps, cur, selected_experts); // [n_ff, n_expert_used, n_tokens]
cb(up, "ffn_moe_up", il);

The change only removes the summation nodes that sum together the obtained results for each expert. Those do not involve reading data from the model, but contribute to many number of graph nodes.


For reference, here is the n_expert_used initialization:

n_expert (hparams.n_expert),
n_expert_used (cparams.warmup ? hparams.n_expert : hparams.n_expert_used),
freq_base (cparams.rope_freq_base),

Edit: fixed wording at the start for clarity

@ggerganov
ggerganov merged commit d498af3 into master Jul 18, 2025
@ggerganov
ggerganov deleted the gg/context-reduce-min-nodes branch July 18, 2025 11:31
graehl added a commit to graehl/llama.cpp that referenced this pull request Sep 18, 2025
fix regression during finetune on Llama-3.2-1B-F32:
GGML_ASSERT(cgraph->n_nodes < cgraph->size) failed

git bisect applying the most recent finetune (SGD) change
showed that
d498af3 Georgi Gerganov 2025-07-18 14:31:15 +0300 graph : avoid huge
warm-up graphs for MoE models (ggml-org#14753)

which greatly decreased graph_max_nodes
has been responsible for finetune failing on reasonably sized models
for the past two months. partially reverting the decrease (maybe
larger models still fail)

note: env LLAMA_SET_ROWS=0 is needed also or else:
GML_ASSERT(!node->view_src || node->op == GGML_OP_CPY || node->op == GGML_OP_VIEW || node->op == GGML_OP_RESHAPE || node->op == GGML_OP_PERMUTE || node->op == GGML_OP_TRANSPOSE) failed
(the node->op in question is indeed a rows op)
unfortunately a git revert on:

8a4280c Georgi Gerganov 2025-08-28 12:27:02 +0300 kv-cache : remove
LLAMA_SET_ROWS checks (ggml-org#15505)

is not straightforward, so this branch is behind that.
blime4 referenced this pull request in blime4/llama.cpp Feb 5, 2026
* graph : avoid huge warm-up graphs for MoE models

ggml-ci

* cont : bump max nodes to 8x model tensors
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* graph : avoid huge warm-up graphs for MoE models

ggml-ci

* cont : bump max nodes to 8x model tensors
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* graph : avoid huge warm-up graphs for MoE models

ggml-ci

* cont : bump max nodes to 8x model tensors
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
* graph : avoid huge warm-up graphs for MoE models

ggml-ci

* cont : bump max nodes to 8x model tensors
MrLordCat referenced this pull request in MrLordCat/llama.cpp-rdna-lab Jul 16, 2026
* graph : avoid huge warm-up graphs for MoE models

ggml-ci

* cont : bump max nodes to 8x model tensors
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
* graph : avoid huge warm-up graphs for MoE models

ggml-ci

* cont : bump max nodes to 8x model tensors
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
* graph : avoid huge warm-up graphs for MoE models

ggml-ci

* cont : bump max nodes to 8x model tensors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants