Skip to content

[fix] Clear rocprofiler env vars before spawning mp_tuner workers - #6860

Merged
yzhou103 merged 1 commit into
ROCm:mainfrom
mjkvaak-amd:fix/mp-tuner-rocprofiler-env
Oct 26, 2026
Merged

yzhou103 merged 1 commit into
ROCm:mainfrom
mjkvaak-amd:fix/mp-tuner-rocprofiler-env

Conversation

@mjkvaak-amd

Copy link
Copy Markdown
Contributor

Motivation

On the vLLM ROCm nightly images (torch 2.13.0+rocm10.0.0), every tuner that uses mp_tuner measures 0 µs for every kernel candidate. Each task prints Warning: try run 3 times, but still get 0!, the run still exits 0, and the tuned CSV gets an arbitrary kernel (the first candidate) with us = 0 and tflops = inf. Nothing marks the result as invalid, so a bad config can be committed by mistake.

Tuning gemm_a4w4_blockscale_tune.py for one shape list on MI355X: all 1404 candidates timed 0 µs.

Technical Details

When the parent process initializes the GPU runtime, rocprofiler-sdk sets ROCPROFILER_REGISTER_LIBRARY and HSA_TOOLS_ROCPROFILER_V1_TOOLS with setenv. mp_tuner's workers are spawned, so they inherit both. In a worker started with them set, the torch profiler records no GPU events, get_trace_perf finds no device rows ("no valida data after post process!") and run_perftest returns 0.

Minimal reproduction, independent of AITER's kernels:

import multiprocessing as mp
import torch

def job(_):
    from torch.profiler import ProfilerActivity, profile
    a = torch.randn(2048, 2048, device="cuda")
    with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA]) as p:
        a @ a
        torch.cuda.synchronize()
    return sum(str(e.device_type).endswith("CUDA") for e in p.events())

if __name__ == "__main__":
    torch.zeros(1, device="cuda")  # parent initializes the runtime
    with mp.get_context("spawn").Pool(1) as pool:
        print(pool.map(job, [0]))  # [0]; [2] without the line above

The fix unsets both variables right before each worker pool is created, both the initial pool and the one rebuilt after a crash, through a small _new_pool helper. It uses os.unsetenv, because the runtime sets them from C after Python took its snapshot, so os.environ doesn't contain them and os.environ.pop alone does nothing. The parent's own runtime is already initialized at that point and is not affected.

Test Plan

  • MI355X (gfx950), vllm/vllm-openai-rocm nightly df3bd094 (AITER 0.1.25, torch 2.13.0+rocm10.0.0).
  • gemm_a4w4_blockscale_tune.py on M = 1, N = 4608, K = 8192 with --mp 1, before and after the change. The change was applied to the image's mp_tuner.py; the hunks are the same as on main except for surrounding context.
  • Same shape tuned with the variables removed at interpreter start instead (a sitecustomize.py on PYTHONPATH), as a reference.
  • The reproduction above with and without the unset.
  • black and ruff 0.16.0 (as in pre-checks).

Test Result

Candidates timed 0 µs Selected kernel µs
Before all a4w4_blockscale_256x64x128x128_..._intrawave_v3 (first candidate) 0.0
After 0 f4gemm_bf16_per1x32Fp4_BpreShuffle_32x128 12.92
Reference (variables removed at startup) 0 f4gemm_bf16_per1x32Fp4_BpreShuffle_32x128 12.88

The reproduction prints [0] before and [2] with the variables unset. black and ruff pass.

Submission Checklist

When the parent process initializes the GPU runtime, rocprofiler-sdk sets
ROCPROFILER_REGISTER_LIBRARY and HSA_TOOLS_ROCPROFILER_V1_TOOLS with
setenv. The spawned tuning workers inherit them, and the torch profiler
in those workers then records no GPU kernels, so run_perftest returns 0
for every candidate and the tuner writes an arbitrary kernel with 0 us.
Seen with the ROCm 10 torch wheels in the vLLM ROCm nightly images.

Unset both (os.unsetenv, since os.environ does not see them) right before
each worker pool is created.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd
mjkvaak-amd requested a review from a team October 23, 2026 06:01
@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 6860 --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.

@yzhou103

Copy link
Copy Markdown
Contributor

I wasn’t able to reproduce the 0 µs behavior with the ROCm images available to me. However, the root-cause analysis is technically sound, and clearing the rocprofiler variables before both the initial pool creation and subsequent pool rebuilds is appropriately scoped.
The reported fixed result also closely matches the reference run where the variables were cleared at interpreter startup. The change is small and low risk, so I’m approving it.

I’ll add separate follow-up handling to treat us == 0 as a failed measurement and prevent it from being written to the tuning config.

@yzhou103
yzhou103 merged commit be0237f into ROCm:main Oct 26, 2026
56 checks passed
yzhou103 pushed a commit that referenced this pull request Nov 24, 2026
…uner spawns shape workers (#8121)

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 #6860 added to mp_tuner._new_pool before the spawn.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants