Skip to content

cuda: add sqrt_softplus in topk-moe for dsv4#25896

Merged
am17an merged 1 commit into
ggml-org:masterfrom
am17an:cuda-sqrt-softplus-topk
Jul 21, 2026
Merged

cuda: add sqrt_softplus in topk-moe for dsv4#25896
am17an merged 1 commit into
ggml-org:masterfrom
am17an:cuda-sqrt-softplus-topk

Conversation

@am17an

@am17an am17an commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Overview

Add sqrt_softplus to the list of supported topk-moe functions.

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, codex implemented and I reviewed

@am17an
am17an requested review from a team and ggerganov as code owners July 19, 2026 14:46
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Jul 19, 2026

@ORippler ORippler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Left some non-blocking comments

__device__ void sqrt_softplus_warp_inplace(float (&vals)[experts_per_thread], const int limit, const int lane) {
#pragma unroll
for (int i = 0; i < experts_per_thread; i++) {
const int idx = lane + i * WARP_SIZE;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const int idx = lane + i * WARP_SIZE;
const int idx = lane + i * ggml_cuda_get_physical_warp_size();

This should resolve to 32 on CUDA and 64 on HIP afaik

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Edit: Looking at the kernel-context, this is something that could/should be done in a separate follow-up PR for the whole op

}
}

template <int experts_per_thread, bool use_limit>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
template <int experts_per_thread, bool use_limit>
template <int experts_per_thread>

It seems like the function is instantiated with use_limit=false always, so we may remove this template parameter (other activations seem to be sharing this potentially -> may be worth follow-up PR)

Comment on lines 7 to 9
bool sigmoid{};
bool sqrt_softplus{};
bool softmax{};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

May consider adding an enum in future, as sigmoid/sqrt_softplus and softmax seem to be mutually exclusive

@am17an

am17an commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@ggml-org/maintainers can I get another approval please?

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@am17an
am17an merged commit 846e991 into ggml-org:master Jul 21, 2026
25 of 29 checks passed
@am17an
am17an deleted the cuda-sqrt-softplus-topk branch July 21, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants