Skip to content

[FlyDSL] Fix issue 7967:mm_a8w8_mxscale_gfx950: support a K of 32 mod 64 (DeepSeek-V4.1 shared-expert down projection at TP8, K = 288) - #8636

Merged
valarLip merged 3 commits into
mainfrom
fix_7967
Nov 25, 2026

Conversation

@solinzby1

Copy link
Copy Markdown
Contributor

perf :

N K M range Rows Avg speedup Min Max TFLOPS (heuristic → tuned, range median)
5120 288 1–256 20 +18.0% +0.9% +32.9% —
5120 288 288–1024 24 +30.2% +20.0% +52.8% —
5120 288 1088–2048 16 +29.5% +8.0% +51.2% 403 → 534
5120 288 2304–3840 9 +47.2% +20.6% +73.9% 477 → 726
5120 288 4096–32768 8 +34.2% +21.8% +54.0% 719 → 963

@solinzby1
solinzby1 requested review from a team and a balanced review from Copilot November 25, 2026 03:04
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 8636 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

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 stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@github-actions github-actions Bot changed the title Fix issue 7967:mm_a8w8_mxscale_gfx950: support a K of 32 mod 64 (DeepSeek-V4.1 shared-expert down projection at TP8, K = 288) [FlyDSL] Fix issue 7967:mm_a8w8_mxscale_gfx950: support a K of 32 mod 64 (DeepSeek-V4.1 shared-expert down projection at TP8, K = 288) Nov 25, 2026
@aiter-bot

aiter-bot commented Nov 25, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision f640c21521ca · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_batched_gemm.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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.

🟡 Changes recommended

Padded B and scale loads can contaminate otherwise finite outputs with neighboring NaNs, and the ragged-K regressions do not fail on numerical mismatches.

2 open issues
What changed in this PR

Extends the gfx950 FlyDSL MXFP8 GEMM to support K values divisible by 32, targeting DeepSeek-V4.1’s TP8 shared-expert projection with K=288 from issue #7967.

Changes:

  • Generalizes partial-step masking and adds a BF16 batched-GEMM fallback.
  • Expands ragged-K regression cases and fused-quantization checks.
  • Adds 77 tuned configurations for N=5120, K=288.
File Description
op_tests/​test_gemm_a8w8_mxfp8_bpreshuffle.py Adds K=288 public-entry regression shapes.
op_tests/​test_flydsl_batched_gemm.py Expands ragged-K kernel and fused-quantization coverage.
aiter/​ops/​gemm_op_a8w8.py Adds the BF16 batched-GEMM heuristic fallback.
aiter/​ops/​flydsl/​kernels/​bmm_a8w8_mxscale_gfx950.py Accepts 32-wide K granularity and generalizes A-tail masking.
aiter/​configs/​model_configs/​dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv Adds tuned K=288 configurations across M sizes.

Review effort: Balanced

