Skip to content

[WebGPU] updates webgpu softmax to use online algorithm#29694

Open
prathikr wants to merge 1 commit into
mainfrom
prathikrao/webgpu-online-softmax-impl-2
Open

[WebGPU] updates webgpu softmax to use online algorithm#29694
prathikr wants to merge 1 commit into
mainfrom
prathikrao/webgpu-online-softmax-impl-2

Conversation

@prathikr

Copy link
Copy Markdown
Contributor

Feature request from #29393

Copilot AI 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.

Pull request overview

This PR updates the WebGPU Softmax shader implementation to use an online safe-softmax accumulation scheme (running max + running sum), reducing the separate “max pass” previously used in the naive safe-softmax approach.

Changes:

  • Switch Softmax’s per-row reduction to an online accumulation of (max, sum) per thread, then merge these states across the workgroup.
  • Introduce x_element_t usage for scalar max/sum tracking and workgroup shared storage, while keeping x_value_t for packed/vector element operations.

Comment thread onnxruntime/core/providers/webgpu/math/softmax.cc

@qjia7 qjia7 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 with one nit.


// Find the row's max value
<< thread_max_decl
// Online accumulation: track scalar running max and scalar running sum.

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.

nit: Please add a reference to the original paper: https://arxiv.org/abs/1805.02867.

@hariharans29 hariharans29 changed the title updates webgpu softmax to use online algorithm [WebGPU] updates webgpu softmax to use online algorithm Jul 14, 2026
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.

4 participants