Skip to content

Widen w4a16 perf-bench weight rotation to match in-model timing - #1065

Merged
mgehre-amd merged 1 commit into
gfx11from
matthias.w4a16-bench-rotation-footprint
Jul 28, 2026
Merged

Widen w4a16 perf-bench weight rotation to match in-model timing#1065
mgehre-amd merged 1 commit into
gfx11from
matthias.w4a16-bench-rotation-footprint

Conversation

@mgehre-amd

@mgehre-amd mgehre-amd commented Jul 28, 2026

Copy link
Copy Markdown

Problem

tests/kernels/quantization/test_hybrid_w4a16_perf.py rotates the weight operand through
several buffers so each captured call reads cold weights. The size was 48 MiB, justified in
the comment as "exceeds the gfx1151 32 MiB MALL".

Checking the bench against real per-call times from a vLLM torch-profiler trace
(cyankiwi/gemma-4-31B-it-AWQ-4bit, bs=1 decode, gfx1151) showed that rationale does not
hold. Standalone vs in-model wvsplitk_int4 average kernel time:

shape (MxNxK) in-model bench @ 48 MiB delta
1x43008x5376 gate_up 661.8 us 648.6 us −2.0%
1x5376x21504 down 343.8 us 279.2 us −18.8%
1x16384x5376 qkv 253.6 us 206.0 us −18.8%

48 MiB clamps n_buf to 2 for weights of 44–116 MB, so the two smaller shapes cycle an
~88 MB working set. That already exceeds MALL, yet still gets locality the model never
has — the model streams weights scattered across ~19.5 GB. The 116 MB shape matched only
because 2 buffers (231 MB) was already near-converged.

Fix

Raise _ROTATE_TARGET_BYTES to 512 MiB. All three shapes then land within 1.1%:

shape in-model bench @ 512 MiB delta
1x43008x5376 661.8 us 660.6 us −0.2%
1x5376x21504 343.8 us 340.0 us −1.1%
1x16384x5376 253.6 us 251.7 us −0.8%

Also included:

AI assistance

AI assistance (Claude Code) was used for this change: running the benchmarks, correlating
against the profiler trace, and drafting this description. All measurements above are real
runs on the target hardware, reproducible with the commands listed.

The rotation in test_hybrid_w4a16_perf.py existed to make each captured
call read cold weights, sized at 48 MiB on the rationale that this
exceeds the gfx1151 32 MiB MALL. Checking the bench against per-call
times from a vLLM torch-profiler trace (gemma-4-31B AWQ, bs=1) showed
that rationale is insufficient: the bench was 19% optimistic on the
44-58 MB weights while matching within 2% on a 116 MB one.

48 MiB clamps n_buf to 2, so those shapes cycle an ~88 MB working set.
That already exceeds MALL, yet still gets locality the model never has,
since the model streams weights scattered across ~19.5 GB. Raising the
target to 512 MiB brings all three shapes to within 1.1% of the trace.

Also adds the three gemma-4-31B shapes that exposed this, and makes both
rotation constants env-overridable so the value can be re-validated.

Changes:
- 512 MiB, not larger: 512 and 2048 MiB measure identically, so this is
  past the knee. _ROTATE_MAX stays 32; small weights converge at the
  ~84 MB that 32 buffers already give, and raising the cap changed
  nothing for them.
- Goldens are fully regenerated because the wider rotation shifts every
  shape whose weight exceeds ~24 MB.
- Comparisons were made with both sides unpinned. Pinning the clock via
  a fixed shader frequency is actively misleading here: it slowed the
  in-model kernel by 44% while barely moving the bench, because the
  serving stack's CPU load shares the package power budget and forcing
  gfxclk high makes the SMU cut memory/fabric clocks instead.

Known issue, why this is a draft: the regenerated goldens are not
reproducible at the current +/-8% tolerance. Two verification runs
against them failed 18/140 and 19/140, always in the "improvement"
direction, and two independent recording runs disagree by more than
+/-8% on 17.5% of measurements. The unmodified 48 MiB setting verifies
at 1/128. The wider footprint appears to import the same physical-page
/ TLB variability that makes it accurate, so tolerance handling needs
to be resolved before this can merge.

Signed-off-by: Matthias Gehre <matthias.gehre@amd.com>
@mgehre-amd
mgehre-amd requested a review from eble-amd July 28, 2026 12:24
@mgehre-amd
mgehre-amd merged commit 599d224 into gfx11 Jul 28, 2026
6 of 7 checks passed
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