diff --git a/src/llama-context.cpp b/src/llama-context.cpp index 6252147a7..7f1cc4c44 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -2949,6 +2949,12 @@ uint32_t llama_context::graph_max_nodes() const { } } + // the MoE cache adds a lookup to each MoE layer, and a second expert path with a CPU share (up to ~16 tensors per layer), + // which the per-tensor estimates above do not cover for models with few tensors per layer + if (cparams.moe_cache_size > 0) { + res += 32u*model.hparams.n_layer_all; + } + // every sampler builds n_outputs_max_per_seq chains, see llm_graph_context::build_sampling for (const auto & [seq_id, sampler] : sampling.samplers) { res += llama_sampler_backend_n_nodes(sampler) * cparams.n_outputs_max_per_seq;