← Back to Pull requests

[GPU] MoE: prefill expert GEMMs on dynamically quantized int8 activations #39666

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 09, 2026 21:12 UTC
Author

Follow-up of #39366 (the u3 batched GEMV decode). Where dynamic quantization is enabled, the grouped GEMM path of the MoE experts (prefill) runs on int8 activations:

Details

Front end for all weight types (moe_3gemm_dyn_quan.cl): quantizes f16 rows to int8 with per-group f16 scales (groups of 128 or 64, same scheme as dynamic_quantize_gpu_opt). Tokens are quantized once and gathered per expert; the down input act(gate) up is quantized by the same kernel.
u3: new int8 x int4 DPAS GEMMs (moe_3gemm_int3_gemm.cl) over a list of 64-row expert tiles; the zero point is applied while decoding the weights. Tile width and GRF size are tuned per architecture (Xe2 / Xe3).
u4/i4 and symmetric u8/i8: OneDNN grouped matmul with s8 source and source scales.
GPU_MOE_DYNAMIC_QUANTIZATION_THRESHOLD: token count up to which f16 activations are kept. Default: none for u3, 256 for OneDNN (see the sweep below).
moe_gather_ref uses aligned vector copies, which also speeds up the f16 gather of master's path.
Requires Xe2+, f16 activations and scales, weight groups a multiple of 64 (u3: plus a u8/i8 zero point). Everything else stays on f16 activations.

Accuracy

LNL, Qwen3.6-35B-A3B, WikiText-2 perplexity over 100k tokens (200 windows of 512 tokens).

| Model | master | this PR |
| --- | --- | --- |
| int3 | 8.5549 | 8.5584 |
| int4 | 7.9626 | 7.9674 |
| int3, dynamic quantization off | 8.5490 | 8.5512 |
| int4, dynamic quantization off | 7.9626 | 7.9622 |

wwb similarity (LNL, ground truths from master):

| Target | master | this PR |
| --- | --- | --- |
| int3 vs int4 | 0.850 | 0.856 |
| int4 vs master int4 | 1.0 | 0.980 |
| int3 vs master int3 | — | 0.972 |

Performance

LNL (Arc 140V), Qwen3.6-35B-A3B, this PR vs its master base (c66911239e), both with GenAI master. llm_bench settings: -n 5, 128 output tokens, SDPA attention, chat template. The numbers are the mean of 2 rounds in alternating order, except the 1st token of int4 at 1032 tokens (see below):

| Model | Prompt | 1st token, master | 1st token, this PR | 2nd token, master | 2nd token, this PR |
| --- | --- | --- | --- | --- | --- |
| int3 | 130 tokens | 206.2 ms | 192.6 ms (−6.6%) | 40.3 ms | 36.6 ms |
| int3 | 1032 tokens | 833.4 ms | 770.3 ms (−7.6%) | 39.3 ms | 40.0 ms |
| int4 | 130 tokens | 211.9 ms | 211.0 ms (−0.4%) | 37.1 ms | 39.2 ms |
| int4 | 1032 tokens | 851.9 ms | 809.6 ms (−5.0%) | 37.1 ms | 39.0 ms |

The decode path is unchanged; its latency varies by a few ms per token between runs of the same build on LNL. int4 at 130 tokens stays on f16 activations (below the threshold). The 1st token of int4 at 1032 tokens varies between launches of this PR (780 to 888 ms; master 844 to 882 ms), so the table gives the median over 14 launches of this PR and 9 of master.

The threshold default comes from int4 prefill on LNL, measured both on one MoE layer in isolation (real weights, 40 inferences per size, inputs varied so that expert weights are not cache resident) and on the full model (real text, median of 6-8 prefills, 2 runs per setting). Change with int8 activations vs f16:

| Tokens | 64 | 128 | 192 | 256 | 384 | 512 | 768 | 1024 | 2048 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| one MoE layer | −1% | +1% | −0% | −2% | −5% | −6% | −7% | −1% | −10% |
| full model prefill | +10% | +3% | ±0% | ±0% | −4% | −2% | −5% to −13% | ±0% | — |

The full model at 2048 tokens runs at the memory limit of the 32 GB LNL in both modes (same peak), so its timings are not comparable.

Compute-bound expert GEMMs of one layer (unitrace device time, layer 0 of Qwen3.6-35B-A3B: 8 of 256 experts, hidden 2048, expert inter 512; ops per GEMM = 2 · 8M · 2048 · 512). For OneDNN the three grouped matmuls are summed:

| M | u3 gate | u3 up | u3 down | u3, all 3 | int4, s8 activations | int4, f16 activations |
| --- | --- | --- | --- | --- | --- | --- |
| 4096 | 15.6 TOPS | 19.8 TOPS | 16.6 TOPS | 17.1 TOPS (12.0 ms) | 18.6 TOPS (11.1 ms) | 15.5 TFLOPS (13.3 ms) |
| 8192 | 17.0 TOPS | 22.1 TOPS | 18.6 TOPS | 19.0 TOPS (21.7 ms) | 22.2 TOPS (18.6 ms) | 18.3 TFLOPS (22.5 ms) |
| 16384 | 17.9 TOPS | 23.1 TOPS | 20.0 TOPS | 20.1 TOPS (41.0 ms) | 24.9 TOPS (33.2 ms) | 19.9 TFLOPS (41.5 ms) |

The u3 gate GEMM includes its act(gate) up epilogue. The int8 gather (values and scales) moves half the bytes of the f16 one (4.9 vs 9.7 ms at 16k tokens).

One MoE layer on LNL, BMG and PTL with KernelFoundry (the plugin's kernels and OneDNN through benchdnn, real routing of Qwen3.6-35B-A3B layers 20 and 39). Device time in ms of one layer: input (quantize + int8 gather vs f16 gather), gate, up and down, including the quantization of the down input. These are kernel times of one layer, not the full model. Master's gate GEMM (and the OneDNN s8 gate GEMM of this PR) is timed without its fused act(gate) up post-op, since benchdnn can't express it for grouped tensors; the u3 int8 gate GEMM includes its epilogue. The master side is master's f16 gather, without the moe_gather_ref change of this PR.

| GPU | Prompt | Layer | u3, master | u3, this PR | Δ | int4, master | int4, this PR | Δ |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| LNL (Arc 140V) | 1030 tokens | 20 | 5.96 | 4.64 | −22% | 5.99 | 4.77 | −20% |
| LNL (Arc 140V) | 1030 tokens | 39 | 6.52 | 4.95 | −24% | 6.61 | 5.30 | −20% |
| LNL (Arc 140V) | 128 tokens | 20 | 1.92 | 1.75 | −9% | 2.09 | f16 activations | — |
| LNL (Arc 140V) | 128 tokens | 39 | 2.50 | 2.30 | −8% | 2.69 | f16 activations | — |
| BMG (B580) | 1030 tokens | 20 | 1.49 | 1.27 | −15% | 1.40 | 1.02 | −28% |
| BMG (B580) | 1030 tokens | 39 | 1.61 | 1.33 | −17% | 1.52 | 1.13 | −26% |
| BMG (B580) | 128 tokens | 20 | 0.51 | 0.48 | −7% | 0.51 | f16 activations | — |
| BMG (B580) | 128 tokens | 39 | 0.67 | 0.62 | −8% | 0.67 | f16 activations | — |
| PTL (b082, 12 Xe-cores) | 1030 tokens | 20 | 3.56 | 3.47 | −3% | 4.17 | 3.42 | −18% |
| PTL (b082, 12 Xe-cores) | 1030 tokens | 39 | 4.35 | 3.76 | −14% | 4.63 | 3.94 | −15% |
| PTL (b082, 12 Xe-cores) | 128 tokens | 20 | 1.45 | 1.41 | −2% | 1.76 | f16 activations | — |
| PTL (b082, 12 Xe-cores) | 128 tokens | 39 | 1.90 | 1.85 | −3% | 2.35 | f16 activations | — |
| PTL (b090, 4 Xe-cores) | 1030 tokens | 20 | 7.27 | 5.74 | −21% | 7.13 | 5.27 | −26% |
| PTL (b090, 4 Xe-cores) | 1030 tokens | 39 | 8.00 | 6.04 | −24% | 7.95 | 5.89 | −26% |
| PTL (b090, 4 Xe-cores) | 128 tokens | 20 | 2.45 | 2.11 | −14% | 2.54 | f16 activations | — |
| PTL (b090, 4 Xe-cores) | 128 tokens | 39 | 3.29 | 2.79 | −15% | 3.40 | f16 activations | — |

At 128 tokens int4 is below the default threshold and runs master's f16 path, apart from the faster f16 gather; with int8 activations forced, OneDNN's s8:s4 down GEMM would make it up to 17% slower there. On the 12 Xe-core PTL the u3 int8 gate/up GEMMs are still slightly slower than OneDNN f16 at 1030 tokens of layer 20 (2.04 vs 1.82 ms for gate + up, with the OneDNN gate timed without its post-op).

On one MoE layer of the 4 Xe-core PTL end to end (layer 0, random routing, device time of the MoE kernels per inference), this PR takes 4.97 ms at 130 tokens and 6.40 ms at 1032 tokens, vs 5.69 and 7.92 ms on master.

Tests

The unit tests take DYNAMIC_QUANTIZATION_GROUP_SIZE and DYNAMIC_QUANTIZATION_GROUP_SIZE_MAX and derive the expected kernels from them: per token, 256, 128, 64, 32 (unsupported, f16), 0, and a group size above the max. They cover u3 (with and without a zero point, single-token decode on the int8 GEMMs for shapes without a batched GEMV, with the row tiles written by the GPU mask gen), symmetric i4/i8 and asymmetric u4 on OneDNN, and the token threshold for both (at or below it, u3 falls back to the OneDNN grouped matmul on f16 activations). A u3 prefill case with the GPU mask gen forced covers the tile list written on the GPU.

Tickets:

N/A

AI Assistance:

yes. Agents were used to implement dynamic quantization. Tests were executed for validation

Diff: 650 lines (+487 / -163) across 8 files Reviewer: v-Golubev Review duration: 30540m
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
0.57
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.344
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #39666"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 57% (MEDIUM) · Higher = larger blast radius
57%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 30.4% · Safe to merge
30.4%