Comment on lines +939 to +942
if const_expr(k_tail and last):
masks = tuple(
_tail_mask(start, final) for start in (0, MFMA_K // 2)
)
shapes = args.mnk or tuned_shapes()
if args.mnk is None and get_gfx() == "gfx950":
shapes = shapes + RAGGED_K_MNK_GFX950
df = pd.DataFrame([test_gemm(*mnk) for mnk in shapes])
Copilot AI balanced review requested due to automatic review settings November 25, 2026 05:28

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

Tail masking leaves B fragments and scale operands unsanitized, allowing neighboring NaNs to contaminate finite outputs, while the added regression cases do not assert numerical correctness.

2 open issues

Review effort: Balanced

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (5)

Thanks, the tail mask itself checks out: for every K that 32 divides, _tail_mask keeps exactly the 16-K lane chunks inside K, and for K % 128 in {0, 64} it emits the same masks as half_step did, so existing shapes compile to the same kernel. The last K tile is always a static tail step, and the new 32x32 ragged-K cases ran and passed in CI (MI35X shard 1).

  1. Keep a neighbour token's A scale out of the partial step, or answer the Copilot thread at :942. bmm_a8w8_mxscale_gfx950.py:931-1000 masks only A's codes in the last step:
    • The lane groups whose 32-K group lies past K still feed the next row's (or next batch's) x_scale bytes to the MFMA. For K = 288 that is groups 1-3; for K % 128 == 64 it was already groups 2-3.
    • If that token's scale is E8M0 0xFF (an inf/NaN activation), the zero codes meet a NaN scale. One bad token then turns another request's row into NaN. Issue #7967 asked for this case.
    • Suggested fix: in the final split's partial step, select 127 (1.0) for sa in those lane groups. It is static and runs only in the tail.
    • Say in the comment at :931-935 that B and w_scale past K are real weight bytes or zeros past the buffer.
    • Add a case that sets the next row's x_scale to 0xFF and checks that the row before it stays finite.
  2. Make the new ragged-K checks fail on a mismatch.
    • op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py:145-148 only logs the checkAllclose ratio, and the new fallback at gemm_op_a8w8.py:3076 is tested only there. This is the second Copilot thread.
    • The gfx950 1x32 ragged-K shapes in test_batched_gemm ((33,1024,544), (4096,512,576)) are also only logged by summarize.
    • Assert on both.
  3. Fold the new branch and fix the text it makes stale.
    • gemm_op_a8w8.py:3074-3080 can be the single line is_bmm = kernel_name is None or kernel_name.startswith(f"{_BMM_MFMA_NAME_PREFIX}_"). It behaves the same: a non-bf16 output still goes to mxpsh with None.
    • Stale text:
      • :2968-2971 says "an untuned gfx950 shape runs the mxpsh heuristic tile".
      • :3049-3050 says the bmm runs only "where a tuned row (kernelId "bmm") picked it".
      • The warning at :2998-3002 logs "falling back to flydsl kernel 'None'" for K = 288 (seen in the CI log).
      • bmm_a8w8_mxscale_gfx950.py:265 still says "half step".
      • test_flydsl_batched_gemm.py:746 says "(32x32 scale only)", but gfx950 now runs 1x32 too.
  4. Give the perf table a baseline that exists today. "heuristic → tuned" compares the CSV rows against this PR's own bmm heuristic. Main cannot run K = 288 at all. ATOM runs it today through ROCm/ATOM#3361, padded to K = 320 with two pad launches. Please compare tuned K = 288 against that path, pad launches included, for a few M (1, 64, 512, 2048, 8192).
  5. Write a PR description and squash text.
    • Description: the problem (#7967: V4.1 TP8 shared-expert down projection, check_bmm_config rejects K % 64 == 32), the fix (the k_tail mask, the untuned-entry fallback, 76 tuned cu256 32x32 rows), the tests and their CI lane, and the baseline.
    • Title: "mm_a8w8" should be "bmm_a8w8".
    • Squash: one message instead of "retune N=5120 K=288 bmm rows" plus a merge commit, without the [email protected] (sic) co-author line.

Reviewed at f640c21 (Deep, first review: hunter A + independent pass B, CPU only, CI logs checked). Open review threads: 2 (Copilot, items 1-2).

@valarLip
valarLip merged commit fb3f506 into main Nov 25, 2026
80 of 82 checks passed
@valarLip
valarLip deleted the fix_7967 branch November 25, 2026 13:34
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
#8978)

* K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows (#8778 @ ea7a5d8)

#8778 (aoli26; base main; open) applied to k3-455-dev as its net change on its 19 files at head
ea7a5d8 (2026-11-26T14:47:07Z), 3-way against the PR's main base adbb6ac. The 8 files k3-455-dev had
changed (all only by #8246 @ 15808c7) take the PR's version, so all 19 files equal the PR head. It
carries the newer #8246 (ccc4270), the table PRs #8579 / #8586 / #8601 and main's #8566 (its compute
guard, which #8778 replaces); no other main change rides in.

Validated in the K3 1P1D integration branch (aiter zejun/k3-455-dev 627e1eb) on 16 MI455X
(wuhuikx/LLM-Booster#578). The PR head has moved on since (204ce9d: merges of #8246 @ 0d6cf15 and of
main, which brings #8737); those can follow when #8778 lands.

Co-authored-by: zejunchen-zejun <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Update K3 FP8 kernels to c997 and add exact-M tuning

Preserve the existing dev wrappers and bucket tables. Add 162 accepted retuned exact configurations and 3 c997-default compatibility records, with CPU dispatch coverage for all 675 measured points. Backport the three kernel files from c99781c without merging main history. Integrated-head GPU validation remains outstanding.

---------

Co-authored-by: aoli26 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Zhang <[email protected]>
(cherry picked from commit 1cc9d02)

Rebase onto main 12-03: the 19 files keep this commit's content; only main's later changes are added: the AOT launcher factories of #8678 (mxfp8 / batched wrappers launch gemm_a8w8_launcher.lazy(), _gemm_a8w8_compute_bound_launcher.lazy(), splitk_reduce_launcher.lazy(); _lazy_import keeps _data_ptr), #7449's deferred split-K entry points and #8636's ragged-K fallback. gemm_a8w8_gfx1250.py: this commit's rank0 split-K epilogue and flush_addr (it already carries #8737's flush). gemm_op_a8w8.py: main's #8566 guard in get_mxscale_bpreshuffle_config (no padded row below a compute kernel's M tile) is removed, as on the #8778 head, because the c997 compute kernel serves underfilled tiles; test_gemm_host_dispatch_cache.py takes #8778's test_mxscale_compute_row_serves_underfilled_m_tile in place of main's two guard tests. kimik3 mxscale tuned CSV: this commit's rows (626 changed or added) replayed by key; the result equals this commit's table.

Rebase onto main 12-03: main #7449 moved the bpreshuffle row lookup into _bpreshuffle_config(XQ, WQ); this commit's Kimi-K3 exact-row lookup there needs x_scale, w_scale and Y, so _bpreshuffle_config takes them (the deferred split-K path passes a meta tensor of the output's shape and dtype, so it picks the same row as gemm_a8w8_bpreshuffle).

Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce).
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.

4 participants