Skip to content

[WIP] GQA supports per head smooth softmax #25269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

tianleiwu
Copy link
Contributor

@tianleiwu tianleiwu commented Jul 3, 2025

Description

It is an extension of Smooth Softmax feature. The difference is that each head has a learnable smooth factor that adding to the denominator of softmax. The smooth factor s is like an extra element that joins the softmax.

The usage of the smooth factor in softmax is like the following (For Smooth Softmax, s is constant 0):

$$softmax_{i} = \frac{exp(x_{i})}{exp(s)+ \sum_{j} exp(x_{j})}$$

Given head_sink input, s can be looked up in head_sink for current head.

Changes in progress:

  • Update operator spec to add an optional new input head_sink
  • Implement CPU (MLAS) kernel.
  • Implement CUDA kernel.

@tianleiwu tianleiwu marked this pull request as draft July 3, 2025 00:38
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

You can commit the suggested changes from lintrunner.

Comment on lines 314 to +316

if (use_smooth_softmax_) {
ComputeSmoothSoftmaxInplace(output_softmax + start_offset, 1, static_cast<int>(window_size), nullptr);

if (use_smooth_softmax_ || head_sink != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (use_smooth_softmax_) {
ComputeSmoothSoftmaxInplace(output_softmax + start_offset, 1, static_cast<int>(window_size), nullptr);
if (use_smooth_softmax_ || head_sink != nullptr) {
if (use_smooth_softmax_ || head_sink != nullptr) {

fs-eire added a commit that referenced this pull request Jul 7, 2025
### Description



support smooth softmax for non-FA GQA implementation


This change depends on:
- #25269



Work items:

- [x] support smooth softmax
- [x] support bias
- [x] support head sink (per-head smooth softmax)

The following will not be included in this PR:
- support for FlashAttention
- support sliding window
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.

1 participant