CUDA: refactor topk-moe to enable more models (GLM 4.7, Nemotron etc.)#19126
Merged
am17an merged 3 commits intoggml-org:masterfrom Jan 29, 2026
Merged
CUDA: refactor topk-moe to enable more models (GLM 4.7, Nemotron etc.)#19126am17an merged 3 commits intoggml-org:masterfrom
am17an merged 3 commits intoggml-org:masterfrom
Conversation
3245ced to
1ae43b9
Compare
JohannesGaessler
approved these changes
Jan 27, 2026
| ggml_tensor * get_rows = cgraph->nodes[node_idx + 4]; | ||
| ggml_tensor * argsort = cgraph->nodes[node_idx + 2]; | ||
| int n_expert = cgraph->nodes[node_idx]->src[0]->ne[0]; | ||
| node_idx++; |
Contributor
There was a problem hiding this comment.
Generally speaking I'm not a fan of changing function arguments in the body (though in this case I think it's still fine).
ggml/src/ggml-cuda/ggml-cuda.cu
Outdated
| if (args.sigmoid || args.softmax) { | ||
| // SOFTMAX -> RESHAPE | ||
| if (node_idx >= n_nodes || nodes[node_idx]->op != GGML_OP_RESHAPE || | ||
| nodes[node_idx]->src[0] != nodes[node_idx - 1]) { |
Contributor
There was a problem hiding this comment.
Suggested change
| nodes[node_idx]->src[0] != nodes[node_idx - 1]) { | |
| nodes[node_idx]->src[0] != nodes[node_idx - 1]) { |
I think it makes sense to indent by 8 spaces rather than 4 to make the logic visually distinct from the code that would oftentimes follow on this line.
Contributor
Author
There was a problem hiding this comment.
I ran this though clang-format and it does this, though I agree with you.
3ad63db to
eeb9b04
Compare
4b1tQu4ntN3k0
pushed a commit
to 4b1tQu4ntN3k0/llama.cpp
that referenced
this pull request
Feb 2, 2026
shaofeiqi
pushed a commit
to qualcomm/llama.cpp
that referenced
this pull request
Feb 6, 2026
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.
Refactor the topk-moe to enabling various combination of topk-moe. Hopefully this will cover most models. I removed some templates from the code and only kept the bias because it has a extra warp shuffle, the rest of the template code does not provide any significant speedup.
3090
4090
5090