Skip to content

[WebGPU] Optimize MatMulNBits wide-tile shader#29611

Open
daijh wants to merge 1 commit into
microsoft:mainfrom
daijh:matmulnbits-f16
Open

[WebGPU] Optimize MatMulNBits wide-tile shader#29611
daijh wants to merge 1 commit into
microsoft:mainfrom
daijh:matmulnbits-f16

Conversation

@daijh

@daijh daijh commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

  • Store the A workgroup tile as [kTileM][kBlockVecs/2][2] pairs of vecs so the two vecs consumed per dequantized weight column are read in one access.
  • Accumulate directly in output_element_t (e.g., f16 for f16 models) instead of hardcoding to f32.

Intel Panther Lake

Prefill Length Prefill TPS Optimized Prefill TPS Improvement
gpt-oss-20b-ONNX 128 305.70 347.71 114%
gpt-oss-20b-ONNX 1024 396.50 451.51 114%
Phi-4-mini-instruct-ONNX 128 515.90 597.81 116%
Phi-4-mini-instruct-ONNX 1024 615.39 747.07 121%

[1] https://huggingface.co/onnx-community/gpt-oss-20b-ONNX
[2] https://huggingface.co/onnx-community/Phi-4-mini-instruct-ONNX

Motivation and Context

See above.

@daijh

daijh commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@qjia7 @hariharans29 PTAL

@qjia7

qjia7 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Accumulate directly in output_element_t (e.g., f16 for f16 models) instead of hardcoding to f32.

Please check #29599, I think using f32 accumulators is the right direction.

Could you split the refactoring changes into a separate PR? That would make it much easier to review and focus on the optimization work.

- Store the A workgroup tile as [kTileM][KAVecSizeForBlock32/2][2] pairs
  of vecs so the two vecs consumed per dequantized weight column are
  read in one access.
- Accumulate directly in output_element_t (e.g., f16 for f16 models)
  instead of hardcoding to f32.
@daijh daijh force-pushed the matmulnbits-f16 branch from 01782f7 to d4b088f Compare July 8, 2026 07:56
@daijh daijh changed the title [WebGPU] Refactor and optimize MatMulNBits wide-tile shader [WebGPU] Optimize MatMulNBits wide-tile shader Jul 8, 2026
@daijh

daijh commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Let's leave this refactoring for a follow-up PR.

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.

2 participants