Skip to content

llama : bump LLAMA_MAX_EXPERTS to 1024 for Kimi-K3 (896 experts) - #26192

Closed
GrEarl wants to merge 1 commit into
ggml-org:masterfrom
GrEarl:bump-llama-max-experts
Closed

llama : bump LLAMA_MAX_EXPERTS to 1024 for Kimi-K3 (896 experts)#26192
GrEarl wants to merge 1 commit into
ggml-org:masterfrom
GrEarl:bump-llama-max-experts

Conversation

@GrEarl

@GrEarl GrEarl commented Jul 27, 2026

Copy link
Copy Markdown

LLAMA_MAX_EXPERTS has been 512 since Qwen3 Next. Kimi-K3 has 896 routed experts, so it trips the arch-generic assert in llama_model_base::load_hparams before any arch hook runs:

src/llama-hparams.h:10   #define LLAMA_MAX_EXPERTS 512 // Qwen3 Next
src/llama-model.cpp:1115 GGML_ASSERT(hparams.n_expert <= LLAMA_MAX_EXPERTS);

moonshotai/Kimi-K3 reports num_experts = 896 in text_config, and convert_hf_to_gguf.py on #26185 emits gguf: expert count = 896. This cannot be worked around on the file side: understating expert_count contradicts ne[2] = 896 on the ffn_*_exps tensors.

LLAMA_MAX_EXPERTS sizes exactly one object in the tree:

src/llama-graph.cpp:2128  ggml_tensor * cur_experts[LLAMA_MAX_EXPERTS] = { nullptr };

Only [0, n_expert_used) of it is ever written or read, so raising the bound to 1024 costs 4 KB of stack in build_moe_ffn and changes no behaviour for existing models.

This unblocks #26185 (model: add Kimi-K3 text model), which is otherwise complete on the conversion side — I verified its repack_mxfp4_blocks is bit-exact against an independent implementation (0 mismatches over 11,010,048 values on a real K3 expert tensor) and that the converter reaches prepare_tensors() with a fully mapped tensor set for all 93 layers. Details in #26185 (comment)

Not verified: I have not built or run inference with a Kimi-K3 GGUF, so this change is argued from the assert and the single array it bounds, not from a successful load.

AI usage disclosure: yes. The line references were read from master with an AI agent; the reasoning and the one-line change are as described above.

@GrEarl
GrEarl requested a review from ggerganov as a code owner July 27, 2026 19:39
@ggml-gh-bot

ggml-gh-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

Hi @GrEarl, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@pwilkin pwilkin added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 27, 2026
@GrEarl GrEarl closed this Jul 27, 2026
@GrEarl
GrEarl deleted the bump-llama-max-experts branch July 27, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants