Skip to content

[FlyDSL] fix: select FMoE GEMM2 A addressing by stored buffer size - #5519

Merged
coderfeli merged 3 commits into
mainfrom
fix/fmoe_gemm1_buf
Sep 16, 2026
Merged

coderfeli merged 3 commits into
mainfrom
fix/fmoe_gemm1_buf

Conversation

@Bernard-Liu

@Bernard-Liu Bernard-Liu commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

GEMM2 buffer addressing cannot represent an A buffer of 4 GiB or larger, which can produce incorrect results for large-token MoE workloads.

Select the addressing mode from the actual A tensor size so that large inputs use 64-bit global addressing while smaller inputs retain the existing buffer-load path.

Technical Details

  • Add requires_flydsl_stage2_global_a() and share it between runtime and AOT. The decision uses numel() * element_size() >= (1 << 32), correctly accounting for packed FP4 storage, declared padding, and contiguous views.
  • Propagate the internal use_global_a compiler parameter through FMoE and FHMoE. Direct compiler callers retain the safe default of True.
  • Select sync buffer/global loads and async buffer-to-LDS/global-to-LDS operations at compile time. Construct the A descriptor only for the buffer variant.
  • Distinguish both variants in compilation caches and generated symbols through _abuffer and _aglobal.
  • Use FakeTensor metadata to compile the required AOT variant without allocating a large GPU buffer. Keep AOT consistent with runtime for FP8 persist_m adjustment and automatic reduce selection for large outputs.
  • Preserve public runtime APIs, GPU launch arguments, CSV schemas, and the existing Graph warmup/capture/replay workflow.

Test Plan

Validation was performed on gfx950 with FlyDSL 0.3.2.

  • Check FP8 and packed FP4 inputs below, at, and above the 4 GiB boundary where representable.
  • Exercise ordinary MoE/FHMoE, sync/async loads, atomic/reduce output, and small contiguous views whose backing-storage offsets exceed 4 GiB.
  • Validate eager execution, Graph replay, and replay after updating input data and routing.
  • Check host metadata decisions and runtime/AOT parameter propagation, then compile small and exact-4-GiB FP8/FP4 AOT configurations.
  • Recompile 11 configurations with both addressing modes before and after rebasing onto current main; compare complete ISA, .text bytes, and code-object resources.
  • Run full two-stage FMoE with a local tuned CSV using token=262144, H=7168, I=3072, E=24, top-k=6, swiglu_limit=10, and an FP32 reference. This configuration has a 4.5 GiB FP8 A buffer.
  • Run Black, Ruff, Python compilation, and git diff --check on the changed files.

Test Result

Validation | Result -- | -- Stage2 correctness and Graph checks | 64/64 passed on the final head; the same 64 passed before rebase Compilation and ISA comparison | 44 builds succeeded; all 22 corresponding ISA, .text, and resource comparisons matched Global variant descriptor checks | All 11 global variants omitted the A descriptor Host metadata and parameter propagation | 24/24 passed Actual AOT compilation | 4/4 passed without initializing the Torch GPU runtime Changed-file formatting and static checks | Passed

The full-FMoE run selected _aglobal and reported no NaNs. The final-head logits_diff was 7.9042e-6, satisfying the agreed <= 0.01 criterion. Elementwise mismatch was 13.3% on both revisions; this result does not claim elementwise equality.

Standards and Spec reviews found no outstanding issues. The full CSV performance matrix was not rerun after rebase.

@Bernard-Liu
Bernard-Liu requested review from a team and a lite review from Copilot September 15, 2026 05:59
@github-actions github-actions Bot changed the title fix: select FMoE GEMM2 A addressing by stored buffer size [FlyDSL] fix: select FMoE GEMM2 A addressing by stored buffer size Sep 15, 2026
@github-actions

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 5519 --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.

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

A critical async large-buffer compilation issue and moderate AOT and CI coverage gaps remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR selects FlyDSL MoE GEMM2 activation addressing based on packed buffer size, using 64-bit global pointers for buffers at or above 4 GiB.

Changes:

  • Propagates use_global_a through runtime, AOT, ordinary MoE, and FHMoE paths.
  • Adds synchronous and asynchronous global-pointer activation loads.
  • Adds large-buffer boundary and regression tests.
File summaries
File Reviewed changes
op_tests/test_flydsl_moe_large_buffer.py Adds large-buffer coverage; moderate gaps remain for default variant, offset-view, FHMoE, and FP4 CI execution.
aiter/ops/flydsl/moe_kernels.py Selects addressing mode from activation-buffer size.
aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage.py Forwards the addressing option.
aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py Implements addressing variants; critical raw global_load_lds pointer handling issue remains.
aiter/ops/flydsl/kernels/fhmoe.py Forwards addressing for FHMoE.
aiter/ops/flydsl/fhmoe.py Propagates runtime configuration.
aiter/aot/flydsl/moe.py Selects the AOT addressing variant; moderate focused AOT coverage is still needed.
Review details

Suppressed comments (2)

aiter/aot/flydsl/moe.py:809

  • The new large-buffer script exercises the runtime wrapper, but it never drives _precompile_to_cache or an AOT backend. This newly added AOT-specific size decision can therefore regress independently (for example, compiling a large-buffer entry with _abuffer) while the runtime test remains green; please add a focused AOT test that checks the forwarded use_global_a value on both sides of the 4 GiB boundary.
                use_global_a=a.numel() * a.element_size() >= (1 << 32),

