Skip to content

[ExecuTorch][WebGPU] Packed-word-dequant f16 steel q4gsw prefill GEMM#20798

Open
JCNTH wants to merge 1 commit into
gh/JCNTH/13/basefrom
gh/JCNTH/13/head
Open

[ExecuTorch][WebGPU] Packed-word-dequant f16 steel q4gsw prefill GEMM#20798
JCNTH wants to merge 1 commit into
gh/JCNTH/13/basefrom
gh/JCNTH/13/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 9, 2026

Copy link
Copy Markdown

Stack from ghstack (oldest at bottom):

+24-28% microbench GFLOP/s (+11-16% end-to-end prefill tok/s) on the f16 steel q4gsw prefill GEMM, Apple M4 Pro / Chrome Canary — bit-exact.

Problem: the f16 steel prefill GEMM (the half variant) dequantizes weights per-nibble — each of the 256 threads extracts ONE 4-bit weight from a full u32 word, so every packed word is re-loaded ~8x and the per-column scale is re-read ~16x across the BK=16 tile. That redundant global traffic dominates the kernel on Apple.

Solution: a packed-word-dequant staging variant, bit-exact to the half kernel — identical As staging, compute loop, epilogue, and 64x64 tile / 256-thread / BK=16 geometry; only the weight-dequant staging differs.

Before (half): each thread extracts 1 nibble from a re-loaded word; scale re-read per nibble.
After (pwdq): threads [0,BN) each stage one full BK-column — load the column's two u32 words ONCE, unpack all 16 nibbles, read the per-column scale ONCE.

Implementation:

  • New q4gsw_linear_gemm_steel_half_pwdq.wgsl (+ generated header); selected on the WGPU_BACKEND_STEEL_F16 path when the device negotiated shader-f16 AND group_size % BK == 0 (the hoisted scale must be constant across the BK tile), else the per-nibble half kernel.
  • No new build option, dispatch, or bindings — same tile/count as steel; only the shader source differs.

Constraints: requires K % BK == 0 (the steel route already guarantees it, making K_packed = K/2 a multiple of 8 so every column is u32-aligned) and group_size % BK == 0 (all real q4 group sizes: 32/64/128). f16-multiply / f32-accumulate, so numerically identical to the half kernel.

Co-authored-with: Claude Code.

Differential Revision: D111163510

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20798

Note: Links to docs will display an error until the docs builds have been completed.

❌ 6 New Failures

As of commit 42c7fe2 with merge base 4af91c3 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants