Skip to content

[FlyDSL] Fix and efficiently initialize A8W4 MoE stage1 padding - #7796

Closed
yzhou103 wants to merge 4 commits into
ROCm:mainfrom
yzhou103:fix/flydsl-a8w4-stage1-padding-20261111
Closed

yzhou103 wants to merge 4 commits into
ROCm:mainfrom
yzhou103:fix/flydsl-a8w4-stage1-padding-20261111

Conversation

@yzhou103

@yzhou103 yzhou103 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix incomplete initialization of the FlyDSL A8W4 MoE stage1 intermediate padding. For an intermediate width of 640 (576 real columns + 64 padding columns) and tile_n=64, the current grid writes only 608 output columns. Stale Inf/NaN in the remaining 32 columns can propagate through MXFP8 quantization into the final MoE output.

This is a standalone kernel fix based on main cb4ac3423f56ef03ddf9d1c329d3ee32ca039270, discovered while reviewing #6433. It does not depend on, or modify, that PR's tuning CSV.

Motivation

Changing the grid to calculate all required padding fixes correctness, but doing extra GEMM work on zero weights adds latency. For tile-aligned A8W4 interleaved gate/up outputs, existing epilogue stores can also initialize the padded tail.

Changes

  • Count restored padding in both gate and up coordinates, and cap it at the physically allocated padding.
  • Use the actual launch dimensions in the XCD remapping calculation.
  • For the supported tile-aligned, nonsplit, unbiased A8W4 path with BF16/FP16 output, clear padding in the existing epilogue. The 576+64 example launches 18 useful GEMM blocks instead of 20 blocks in the correctness-only implementation, with no additional kernel launch.
  • Add 32 poisoned-workspace regression cases, checking the torch reference, exact zero padding, and guard rows. Run the sweep from the standard MoE op-test entry as well as the existing FlyDSL test module.

Performance (if applicable)

Hardware: gfx950, 256 CUs (MI355-class GPU). PyTorch 2.10.0+rocm7.2.4.git3d3aa833, HIP 7.2.53211, pinned FlyDSL 0.5.0. All variants use the same main tree and runtime; only the shared stage1 kernel source changes.

Workload: D=5120, I=640, intermediate_pad=64, FP8 activations, MXFP4 weights, BF16 output, interleaved gate/up, SiLU limit 10. Stage1 uses t32x64x256, k_wave=4; the three configurations are the affected rows from #6433. Timings exclude compilation and workspace poisoning. HIP events measure 100-call graphs replayed 20 times per interval.

Stage1, same process, identical input/output buffers, alternating variant order (median of 12 intervals, microseconds):

E / tokens / topk / waves_per_eu Original main (zero-tail control) Correctness-only grid fix This PR vs. correctness-only
385 / 1 / 7 / 4 8.385 8.901 8.306 -6.7%
129 / 1 / 4 / 2 7.162 8.040 7.453 -7.3%
129 / 2 / 4 / 3 6.280 5.927 5.622 -5.1%

Full fused_moe, separate-process confirmation in reversed variant order (median of 7 intervals, microseconds):

E / tokens Correctness-only grid fix This PR Change
385 / 1 27.466 27.277 -0.7%
129 / 1 25.125 25.239 +0.5%
129 / 2 27.527 26.851 -2.5%

Performance is not fully recovered for every configuration. E129/M1 remains 3–4% slower than original main in two alternating comparisons; separate-process stage1 measurements showed a larger 37–38% difference. Absolute stage1 timings are sensitive to the measurement setup, so this PR does not claim performance parity with the original implementation. The optimization consistently improves the alternating comparison against the correctness-only grid fix. Full MoE improvement is modest, and E129/M1 is slightly slower. The original implementation is only a zero-initialized correctness control, not a safe end-to-end baseline under arbitrary workspace contents.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No user-facing documentation change is needed: existing operation semantics and API are preserved.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

Base: cb4ac3423f56ef03ddf9d1c329d3ee32ca039270.
Validated kernel SHA256: 42bbdf9fd558093e011e4708c6c7c3a153d597cdf375daf9c05b6120edebf6f5.
PR head: 1ce7f9314b1c6311feefdcbf2f6535c275e90617.

Behavior and intent

Stage1 must initialize padding that is consumed by the next quantization/GEMM stage, even when the caller provides a workspace containing non-finite values. The optimized path gives each participating real-output vector a distinct padding vector to clear. Eligibility checks exclude split-K, fused quantized output, bias, heterogeneous weights, and unaligned tails; those cases retain the corrected grid path.

Validation and unverified scope

  • python3 -m pytest op_tests/flydsl_tests/test_flydsl_moe.py -q --tb=short: 66 passed on gfx950 with FlyDSL 0.5.0.
  • python3 op_tests/flydsl_tests/test_flydsl_moe.py: 32/32 regression/performance cases passed, with the Markdown metrics summary emitted.
  • Negative control: original main kernel + the same new regression cases: 20 failed, 12 passed. The regression detects both incomplete padding and the tile_k=512 overlaunch cases.
  • The new matrix sweeps (tile_n,tile_k,k_wave) = (64,256,4), (128,256,1), (64,512,1), (128,512,1); padding = 0/32/64/96; XCD swizzle = 0/4. It compares against the existing torch reference with checkAllclose and asserts zero mismatches, exact zero padding, and unchanged guard rows.
  • Public fused_moe validation for all three affected configurations, with stage1 workspace initialized to 0, 17, Inf, and NaN: 12/12 finite outputs, bitwise equal to the zero-workspace control, repeated in all completed optimized runs. Saved final outputs also equal original main's zero-workspace control.
  • Black and Ruff pass for all three changed files.
  • Standard entry attempt: python3 op_tests/test_moe_2stage.py --no-legacy --no-flydsl-csv --quant 7 stops in the pre-existing test_output_buffer_contract, before the added sweep, because triton.runtime.cache.triton_key() raises OSError: [Errno 5] Input/output error while reading a Triton file. Retrying with Inductor caches disabled encounters the same file-read error. This is not recorded as a passing standard-entry run.
  • Full-MoE profiler output in this environment reported missing events; the performance tables use independent HIP-event measurements instead.
  • MI250X/MI300X, full model serving, and the frequency of encountering poisoned allocator memory have not been validated. This remains a draft while the standard-entry environment issue and residual performance difference are assessed.

PR-specific question

Pending the automated question after PR creation. The new regression fails with the original kernel, rather than relying on a pre-zeroed output or an unchecked numeric comparison.

Changed op tests

  • op_tests/flydsl_tests/test_flydsl_moe.py: extends existing data generation to choose padding/activation and adds the poisoned-output, torch-reference, guard-row, and performance sweep. Existing tests did not poison the caller-owned stage1 buffer for these tilings.
  • op_tests/test_moe_2stage.py: invokes the same regression sweep from the standard op-test entry, so this is not an isolated second test implementation.

@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 7796 --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.

@yzhou103
yzhou103 marked this pull request as ready for review November 11, 2026 05:41
@yzhou103
yzhou103 requested review from a team and a balanced review from Copilot November 11, 2026 05:41
@aiter-bot

aiter-bot commented Nov 11, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision d519e5a758c8 · 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. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  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 — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — validation answer must explicitly state what remains unverified (or say none with a reason)

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

The new absolute import fails for direct script execution with a wheel install and no repository root on PYTHONPATH, preventing the regression from running.

1 open issue
What changed in this PR

This PR fixes incomplete FlyDSL A8W4 MoE stage1 padding initialization, preventing stale non-finite workspace values from propagating into later stages. It is independent of the tuning changes in #6433.

Changes:

  • Correct padding calculations and use actual launch dimensions for XCD remapping.
  • Clear eligible padding through existing epilogue stores, avoiding extra GEMM blocks.
  • Add 32 poisoned-workspace regression cases with reference, zero-padding, and guard-row checks, plus standard MoE test-entry integration.
File Description
op_tests/​test_moe_2stage.py Invokes the padding regression sweep from the standard test entry.
op_tests/​flydsl_tests/​test_flydsl_moe.py Adds configurable test data and padding correctness/performance cases.
aiter/​ops/​flydsl/​kernels/​mixed_moe_gemm_2stage_common.py Fixes padding launch bounds and adds optimized epilogue tail clearing.

Review effort: Balanced

Comment thread op_tests/test_moe_2stage.py Resolved
Copilot AI balanced review requested due to automatic review settings November 12, 2026 04:06

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

Shared stage1 grid and XCD remapping changes extend beyond tested cases, while GPU validation is unavailable, the standard-entry run is incomplete, and production-shape performance differences remain unresolved.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 12, 2026 06:41

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

Shared stage1 launch and epilogue changes affect paths beyond the regression coverage, while unavailable GPU validation and an unresolved standard-entry failure leave correctness and latency unconfirmed.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 12, 2026 07:18

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

Human GPU review is needed because shared stage1 grid and epilogue changes lack independent head-matched gfx950 validation, with a blocked standard-entry run and unresolved timing differences.

1 open issue

Review effort: Balanced

cpersson-amd added a commit to cpersson-amd/aiter that referenced this pull request Nov 18, 2026
…h-grid remap

ROCm#7796 was closed without merging; ROCm#7822 handles the stage-1 padding in
the dispatch instead. Drop its padding changes and tests, but keep the
remap over the launch grid: stage 1 launches tile2_pad more N columns
than the count the remap recomputed, so with intermediate_pad (DSv4.1
TP4: 576 + 64) an xcd_swizzle stage 1 left the padded columns unwritten.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Carl Persson <[email protected]>
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