Repository navigation
fix(sc): Fix Nsys profiling for vLLM async workers - #4604
Merged
Merged
Conversation
scsudhakaran
force-pushed
the
scsudhakaran/fix-vllm-nsys-profiling
branch
from
October 8, 2026 19:36
144b7a2 to
5b3fa65
Compare
scsudhakaran
force-pushed
the
scsudhakaran/fix-vllm-nsys-profiling
branch
2 times, most recently
from
October 13, 2026 09:28
4f11ef6 to
ed8488b
Compare
terrykong
reviewed
Oct 14, 2026
terrykong
left a comment
Collaborator
There was a problem hiding this comment.
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 --sessionstep that is not in the diff. The commit message says it isn't needed, because nsys finalizes the report atcudaProfilerStop. 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.pychange 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
RuntimeWarningin 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_rpcto the one vLLM worker class that already ranAsyncLLM(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 awaitedin the Ray actor's log. The driver'sray.getreturnsNoneeither 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
*_asyncmethods 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
force-pushed
the
scsudhakaran/fix-vllm-nsys-profiling
branch
from
October 14, 2026 11:48
ed8488b to
10819ae
Compare
Signed-off-by: Sanju C Sudhakaran <[email protected]>
scsudhakaran
force-pushed
the
scsudhakaran/fix-vllm-nsys-profiling
branch
from
October 14, 2026 12:51
10819ae to
da63aa0
Compare
Contributor
Author
|
/ok to test da63aa0 |
terrykong
enabled auto-merge (squash)
October 14, 2026 21:51
terrykong
approved these changes
Oct 14, 2026
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]>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The async vLLM worker inherited the sync
start_gpu_profiling/stop_gpu_profiling. On anAsyncLLM,collective_rpcis a coroutine, so the inherited methods created it and dropped it without awaiting.cudaProfilerStart/Stopnever reached the GPU workers and no.nsys-repfiles were written.This PR
VllmAsyncGenerationWorkerImpland awaitscollective_rpc, so every GPU worker starts and stops its capture.cudaProfilerStart/Stopitself.nsys stop --sessionstep or grace sleep is needed, because nsys finalizes each report when its capture ends atcudaProfilerStop.vllm_worker_async.py.Pattern to use:
Set
NRL_NSYS_WORKER_PATTERNS=vllm_async_generation_workerfor the async engine. Do not use*vllm*or*generation_worker: they also matchvllm_generation_worker, which setsray_workers_use_nsight=Trueand 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):
TP=4 (async engine, Nemotron 3.5 Lightning RLVR, 10 nodes, GB300, Megatron also profiled, 10 steps):
One report per GPU worker at every TP size, no reports from the outer actor at TP>1, no
.qdstrmfiles, and all steps completed.nsys statsshows GPU kernels in all reports.TP=1: the engine process still writes its report even though the outer actor no longer calls
cudaProfilerStart, sotorch.cuda.profiler.start()/stop()do not need to be restored.Tests and docs
test_async_vllm_worker_gpu_profiling_awaits_collective_rpc: fails on the base commit withTypeError: object NoneType can't be used in 'await' expressionand passes with this change.docs/nsys-profiling.md: adds the async worker to Supported Workers, the*vllm*warning, and thevllm_async_generation_worker_<range>_<PID>.nsys-repfile name. The TP=1, TP=2 and TP=4 report listings are in this description.