Skip to content

[Performance] [WebGPU] Proposal: Add an option to use online softmax instead of naive softmax #29393

Description

@kareertl

Describe the issue

Problem:
The shader code used by WebGPU's softmax currently always uses the naive safe softmax algorithm.

For some hardware with faster exp, using online safe softmax (as described in https://arxiv.org/abs/1805.02867) can improve the inference time.

Still, for hardware with slower exp, naive safe softmax might perform better than online safe softmax.

Proposal:
Add a per-session or per-context WebGPU EP option to allow selecting the softmax algorithm used (say, "naive" and "online").

Use online safe softmax shader code if the online algorithm is selected.

Possible changes involved for C++:

  • In webgpu_provider_options.h, add a new option - say - "ep.webgpuexecutionprovider.softmaxAlgorithm" and 2 constant strings for the values - say - "naive" and "online".
  • In webgpu_provider_factory.cc, parse the option and add it to the logs.
  • Add shader code for online safe softmax
  • Per-session or per-context changes to configure the softmax algorithm
  • Software-architecture dependent changes to use the selected algorithm

To reproduce

  1. Write WebGPU shader code for online safe softmax.
  2. Compare the performance between using naive safe softmax and using online safe softmax with a model with the softmax op.
  3. Depending on the hardware and model, there may be performance gain or loss when using online safe softmax.

Urgency

No response

Platform

Other / Unknown

OS Version

Custom

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.26.0

ONNX Runtime API

C++

Architecture

Other / Unknown

Execution Provider

Other / Unknown

Execution Provider Library Version

No response

Model File

No response

Is this a quantized model?

Unknown

Metadata

Metadata

Assignees

Labels

ep:WebGPUort-web webgpu providerperformanceissues related to performance regressionsplatform:webissues related to ONNX Runtime web; typically submitted using template

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions