Skip to content

[FlyDSL] [Perf] Avoid empty Tensor construction for omitted MoE operands - #7248

Open
xytpai wants to merge 1 commit into
ROCm:mainfrom
xytpai:perf/moe-null-pointer-args-1031
Open

xytpai wants to merge 1 commit into
ROCm:mainfrom
xytpai:perf/moe-null-pointer-args-1031

Conversation

@xytpai

@xytpai xytpai commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pass omitted MoE launch operands as an explicit null PointerJitArg, instead of allocating zero-element Torch tensors solely to recover their null data_ptr().

  • ptr_arg(None) constructs the same default Uint8/global/trivial-alignment pointer descriptor and C ABI as ptr_arg(torch.empty(0)). Existing Tensor/FakeTensor handling remains.
  • Replace empty placeholders in route indices, psum/remap, gather/reduce, route-ksplit optional count, and disabled EP-psum arguments.
  • No Tensor, raw-address, mutable-pointer or device cache. Real output tensors and nonempty masked-row dummies are unchanged.
  • No kernel, quantization/math, dispatch policy, explicit stream behavior, or compile-cache key changes.

This removes small repeated Python Tensor allocations/metadata operations. It does not remove large GPU storage allocations or claim lower device-memory consumption.

Validation

Release base: bd4ff1c7087970a5b9af92f90c83635e4240f562; reviewed head: 0af25c06f51b583d8022b9bed3bbe81b4c0f18f3.

  • Separate gfx1250 GPU0 and GPU1 runs: 20 passed each for python3 -m pytest -q op_tests/test_moe_null_pointer.py.
  • Separate old-source/new-source GPU harness: 21 passed each, using the actual previous function bodies and old pointer helper/aliases for baseline.
  • GPU-hidden run: 6 passed, 14 skipped. Black/Ruff and git diff --check pass.
  • Null-vs-empty C ABI and cache signatures at Uint8/Int32/Float32, non-null values, FakeTensor metadata and live/disabled EP-psum operands.
  • Full public MoE A4W4/A8W4 M1/16/257: existing quantized reference gate, bitwise output equality, fewer empty Tensor constructions, changed-input non-default-stream graph replay.
  • Ordinary TP routing without EP truncation and actual EP routing with dynamic counts 23→7→0→23; optional inverse row map on/off; independent counts/start/end/gather reference.
  • The gather dead tail is unwritten, not implicitly zero: tests prefill it with a sentinel and assert preservation.
  • Independent profiler check: identical nonempty kernel-name/grid/block sequences at M257. Profiling is separate from timing.

Initial experimental tests had two incorrect assumptions (psum as padded inclusive sum, and EP truncation applied to the ordinary TP route / gather tail auto-zeroing). The old implementation reproduced the failures. The final tests use padded starts plus valid counts, the real EP branch for truncation, and a preserved tail sentinel. No numeric tolerance was relaxed.

Real full-MoE timing (host optimization, not model throughput)

gfx1250, M3 TP4-per-rank operator shape E129/top5/K6144/I768, SwiGLU. Single GPU with real route/quant/GEMM/reduce; not distributed TP4.
Python 3.12, FlyDSL 0.4.1, rocm/fw-bringup-mlperf:gfx1250-atom-20261023, WARNING logging. Unchanged main kernels, matched inputs. Two independent processes on two physical GPUs, 75 warmups/arm, 21 randomized paired rounds ×120 eager calls; synchronize before and after each timed block. Report CPU submission; completed timings are also retained.

Format Rows GPU0 old host µs GPU0 new host µs GPU0 paired saving µs GPU1 paired saving µs
a4w4 1 199.308 196.137 3.511 3.852
a4w4 16 200.423 196.496 3.816 4.210
a4w4 256 200.353 199.944 1.019 0.938
a4w4 2517 261.131 257.634 3.104 3.590
a8w4 1 191.888 188.205 3.691 4.093
a8w4 16 192.514 188.782 3.685 4.000
a8w4 256 189.534 189.231 0.377 0.697
a8w4 2517 251.720 248.577 3.141 2.747

Paired saving is the median of per-round differences, so it need not equal the difference of separately reported medians. M256 takes fewer affected paths and has only 0.38–1.02µs improvement; it is not reported as a large win.

Graph negative controls (8 full MoE calls/capture, 21 randomized paired samples, GPU events): relative differences range -0.55% to +1.09% across A4W4/A8W4 M1/256/2517. No graph/device speedup or strict graph non-regression claim is made from this small spread; numerical graph replay and launch-sequence identity pass.

Full M3 model ABBA is now complete: verified four-arm report. Descriptive mean-of-process-medians: short latency -1.71%, long-prefix latency -0.43%, C2 throughput -0.69%. The return baseline drifted upward; these limited data do not establish a whole-model speedup. No timed compile misses, but four Triton cache-hit loading events in return-baseline C2. All rounds retained. Post-timing profiles confirm 228 fewer torch.empty calls per short prefill on each rank. Synthetic acceptance is performance-only, not a quality oracle.

Artifacts on f01: ~/bench/m3_null_pointer_20261031/ (release_validation.json, GPU/JUnit logs, both release benchmark JSONs, graph negative samples, baseline/candidate sources and traces); model ~/bench/m3_null_model_20261031/.

PR Self-Review

Reviewed revision

0af25c06f51b583d8022b9bed3bbe81b4c0f18f3

Behavior and intent

Omitted launch arguments no longer construct empty Torch tensors solely for address zero. This hot eager overhead repeats per MoE layer; the pointer descriptor, ABI, optional-operand semantics and kernels remain the same. No pointer cache or real-output reuse is introduced.

Validation and unverified scope

Commands/results/hardware above. Run python3 -m pytest -q op_tests/test_moe_null_pointer.py in a ROCm/Python3.12 environment with the release checkout and FlyDSL0.4.1 on PYTHONPATH; physical GPU1 is selected with ROCR_VISIBLE_DEVICES=1 and HIP_VISIBLE_DEVICES=0 after ROCr renumbering. Black/Ruff checks cover the three changed modules and test file. Unverified: whole-model performance/quality, other-architecture performance, distributed EP transport, every unrelated ptr_arg consumer, and statistical graph-speed equivalence. Real EP local routing and optional arguments are tested; no distributed communication change is made.

PR-specific question

Before the patch ptr_arg(None) raises on data_ptr; ABI/FakeTensor-null assertions fail. The tests also require fewer zero-element constructions in the full public call, which numerical kernel tests alone cannot detect. Dynamic EP count/inverse-map/sentinel and live-pointer tests are regression controls expected to preserve previous correct behavior, not advertised as new pre-patch correctness failures.

Changed op tests

op_tests/test_moe_null_pointer.py adds optional-null descriptor/ABI/cache-signature and host-allocation coverage absent from canonical device arithmetic tests. It reuses the existing grouped-GEMM reference for six format/shape cases, and checks changed-input graph replay plus dynamic optional operands. The Tensor-backed-null oracle inside repository tests is a correctness oracle, not a performance baseline; performance used actual original source functions in independent experiments.

@xytpai
xytpai requested a review from a team October 31, 2026 15:35
@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 (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 gfx1201 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 7248 --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.

@aiter-bot

aiter-bot commented Oct 31, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 0af25c06f51b · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Omitted launch arguments no longer construct empty Torch tensors solely for address zero. This hot eager overhead repeats per MoE layer; the pointer descriptor, ABI, optional-operand semantics and kernels remain the same. No pointer cache or real-output reuse is introduced.

Validation and unverified scope

Commands/results/hardware above. Run `python3 -m pytest -q op_tests/test_moe_null_pointer.py` in a ROCm/Python3.12 environment with the release checkout and FlyDSL0.4.1 on PYTHONPATH; physical GPU1 is selected with ROCR_VISIBLE_DEVICES=1 and HIP_VISIBLE_DEVICES=0 after ROCr renumbering. Black/Ruff checks cover the three changed modules and test file. Unverified: whole-model performance/quality, other-architecture performance, distributed EP transport, every unrelated ptr_arg consumer, and statistical graph-speed equivalence. Real EP local routing and optional arguments are tested; no distributed communication change is made.

PR-specific question

Before the patch `ptr_arg(None)` raises on data_ptr; ABI/FakeTensor-null assertions fail. The tests also require fewer zero-element constructions in the full public call, which numerical kernel tests alone cannot detect. Dynamic EP count/inverse-map/sentinel and live-pointer tests are regression controls expected to preserve previous correct behavior, not advertised as new pre-patch correctness failures.

Changed op tests

`op_tests/test_moe_null_pointer.py` adds optional-null descriptor/ABI/cache-signature and host-allocation coverage absent from canonical device arithmetic tests. It reuses the existing grouped-GEMM reference for six format/shape cases, and checks changed-input graph replay plus dynamic optional operands. The Tensor-backed-null oracle inside repository tests is a correctness oracle, not a performance baseline; performance used actual original source functions in independent experiments.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

@xytpai

xytpai commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Complete M3 model ABBA: null-pointer metadata follow-up

Only the omitted-operand metadata change differs. Both arms use the same frozen prior host/cache/FP4 compact-policy/route-safety stack, M3 TP4, Simple, FP8 KV, EAGLE3 and synthetic acceptance 0.5933. This is not a current-main model comparison or a production-quality test.

30 short +30 long-prefix measured requests and 10 measured C2 pairs after 20 C2 warmup pairs per process. No profiler during timing; identical lightweight forward/event logging in each arm. cProfile runs only after all measured samples.

Order Arm Short request median ms Long-prefix request median ms C2 median output tok/s
1 baseline_a 82.058 89.296 519.27
2 gated_b 83.584 91.041 514.90
3 gated_c 85.189 90.931 513.49
4 baseline_d 89.647 93.458 516.31

Descriptive mean-of-process-medians changes (not statistical significance):

  • short_s: -1.71%.
  • long_s: -0.43%.
  • c2_tokens_s: -0.69%.

Recorded timed-window compile misses by arm: {'baseline_a': 0, 'gated_b': 0, 'gated_c': 0, 'baseline_d': 0}; Triton cache-hit events: {'baseline_a': 0, 'gated_b': 0, 'gated_c': 0, 'baseline_d': 4}.
No recorded compile misses, but cache-hit loading occurred in measured windows. These are not fully warm in-memory-launch samples; all rounds are retained.

All source/script hashes and expected worker import paths verified; all 70 measured input entries match between arms. Output text hashes matching baseline A: {'baseline_a': 70, 'gated_b': 70, 'gated_c': 70, 'baseline_d': 70} (not a quality oracle).

Post-timing rank0 short-prefill torch.empty counts (diagnostic only):

  • baseline_a: {'empty_calls': 1853, 'relevant_callers': {'flydsl_moe_gather_reduce': 57, 'contiguous_psum_remap': 285, 'flydsl_moe_topids_to_rows': 114, 'flydsl_moe_fused_quant_preshuffle': 171}}.
  • gated_b: {'empty_calls': 1625, 'relevant_callers': {'flydsl_moe_topids_to_rows': 57, 'flydsl_moe_fused_quant_preshuffle': 171, 'contiguous_psum_remap': 171}}.
  • gated_c: {'empty_calls': 1625, 'relevant_callers': {'flydsl_moe_fused_quant_preshuffle': 171, 'contiguous_psum_remap': 171, 'flydsl_moe_topids_to_rows': 57}}.
  • baseline_d: {'empty_calls': 1853, 'relevant_callers': {'flydsl_moe_gather_reduce': 57, 'contiguous_psum_remap': 285, 'flydsl_moe_topids_to_rows': 114, 'flydsl_moe_fused_quant_preshuffle': 171}}.

Only two baseline and two candidate processes, sequential ABBA, possible process drift. Small changes may be noise. No generalized throughput or accuracy improvement claimed. Operator numerical/graph correctness is validated separately in the PR.

Artifacts: ~/bench/m3_null_model_20261031/verified.json, manifest.json, four arm request/event logs, launch scripts and verify_model.py. Verification command: python3 ~/bench/m3_null_model_20261031/verify_model.py.

@xytpai

xytpai commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

CI audit (2026-11-01): MI35X shard4 reports a 90-minute Tests-step timeout and step-summary size >1024k. Downloaded its complete artifact: 420324 lines, no FAILED, AssertionError or Traceback match. Its tail is in test_gemm_a8w8_blockscale_aq_rowmajor.py / module_gemm_a8w8_blockscale_cktile_tune. This identifies where logging stopped, not a proven root cause or a claim that all tests passed.

Requesting one failed-job rerun of run 41215558861. No source, timeout, tolerance or unrelated test changes are made to bypass the gate. Other first-attempt results and timeout artifacts remain available.

XiaobingSuper added a commit that referenced this pull request Nov 2, 2026
…nds (#7248)

Squash of #7248 at 0af25c0, by @xytpai.

Conflict: aiter/ops/flydsl/kernels/tensor_shim.py. main (#7219) adds current_stream_arg above ptr_arg; #7248 lets ptr_arg take None. Kept both.
XiaobingSuper added a commit that referenced this pull request Nov 2, 2026
…nds (#7248)

Squash of #7248 at 0af25c0, by @xytpai.

Conflict: aiter/ops/flydsl/kernels/tensor_shim.py. main (#7219) adds current_stream_arg above ptr_arg; #7248 lets ptr_arg take None. Kept both.
lirui927 pushed a commit that referenced this pull request Nov 10, 2026
…nds (#7248)

Squash of #7248 at 0af25c0, by @xytpai.

Conflict: aiter/ops/flydsl/kernels/tensor_shim.py. main (#7219) adds current_stream_arg above ptr_arg; #7248 lets ptr_arg take None. Kept both.
(cherry picked from commit 9963579)
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 17, 2026
@zufayu
zufayu requested review from XiaobingSuper and removed request for aoli26 November 27, 2026 08:32
@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Nov 28, 2026

This branch has not been deployed

No deployments
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.

3 participants