Repository navigation
[FlyDSL] Tune the GLM-5.2 decode shapes for gfx950 - #5328
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
3c25694 to
dcbcc51
Compare
…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.
dcbcc51 to
40c85e7
Compare
There was a problem hiding this comment.
🔵 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_logitskernel (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.
There was a problem hiding this comment.
🔵 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
Motivation
A GLM-5.2 decode step issues each GEMM at two M values per concurrency —
M=concfor the EAGLE draft pass andM=conc*6for the verify pass. Theuntuned 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)combinationshave 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_configsreads theper-CU LDS size through a
getattrwhose default argument is evaluated eagerly,so on a torch carrying neither
shared_memory_per_multiprocessornorshared_memory_per_blockit raises instead of falling back. On2.9.1+rocm7.2.0that is every call, which leaves the A16W16 tuner unable toproduce a single candidate for any shape.
Technical Details
1.
flydsl: stop the A16W16 policy from raising on torches without the LDS fieldaiter/ops/flydsl/gemm_a16w16_policy.py(+4 −6)chip_infoalready keeps the architectural LDS capacity in a table, and thismodule 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 foraiter/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:
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:
incumbent, by up to 6.2%.
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.
(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_gemmfamily — thecanonical file plus all 17
model_configs/*bf16_tuned_gemm*.csv— rather thanchecking the added file alone.
Policy.
get_flydsl_a16w16_configscalled for four GLM-5.2 decode shapesbefore and after the change, and one config per distinct
block_nexecuted andchecked against a fp32 reference — including
block_nvalues that do not divideN, since
N=19360is 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_a16w16from 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_bf16over the18-file merge. The guard's own positive and negative controls
(
selfcheck_detects_planted_duplicate,selfcheck_passes_on_clean) pass, so itis not vacuously green.
Policy: the four shapes that previously raised
AttributeErrorreturn786 / 589 / 289 / 1683 candidates. Every executed config matches the fp32
reference, including
block_n= 64 / 96 / 128 / 256 againstN=19360.Decode step, six samples per arm, medians:
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