op_tests/test_flydsl_moe_large_buffer.py:337

  • The same no-argument CI invocation leaves the newly exposed offset_view, reduce, and fhmoe branches disabled: the defaults below are only own, atomic, and moe. In particular, offset_view is the only test that verifies the intended distinction between a small logical buffer and a base pointer located above 4 GiB, while FHMoE exercises the new shared-expert forwarding. Please run at least focused boundary cases for these variants in CI rather than relying on optional command-line flags.
        "--modes", choices=["atomic", "reduce"], nargs="+", default=["atomic"]
    )
    parser.add_argument(
        "--storage", choices=["own", "offset_view"], nargs="+", default=["own"]
    )
    parser.add_argument(
        "--families", choices=["moe", "fhmoe"], nargs="+", default=["moe"]
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Initialize captured A-load bindings before specialization and share the 4 GiB predicate between runtime and AOT.

Stop tracking the local validation report and large-buffer harness while retaining their workspace copies.
Copilot AI review requested due to automatic review settings September 15, 2026 15:26

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

Fix compiler defaults and add regression coverage for global-addressing variants.

Get a fresh assessment by requesting another Copilot review.

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

Comment thread aiter/ops/flydsl/moe_kernels.py Resolved
@binding7012

Copy link
Copy Markdown
Contributor

LGTM

@coderfeli
coderfeli merged commit a7ff56d into main Sep 16, 2026
316 of 335 checks passed
@coderfeli
coderfeli deleted the fix/fmoe_gemm1_buf branch September 16, 2026 14:47
@zufayu

zufayu commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Advisory review (static + hand-run; not a merge gate). Validation/Perf ran no GPU stage — reasons are on their lines below. Findings tagged [verified] are traced to code/repro.

Selects the FlyDSL MoE stage2 (GEMM2) A-activation addressing mode at compile time from the A tensor's stored size — A at or above 4 GiB builds an _aglobal variant that addresses A through 64-bit global pointers (sync ptr_load plus async global_load_lds), smaller A keeps the existing 32-bit buffer-descriptor path — and threads the same use_global_a decision through the runtime, FHMoE, and the AOT precompiler.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — the PR changes runtime code but ships no test target (auto-validation disabled, REVIEW_AUTO_VALIDATE=0)
Perf (advisory): NOT RUN — no perf target for the same reason there is no test target: the PR changes runtime code but ships no test target

⚠️ [verified] The final head ships zero tests for the _aglobal variants this diff adds to aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py (load_x / dma_x_tile_to_lds) and for the new requires_flydsl_stage2_global_a in aiter/ops/flydsl/moe_kernels.py: the boundary test that existed earlier in this PR (op_tests/test_flydsl_moe_large_buffer.py, covered by the first bot review on commit b7cbdc9 as 1 of 7 files) is absent from the final 6-file diff, and existing CI (op_tests/flydsl_tests/test_flydsl_moe.py, op_tests/test_fhmoe.py) only reaches the < 4 GiB _abuffer variant. An A buffer at or above 2^32 bytes (about 233k tokens at topk=6, I=3072, fp8 — reachable in long-context prefill) is exactly the regime that produced silently wrong GEMM2 results, so a future refactor of load_x/dma_x_tile_to_lds could break the _aglobal path with no CI signal, and the PR body's 64/64 and logits_diff 7.9042e-6 numbers have no committed reproducer. Author must restore a committed regression test for the boundary — a >= 4 GiB A run where the GPU can represent it, or at minimum host-side checks that requires_flydsl_stage2_global_a and the use_global_a propagation select _aglobal/_abuffer on both sides of 2^32 — or state on the PR why it cannot be committed.

⚠️ [verified] Stage1 has the same unfixed bug this PR fixes for stage2: compile_mixed_moe_gemm1_common still builds x_rsrc = ptr_rsrc(arg_x, x_nbytes_i32) unconditionally (mixed_moe_gemm_2stage_common.py:602, no global variant anywhere in the stage1 emitter) and gathers A through buffer_copy_gmem16_dwordx4 at :761. Stage1's A is the [tokens, model_dim] input, which crosses 4 GiB at about 599k fp8 tokens (H=7168; about 1.2M for fp4), so the "large-token MoE workloads" named in the motivation still get silently wrong stage1 output above that — this PR makes the full FMoE correct only for tokens between roughly 233k and 599k. Author must extend the same stored-size addressing selection to stage1's A, or state the supported stage1 token bound on the PR.

⚠️ [verified] The bf16-A stage2 path is not covered: compile_flydsl_moe_stage2 (moe_kernels.py:759) dispatches a_dtype=bf16 to compile_gemm2_a16w4_port, which stages A through a 32-bit buffer view (moe_2stage_a16wmix/utils.py make_a_loader, _global_i32_buffer_view plus BufferCopy atoms) with no use_global_a equivalent, even though this PR added the parameter to the same function's fp4/fp8 arm. bf16 A crosses 4 GiB at about 116k tokens (topk=6, I=3072) — half the fp8 threshold this PR fixes — so a W4A16 model at e.g. 150k tokens still computes wrong GEMM2 results after this PR. Author must confirm whether the a16w-mix path needs the same stored-size selection, or state that its token range is bounded below the limit.

📝 [verified] GEMM2's weight buffer resource (w_rsrc = ptr_rsrc(arg_w, w_nbytes), mixed_moe_gemm_2stage_common.py:3511) is an unconditional 32-bit descriptor: W2 is 3.77 GB at DSv3 scale (E=257, H=7168, I=2048) and crosses the same 4 GiB limit at E >= 293, while stage1's W already carries a per-expert 64-bit re-base (:725) for exactly this reason. No shipping model crosses it today, but a larger-expert-count model would hit silently wrong W loads with no size guard. Reviewer should ask whether a W-side guard or per-expert re-base is planned for GEMM2.

📝 [inferred] No base-vs-head codegen comparison exists for the small-buffer path: the PR's 11-config ISA comparison ran before and after rebasing the PR (both sides carry the change), not head against the merge target, and the _abuffer branch of load_x in aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py — textually the old emitter under a const_expr else — is expected but not demonstrated to produce identical ISA. If the restructure (moved x_rows/x_elem/vec16_elems definitions, new branch nesting) shifted small-buffer codegen, every existing production shape would pay it and no measurement would catch it. Reviewer should ask for one _abuffer config's ISA and .text diff against the merge target to confirm zero codegen drift below 4 GiB.

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