Skip to content

[FlyDSL] Tune the GLM-5.2 decode shapes for gfx950 - #5328

Merged
coderfeli merged 2 commits into
mainfrom
kyle/upstream-dsa-kv-split
Sep 8, 2026
Merged

coderfeli merged 2 commits into
mainfrom
kyle/upstream-dsa-kv-split

Conversation

@kyle-256

@kyle-256 kyle-256 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A GLM-5.2 decode step issues each GEMM at two M values per concurrency —
M=conc for the EAGLE draft pass and M=conc*6 for the verify pass. The
untuned shape list the bf16 table is generated from walks a power-of-two M grid,
so 6, 10, 12, 14, 60 and 84 never appear. 116 of those (M, N, K) combinations
have no row anywhere in the merged tables and reach a config only through M
padding, which for M=84 means travelling all the way to 128.

Tuning them turned out to need a fix first. get_flydsl_a16w16_configs reads the
per-CU LDS size through a getattr whose default argument is evaluated eagerly,
so on a torch carrying neither shared_memory_per_multiprocessor nor
shared_memory_per_block it raises instead of falling back. On
2.9.1+rocm7.2.0 that is every call, which leaves the A16W16 tuner unable to
produce a single candidate for any shape.

Technical Details

1. flydsl: stop the A16W16 policy from raising on torches without the LDS field

aiter/ops/flydsl/gemm_a16w16_policy.py (+4 −6)

chip_info already keeps the architectural LDS capacity in a table, and this
module already imports from it, so the figure is taken from there rather than
from device properties.

2. glm5: tune the decode shapes the bf16 table was falling back to torch for

aiter/configs/model_configs/glm5_bf16_tuned_gemm.csv (+81 −0)

Missing a row is not the same as having no config: the lookup pads M up to a
multiple of 16, then to the next power of two, and takes the first hit. That
fallback is often cheap, but its cost scales with the distance travelled:

padding measured cost
M=60 → 64 +0.8 … +2.9%
M=12/14 → 16 +1.4 … +2.2%
M=10 → 16 +4.1 … +5.0%
M=84 → 128 +8.8 … +18.7%

So all 116 were tuned, then kept only where they earn their place. Adding a row
is not free: the lookup tries the exact M before any padded M, so a new row
replaces whatever padding was reaching, and the tuner never saw that incumbent
because it lives at a different M. Three rules:

  1. A row must beat what padding already reaches. 17 rows lost to their
    incumbent, by up to 6.2%.
  2. Judged against the finished table, not the current one. A candidate can
    be beaten by a sibling added in the same batch that now sits within padding
    reach of it. Iterated until stable; 2 more rows lost, one worth 28 us/step.
  3. Priced in microseconds per step, not percent. (fallback − mine) × reps,
    where a draft M is issued five times per step and a verify M once per layer.
    A 4% win at a draft M on a three-layer shape is 0.2 us. 16 rows fell below
    2 us/step.

81 rows remain: 53 serve a shape with no config at all, 28 beat what padding
reached. 64 resolve to flydsl and 17 to triton. None displaces an existing row,
so the diff is purely additive.

Test Plan

