Skip to content

fix(sc): Fix Nsys profiling for vLLM async workers - #4604

Merged
terrykong merged 2 commits into
mainfrom
scsudhakaran/fix-vllm-nsys-profiling
Oct 14, 2026
Merged

terrykong merged 2 commits into
mainfrom
scsudhakaran/fix-vllm-nsys-profiling

Conversation

@scsudhakaran

@scsudhakaran scsudhakaran commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

The async vLLM worker inherited the sync start_gpu_profiling/stop_gpu_profiling. On an AsyncLLM, collective_rpc is a coroutine, so the inherited methods created it and dropped it without awaiting. cudaProfilerStart/Stop never reached the GPU workers and no .nsys-rep files were written.

This PR

  • Overrides both methods on VllmAsyncGenerationWorkerImpl and awaits collective_rpc, so every GPU worker starts and stops its capture.
  • The outer actor does not call cudaProfilerStart/Stop itself.
  • No nsys stop --session step or grace sleep is needed, because nsys finalizes each report when its capture ends at cudaProfilerStop.
  • The source change is one file, vllm_worker_async.py .
  • The PR also adds a unit test and a docs entry.

Pattern to use:
Set NRL_NSYS_WORKER_PATTERNS=vllm_async_generation_worker for the async engine. Do not use *vllm* or *generation_worker: they also match vllm_generation_worker, which sets ray_workers_use_nsight=True and replaces the inner workers' nsight config with vLLM's always-on one, so the step range is ignored.

Validation

TP=1 and TP=2 (async engine, 2 GPUs, Qwen3-0.6B, 2 GRPO steps, GB300, nsys 2026.2.1, NeMo-RL nightly container):

NRL_NSYS_WORKER_PATTERNS=vllm_async_generation_worker
NRL_NSYS_PROFILE_STEP_RANGE=1:2
NRL_NSYS_EXTRA_OPTIONS='{"t":"cuda-sw,nvtx"}'     # also run with the default cuda,nvtx: same report counts

uv run examples/run_grpo.py policy.model_name=Qwen/Qwen3-0.6B grpo.num_prompts_per_step=2 \
  grpo.num_generations_per_prompt=4 policy.train_global_batch_size=4 policy.train_micro_batch_size=1 \
  policy.generation.vllm_cfg.async_engine=true policy.generation.vllm_cfg.tensor_parallel_size=<1|2> \
  cluster.gpus_per_node=2 grpo.max_num_steps=2 checkpointing.enabled=false
$ ls -l /tmp/ray/session_latest/logs/nsight          # TP=1 (two single-GPU engines)
6.7 MB  vllm_async_generation_worker_1:2_169100.nsys-rep
6.7 MB  vllm_async_generation_worker_1:2_169123.nsys-rep

$ ls -l /tmp/ray/session_latest/logs/nsight          # TP=2 (one engine, two inner TP workers)
7.4 MB  vllm_async_generation_worker_1:2_189563.nsys-rep
7.2 MB  vllm_async_generation_worker_1:2_189577.nsys-rep

TP=4 (async engine, Nemotron 3.5 Lightning RLVR, 10 nodes, GB300, Megatron also profiled, 10 steps):

NRL_NSYS_WORKER_PATTERNS=megatron_policy_worker,vllm_async_generation_worker
NRL_NSYS_PROFILE_STEP_RANGE=5:7
NRL_NSYS_EXTRA_OPTIONS='{"t":"cuda-sw,nvtx"}'

$ ls -l <nsight output dir>                          # TP=4 (one engine, four inner TP workers)
630 MB  vllm_async_generation_worker_5:7_2457710.nsys-rep
620 MB  vllm_async_generation_worker_5:7_2457729.nsys-rep
622 MB  vllm_async_generation_worker_5:7_2457756.nsys-rep
621 MB  vllm_async_generation_worker_5:7_2457775.nsys-rep

One report per GPU worker at every TP size, no reports from the outer actor at TP>1, no .qdstrm files, and all steps completed. nsys stats shows GPU kernels in all reports.

TP=1: the engine process still writes its report even though the outer actor no longer calls cudaProfilerStart, so torch.cuda.profiler.start()/stop() do not need to be restored.

Tests and docs

  • Unit test test_async_vllm_worker_gpu_profiling_awaits_collective_rpc: fails on the base commit with TypeError: object NoneType can't be used in 'await' expression and passes with this change.
  • docs/nsys-profiling.md: adds the async worker to Supported Workers, the *vllm* warning, and the vllm_async_generation_worker_<range>_<PID>.nsys-rep file name. The TP=1, TP=2 and TP=4 report listings are in this description.

@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@scsudhakaran
scsudhakaran force-pushed the scsudhakaran/fix-vllm-nsys-profiling branch from 144b7a2 to 5b3fa65 Compare October 8, 2026 19:36
@scsudhakaran
scsudhakaran requested a review from terrykong October 9, 2026 06:40
@scsudhakaran
scsudhakaran force-pushed the scsudhakaran/fix-vllm-nsys-profiling branch 2 times, most recently from 4f11ef6 to ed8488b Compare October 13, 2026 09:28

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix. The root cause is right: in vLLM 0.29, AsyncLLM.collective_rpc is async def, so the inherited sync call built a coroutine and then dropped it. Awaiting it is the fix. Ray dispatch, the stop at exit, and the data-parallel fan-out all check out.

Before merge

  • The PR description is out of date. Paragraph 2 describes an nsys stop --session step that is not in the diff. The commit message says it isn't needed, because nsys finalizes the report at cudaProfilerStop. Please replace that paragraph with the commit message text, including the TP=4 validation note.
  • Overlap with #4090. Open PR #4090 (zswerth) has the same vllm_worker_async.py change in 04069c28. Please agree on which PR carries it.

How this bug was missed

  • It came in with #865 (Aug 2025). No version of the code ever awaited the call.
  • Nothing failed. The only sign was a RuntimeWarning in the Ray actor's log; the profile file was just missing.
  • No test runs a worker's start/stop, and no CI job turns on nsys.
  • The docs' vLLM examples use the sync engine, but async GRPO needs the async engine, so every async-GRPO vLLM profile hit this.
  • Two later nsys PRs (#2156, #3130) worked in this area but did not touch vLLM async.
  • The test in the test comment would have caught it, and will catch it next time.
Evidence for each point above
  • Origin: #865 (2025-08-11) added the un-awaited collective_rpc to the one vLLM worker class that already ran AsyncLLM (async support came in #418). Three days later, #900 split the class and moved this code into the sync parent.
  • No error: an un-awaited coroutine only prints RuntimeWarning: coroutine ... was never awaited in the Ray actor's log. The driver's ray.get returns None either way. The inner workers ran under nsys, but capture never started, so there was no report and no error.
  • No test: test_nsys.py mocks the policy. No CI job sets NRL_NSYS_*. Neither vLLM worker file is listed in pyrefly.toml.
  • Docs use the sync engine: the vLLM examples use grpo_math_1B.yaml, which sets async_engine: false. Async GRPO requires the async engine (grpo.py#L4774).
  • Later PRs: #2156 added vLLM TP>1 profiling. #3130 added TRT-LLM async profiling and did it right, with separate *_async methods that await.

The *vllm* problem in the docs comment also affects sync TP>1 and is not this PR's job; we'll track it in a follow-up issue.

Generated by Claude Code

The async vLLM worker inherited the sync start/stop_gpu_profiling, which call
collective_rpc without awaiting it. The coroutine was dropped, so
cudaProfilerStart/Stop never reached the inner TP workers and no .nsys-rep
files were written.

Override both methods on VllmAsyncGenerationWorkerImpl and await
collective_rpc so every inner worker starts and stops its capture. The outer
actor does not trigger its own capture, so only the inner-worker reports are
written. Reports are finalized by nsys itself at cudaProfilerStop, so no
`nsys stop --session` step or grace sleep is needed.

Validated on an async engine with TP=4 and ray_workers_use_nsight=False,
using NRL_NSYS_EXTRA_OPTIONS='{"t":"cuda-sw,nvtx"}' and capture range 5:7:
one report per inner TP worker, no .qdstrm files, all steps complete.

Signed-off-by: Sanju C Sudhakaran <[email protected]>
@scsudhakaran
scsudhakaran force-pushed the scsudhakaran/fix-vllm-nsys-profiling branch from ed8488b to 10819ae Compare October 14, 2026 11:48
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 14, 2026
@scsudhakaran scsudhakaran added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 14, 2026
@scsudhakaran
scsudhakaran force-pushed the scsudhakaran/fix-vllm-nsys-profiling branch from 10819ae to da63aa0 Compare October 14, 2026 12:51
@scsudhakaran

Copy link
Copy Markdown
Contributor Author

/ok to test da63aa0

@terrykong
terrykong enabled auto-merge (squash) October 14, 2026 21:51
@terrykong
terrykong merged commit 4906c16 into main Oct 14, 2026
97 checks passed
@terrykong
terrykong deleted the scsudhakaran/fix-vllm-nsys-profiling branch October 14, 2026 21:51
zswerth added a commit to zswerth/RL that referenced this pull request Oct 31, 2026
- Restore the cuda-graph-trace=node default in the outer/policy nsight config
  (the key-set unit test passes unchanged); NRL_NSYS_EXTRA_OPTIONS now treats a
  JSON null as "remove this default" (review NVIDIA-NeMo#1, NVIDIA-NeMo#2).
- Remove the per-worker `nsys sessions list` / `nsys stop --session` sweep from
  VllmInternalWorkerExtension.stop_gpu_profiling and the 30 s post-stop sleep:
  the awaited cudaProfilerStop with capture-range-end=stop finalizes each inner
  report while the worker runs (review NVIDIA-NeMo#3, NVIDIA-NeMo#7, NVIDIA-NeMo#10).
- Build both inner TP-worker configs with one build_inner_nsight_config() in
  nemo_rl/utils/nsys.py (v1 keeps capture-range-end=repeat; the v2 plugin uses
  stop + wait=primary, documented), using the NRL_NSYS_PROFILE_STEP_RANGE
  constant and the validated NRL_NSYS_EXTRA_OPTIONS parser; the plugin imports
  the helper lazily and logs one line on install (review NVIDIA-NeMo#4, NVIDIA-NeMo#5).
- Import RayExecutorV2 directly in the plugin; drop the ImportError fallback so a
  moved executor fails loudly when profiling is requested (review NVIDIA-NeMo#11).
- Align the async start/stop_gpu_profiling with upstream NVIDIA-NeMo#4604 (already on main):
  await collective_rpc only, no outer cudaProfilerStart/Stop, so the outer async
  actor writes no near-empty report; adopt main's unit test verbatim (review NVIDIA-NeMo#8, NVIDIA-NeMo#9).
- Unit tests: plugin (entry point resolves, no-op, install once with one log line,
  call-through, overrides/null removal, fails loudly without RayExecutorV2, bad
  NRL_NSYS_EXTRA_OPTIONS raises at executor startup, vllm-marked contract test
  against the real RayExecutorV2), helper defaults/options, v1 call site, outer
  async profiler untouched; whitelist the plugin in pyrefly.toml (review NVIDIA-NeMo#6).
- Add an end-to-end nightly suite, grpo-llama3.2-1b-instruct-1n8g-megatron-nsys
  (Megatron recipe, vLLM TP=2, async engine): sets NRL_NSYS_*, passes a caller's
  NRL_NSYS_EXTRA_OPTIONS through, and asserts per-class report counts derived from
  the config (policy and inner vllm_tp_worker = engines x TP), no stock-config or
  unfinished captures, and CUDA activity in an inner report. The nightly GPU-hour
  cap is raised by this suite's budget (review NVIDIA-NeMo#12).
- Docs: null removal, the v2 plugin and when it is (not) loaded, failure modes.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zswerth added a commit to zswerth/RL that referenced this pull request Oct 31, 2026
Bring the fix branch up to date with main.

Conflict resolutions:
- tests/test_suites/nightly.txt: keep main's new vLLM block and the nsys
  end-to-end suite entry.
- tests/unit/test_recipes_and_test_suites.py: nightly GPU-hour cap = main's
  5203 + the nsys suite's 6 GPU-hours = 5209.
- tests/unit/models/generation/test_vllm_generation.py: keep the tests from
  both sides.

nemo_rl/models/generation/vllm/vllm_worker_async.py merges cleanly: the fix
commit already uses NVIDIA-NeMo#4604's start/stop_gpu_profiling as is.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zswerth added a commit to zswerth/RL that referenced this pull request Oct 31, 2026
nsys samples GPU hardware metrics with --gpu-metrics-devices, but each GPU
can be sampled by only one nsys process: a second process asking for the
same GPU records no metrics, without an error. Profiled workers see every
GPU of their node, so a single value in NRL_NSYS_EXTRA_OPTIONS ("all" or a
GPU id) makes the workers of a node compete. With "all", some policy and
vLLM reports got the metrics of several GPUs, others none, and empty outer
vLLM workers took GPUs away from the workers running on them.

Add the value "worker": NRL_NSYS_EXTRA_OPTIONS='{"gpu-metrics-devices":
"worker"}' gives each profiled process the metrics of the GPU it runs on.
The GPU is the one Ray assigned to the worker's placement-group bundle,
read with the same short probe task get_reordered_bundle already uses
(new get_bundle_gpu_id), so it holds for any bundle-to-node layout.

- Policy workers and vLLM generation workers at TP=1: resolved in
  RayWorkerBuilder.create_worker. Workers without a GPU, such as the outer
  vLLM worker at TP>1, do not sample.
- vLLM internal TP workers: vLLM creates them with one shared runtime_env.
  build_executor_nsight_config (shared by the v1 executor patch and the v2
  plugin) marks the config, and a wrapper around the executor module's
  `ray` gives each actor creation a copy for the GPU of its bundle. When
  only the outer async vLLM worker is profiled, the inner workers inherit
  its config through vLLM's ray_runtime_env; the v2 plugin gives them the
  per-worker value as well.
- Colocated generation: vLLM leaves the shared GPUs to the policy workers
  (one sampler per GPU), whose reports cover the generation phase too.

The value is consumed only where it can be resolved, so nsys never sees
"worker". Other values and every other NRL_NSYS_EXTRA_OPTIONS key reach
policy, vLLM generation and vLLM internal TP workers unchanged.

Docs: new "GPU Metrics for Every Profiled Worker" section; examples use
the current flag name gpu-metrics-devices (gpu-metrics-device is
deprecated in nsys but still accepted). The async-engine note from NVIDIA-NeMo#4604
("match vllm_async_generation_worker exactly, do not use *vllm*") is
updated: with the nemo_rl_nsight_inner plugin both pattern styles profile
every internal TP worker with deferred capture; the note now says which
report names each style gives.

Tests: option handling, the bundle probe (GPU test, excluded from the
fast unit list like its >1 s neighbours), the RayWorkerBuilder wiring,
the vLLM opt-out on shared GPUs, the v1/v2 per-worker hook (including the
inherited config) and a vllm-marked check that both vLLM Ray executors
still create their workers through the module's `ray`. The v1 call-site
test stub gains the parallel_config the patch now reads. The nsys e2e
suite budget drops from 45 to 30 minutes (a full run measured about 13),
so the nightly GPU-hour gate moves from 5209 to 5207.

Signed-off-by: zswerth <[email protected]>
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

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants