Skip to content

[CK] [Tune][MoE] Clear inherited rocprofiler env before the MXFP4 FlyDSL tuner spawns shape workers - #8121

Merged
yzhou103 merged 3 commits into
ROCm:mainfrom
mjkvaak-amd:mtukiain/moe-tuner-rocprofiler-env
Nov 24, 2026
Merged

yzhou103 merged 3 commits into
ROCm:mainfrom
mjkvaak-amd:mtukiain/moe-tuner-rocprofiler-env

Conversation

@mjkvaak-amd

@mjkvaak-amd mjkvaak-amd commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

gemm_moe_tune.py --mxfp4-flydsl runs each shape in a fresh spawn process. Each child inherits the two rocprofiler-sdk variables that the parent's GPU initialisation sets, so torch.profiler in the child records no GPU kernels, and every candidate either fails or times as 0. This PR clears those variables before the spawn, reusing the helper #6860 added for mp_tuner's pool.

Motivation

rocprofiler-sdk calls setenv for ROCPROFILER_REGISTER_LIBRARY and HSA_TOOLS_ROCPROFILER_V1_TOOLS in whichever process initialises the GPU. #6860 found that mp_tuner workers which inherit these variables see an empty profiler trace, and cleared them in _new_pool.

Mxfp4FlydslTuner.tune does not use that pool. It calls _preflight_devices, which initialises the GPU in the parent, and then starts its own multiprocessing.get_context("spawn") pool, so #6860's fix never applies. Staged search is the default and always takes this path, even with --mp 1.

The symptom in the 0.1.29 image, tuning one Qwen3.8-Flash-Next TP2 shape (token=64, model_dim=2560, inter_dim=384, expert=513, topk=11, MXFP4 per_1x32):

  • Unpatched (two runs): every candidate's post-processing hits an empty DataFrame (host_time_sum). The tuner ends with [Tuning not Finished] some shapes are not tuned or all failed, and the output row is empty.
  • Patched: the row is tuned at 104.6 µs, using flydsl_mxmoe_g1_a4w4_16x128x256_f16in_nt_xcd2 and flydsl_moe2_layout_afp4_wfp4_bf16_t16x128x128_atomic_nt_sbm16. CUDA-graph replay of fused_moe with that row measures 103.8 µs, so the profiler time is real.

Falling back to CUDA-event timing is not a workaround. At small M it measures host launch time: every candidate at M=64 landed near 155 µs, so the pick was noise.

Not a duplicate: I searched the open AITER PRs for rocprofiler and tuner environment fixes. #6860 (merged) fixed mp_tuner._new_pool only.

Changes

  • aiter/utility/mp_tuner.py: move the loop out of _new_pool into a public clear_inherited_rocprofiler_env(). _new_pool calls it, so its behaviour is unchanged.
  • csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py: call the new function in Mxfp4FlydslTuner.tune right before the spawn context is created.

The variables are removed only from the tuner process, which runs no profiled work of its own after this point. No kernel or runtime path changes.

Performance (if applicable)

Not a kernel change, so there is no kernel speedup to report. The fix makes the existing tuner produce timings.

Hardware Workload/configuration Before After Change
MI355X, AITER 0.1.29 --mxfp4-flydsl, one shape (M=64, 2560/384/513/11) all candidates fail, no row row tuned, 104.6 µs (graph replay 103.8 µs) tuner works

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 documentation change is needed, with the reason stated below

There is no new flag or behaviour: the tuner now works as documented.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

9faae0e

Behavior and intent

The MXFP4 FlyDSL MoE tuner's shape workers no longer inherit the parent's rocprofiler-sdk registration. Before this PR, torch.profiler in those workers recorded no GPU kernels and every candidate failed.

Validation and unverified scope

Repro on one GPU, MI355X (gfx950), AITER 0.1.29 in vllm/vllm-openai-rocm:nightly-rocm100-8ca766326652caf4b8e50d1b9118d8a22f6adc73:

cat > s64.csv <<'EOF'
token,model_dim,inter_dim,expert,topk,act_type,dtype,q_dtype_a,q_dtype_w,q_type,use_g1u1,doweight_stage1
64,2560,384,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0
EOF
python3 csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py -i s64.csv -o s64_out.csv --mxfp4-flydsl

Before the fix, this prints "[Tuning not Finished] ... all failed" and the s64_out.csv row is empty. After it, the row is tuned at about 105 µs with the kernels named above.

Remaining and unverified:

  • Only the --mxfp4-flydsl path was exercised. I found no other spawn pools in gemm_moe_tune.py, but did not audit other tuner scripts.
  • MI250X and MI300X are not tested.
  • No unit test was added. The failure needs a real rocprofiler-sdk registration in the parent before a spawn, and a test that only checks the environment is cleared would pass for any implementation that calls the helper.
  • Separately, profiler post-processing occasionally under-counts a candidate (one rerun reported 25.8 µs for the same shape). That is not addressed here. Re-time winners before shipping rows.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

No kernel path changes, so no runtime dispatch is affected. The change only runs inside the offline tuner, gemm_moe_tune.py --mxfp4-flydsl (Mxfp4FlydslTuner.tune), for every architecture, dtype and shape that tuner accepts.

The new call removes two rocprofiler-sdk environment variables from the tuner's own process right before it creates the spawn context. This is the same thing mp_tuner._new_pool already does since #6860. Inference processes never import or call it, and the variables are only cleared in a process that runs no profiled work of its own after that point.

Changed op tests

None.

Co-authored-by: Cursor [email protected]

…uner spawns shape workers

Mxfp4FlydslTuner.tune initialises the GPU in the parent and then starts
its own spawn pool, so the shape workers inherit the rocprofiler-sdk
registration variables and torch.profiler records no GPU kernels. Reuse
the clearing that ROCm#6860 added to mp_tuner._new_pool before the spawn.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
@mjkvaak-amd
mjkvaak-amd requested a review from a team November 17, 2026 17:00
@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 8121 --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 [Tune][MoE] Clear inherited rocprofiler env before the MXFP4 FlyDSL tuner spawns shape workers [CK] [Tune][MoE] Clear inherited rocprofiler env before the MXFP4 FlyDSL tuner spawns shape workers Nov 17, 2026
@github-actions github-actions Bot added the CK label Nov 17, 2026
@aiter-bot

aiter-bot commented Nov 17, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision d6ddf0cfd76c · 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 architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  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

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

@yzhou103

Copy link
Copy Markdown
Contributor

@valar-cop review

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

ci green.

@yzhou103
yzhou103 merged commit bc1fd26 into ROCm:main Nov 24, 2026
62 checks passed
vedenev-amd added a commit that referenced this pull request Nov 24, 2026
…uner import conflict.

#7542 and #8121 import clear_inherited_rocprofiler_env from mp_tuner; this
branch imports gfx942_mxfp8_block_exponent from fp4_utils. Both imports are
kept.

Co-Authored-By: Claude Opus 5.5 <[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.

4 participants