Shape collisions. python3 -m unittest op_tests.tuning_tests.test_config_shape_collision,
which drives the real runtime merge of the bf16_tuned_gemm family — the
canonical file plus all 17 model_configs/*bf16_tuned_gemm*.csv — rather than
checking the added file alone.

Policy. get_flydsl_a16w16_configs called for four GLM-5.2 decode shapes
before and after the change, and one config per distinct block_n executed and
checked against a fp32 reference — including block_n values that do not divide
N, since N=19360 is divisible by none of 64/96/128/256.

Decode step. Both arms in one process, one set of weight buffers, the lookup
dictionary swapped between measurements, arms interleaved ABBA, six samples
each. The step is replayed from a CUDA graph, since dispatching gemm_a16w16
from Python costs ~20 us against a ~4 us kernel, and every shape is issued at its
real layer count over eight distinct weight sets so that reusing one weight
matrix does not turn the measurement into an L2 hit.

Two more obvious harnesses were tried first and are not the basis of any number
here. Running arm A then arm B on one card puts all clock drift on B and
reported a consistent 2.6% regression on a shape where both arms dispatch the
same kernel. Running the arms side by side on two cards is worse: the node's
power budget couples them, so whichever job finishes first frees headroom and
the survivor boosts, which made even the stock arm bimodal at 4214 ↔ 4452 us.

A control run with the same table on both arms establishes the noise floor.

Test Result

Shape-collision guard: 17 families pass, including test_bf16 over the
18-file merge. The guard's own positive and negative controls
(selfcheck_detects_planted_duplicate, selfcheck_passes_on_clean) pass, so it
is not vacuously green.

Ran 17 tests in 0.279s

OK

Policy: the four shapes that previously raised AttributeError return
786 / 589 / 289 / 1683 candidates. Every executed config matches the fp32
reference, including block_n = 64 / 96 / 128 / 256 against N=19360.

Decode step, six samples per arm, medians:

  TP4 conc=4    3777.8 -> 3644.8 us    -3.52%
  TP4 conc=8    4101.5 -> 4100.6 us    -0.02%
  TP4 conc=10   4474.9 -> 4248.9 us    -5.05%
  TP4 conc=14   5267.1 -> 4720.3 us   -10.38%
  TP8 conc=1    2915.3 -> 2663.4 us    -8.64%
  TP8 conc=2    3000.7 -> 2690.8 us   -10.33%

No point regresses. Each point's six samples span under 1%, and the same-table
control moves less than 0.4%, so conc=8 is flat rather than slightly slower.
What a point gains depends on whether its M already reached a tuned row through
padding, which is why conc=14 gains and conc=8 does not.

Submission Checklist

@kyle-256
kyle-256 requested review from a team and a lite review from Copilot September 8, 2026 08:06
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5328 --add-label <label>

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.

@github-actions github-actions Bot changed the title GLM-5.2 decode: split the DSA indexer across KV, unblock the A16W16 policy, and tune the decode M grid [Triton/Gluon] [FlyDSL] GLM-5.2 decode: split the DSA indexer across KV, unblock the A16W16 policy, and tune the decode M grid Sep 8, 2026
@kyle-256
kyle-256 force-pushed the kyle/upstream-dsa-kv-split branch from 3c25694 to dcbcc51 Compare September 8, 2026 08:08
…S field

get_flydsl_a16w16_configs read the per-CU LDS size as

    getattr(props, "shared_memory_per_multiprocessor", props.shared_memory_per_block)

whose default argument is evaluated eagerly, so on a torch that carries
neither attribute the getattr never gets a chance to fall back.  On
2.9.1+rocm7.2.0 that is every torch: device properties expose neither
name, and every call raises AttributeError, which leaves the A16W16
tuner unable to generate a single candidate.

chip_info already keeps the architectural capacity in a table, and this
module already imports from it, so take the figure from there.  On the
architectures this policy accepts a workgroup may occupy the whole per-CU
LDS, so the per-CU and per-workgroup figures coincide.

With the fix the four GLM-5.2 decode shapes that used to raise return
786 / 589 / 289 / 1683 candidates.
… for

The GLM-5.2 decode step issues each GEMM at two M values per concurrency --
M=conc for the EAGLE draft pass and M=conc*6 for the verify pass. The untuned
shape list this table is generated from walks a power-of-two M grid, so 6, 10,
12, 14, 60 and 84 never appear, and 116 of those (M, N, K) combinations had no
row anywhere in the merged tables.

Missing a row is not the same as having no config: the lookup pads M up to a
multiple of 16, then to the next power of two, and takes the first hit. That
fallback is often cheap -- M=60 landing on the M=64 row costs 0.8-2.9% -- but
it gets expensive as the gap widens, and M=84 has to travel to 128, which costs
8.8-18.7%.

All 116 were tuned and then kept only where they earn it. A row has to beat
what padding would otherwise reach, judged against the finished table rather
than the current one, since a candidate can be beaten by a sibling added in the
same batch that now sits within padding reach of it. Beyond that, a row has to
be worth more than 2us per step, counting how much slower the fallback is times
how often the step issues that M -- a draft M goes out five times, a verify M
once per layer, so a 4% win on a three-layer shape at a draft M is noise.

That leaves 81 of 116: 53 serve a shape with no config at all, 28 beat what
padding reached. 64 resolve to flydsl and 17 to triton. None displaces an
existing row.

Decode step, both arms in one process on one set of buffers, the lookup table
swapped between measurements, arms interleaved ABBA, six samples each:

  TP4 conc=4    3777.8 -> 3644.8 us    -3.52%
  TP4 conc=8    4101.5 -> 4100.6 us    -0.02%
  TP4 conc=10   4474.9 -> 4248.9 us    -5.05%
  TP4 conc=14   5267.1 -> 4720.3 us   -10.38%
  TP8 conc=1    2915.3 -> 2663.4 us    -8.64%
  TP8 conc=2    3000.7 -> 2690.8 us   -10.33%

No point regresses. Each point's six samples span under 1%, and a control run
with the same table on both arms moves less than 0.4%. Dropping the 35 rows
that did not clear the bar moves no point outside that control.
@kyle-256
kyle-256 force-pushed the kyle/upstream-dsa-kv-split branch from dcbcc51 to 40c85e7 Compare September 8, 2026 08:09
@github-actions github-actions Bot changed the title [Triton/Gluon] [FlyDSL] GLM-5.2 decode: split the DSA indexer across KV, unblock the A16W16 policy, and tune the decode M grid [FlyDSL] GLM-5.2 decode: split the DSA indexer across KV, unblock the A16W16 policy, and tune the decode M grid Sep 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new KV-split picker can raise on empty launches (division by zero) and should use the tensor’s device rather than torch.cuda.current_device() to avoid incorrect behavior in multi-GPU contexts.

Pull request overview

Improves GLM-5.2 decode performance and tuning coverage on gfx950 by (1) increasing fp8 MQA logits kernel parallelism via KV slicing, (2) fixing FlyDSL A16W16 policy candidate generation on Torch builds missing LDS device-property fields, and (3) extending the bf16 tuned GEMM table to cover decode-relevant M values.

Changes:

  • Add a KV-splitting heuristic and launch a 2D grid for the gfx950 Gluon fp8_mqa_logits kernel (query-block × KV-slice).
  • Make A16W16 policy occupancy estimation use architectural LDS capacity (chip_info) instead of fragile Torch device-property fields.
  • Add tuned (M, N, K) rows to the GLM-5 bf16 tuned GEMM CSV to reduce padding fallbacks.
File summaries
File Description
aiter/ops/triton/attention/fp8_mqa_logits.py Adds KV-split heuristic and 2D grid launch for gfx950 Gluon logits kernel.
aiter/ops/triton/_gluon_kernels/gfx950/attention/fp8_mqa_logits.py Implements KV-range partitioning by program_id(axis=1) via NUM_KV_SPLITS.
aiter/ops/flydsl/gemm_a16w16_policy.py Switches LDS capacity source to get_lds_capacity_bytes() to avoid Torch property issues.
aiter/configs/model_configs/glm5_bf16_tuned_gemm.csv Adds tuned rows for decode-shaped GEMMs to avoid expensive M-padding fallbacks.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 8, 2026 08:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It changes performance-critical kernel selection heuristics and tuned-kernel lookup data, so it warrants final human review to confirm the new LDS-capacity assumption doesn’t adversely affect pruning or runtime selection.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread aiter/ops/flydsl/gemm_a16w16_policy.py Resolved
@kyle-256 kyle-256 changed the title [FlyDSL] GLM-5.2 decode: split the DSA indexer across KV, unblock the A16W16 policy, and tune the decode M grid [FlyDSL] Tune the GLM-5.2 decode shapes for gfx950 Sep 8, 2026
@coderfeli
coderfeli requested a review from xytpai September 8, 2026 09:04
@coderfeli
coderfeli merged commit 3a7a22f into main Sep 8, 2026
84 of 86 checks passed
@coderfeli
coderfeli deleted the kyle/upstream-dsa-kv-split branch September 8, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants