Skip to content

fix: capture inner vLLM TP-worker nsys traces for ALL ranks - #4090

Open
zswerth wants to merge 24 commits into
NVIDIA-NeMo:mainfrom
zswerth:fix_multirank_generation_profiling
Open

zswerth wants to merge 24 commits into
NVIDIA-NeMo:mainfrom
zswerth:fix_multirank_generation_profiling

Conversation

@zswerth

@zswerth zswerth commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Problem. nsys generation profiling does not work at vLLM tensor parallel > 1, and nsys GPU metrics collide between workers.

  • With the async engine, vLLM builds its Ray executor (RayExecutorV2) inside EngineCore, a separate process. NeMo RL's in-process patch of the inner-worker nsight config cannot reach it, so with a pattern such as *policy*,*vllm* the inner TP workers keep vLLM's stock always-on nsight config and write no usable report.
  • With the sync engine, the in-process patch installs a fixed config that ignores NRL_NSYS_EXTRA_OPTIONS. It cannot be adjusted where the hardware CUDA trace is unreliable, and it cannot take GPU metrics.
  • nsys lets only one process sample a GPU's metrics; a second process asking for the same GPU records nothing, without an error. Profiled workers see every GPU of their node, so the documented "gpu-metrics-devices": "all" makes them compete: some reports get the metrics of several GPUs, others none.

Change.

  • A vllm.general_plugins entry point, nemo_rl = "nemo_rl.utils.vllm_plugin:register", one NeMo RL plugin for current and future vLLM patches. vLLM calls register() in every process it starts, including EngineCore; when profiling is requested it installs NeMo RL's deferred-capture config on RayExecutorV2 (nemo_rl/utils/vllm_nsight_plugin.py: capture-range=cudaProfilerApi, capture-range-end=stop, wait=primary). The sync engine gets the same config from vLLM's own plugin load in its process; the old in-process patch is replaced by a startup check. Every inner TP worker writes a complete vllm_tp_worker_<range>_<pid>.nsys-rep, for both engines and with any pattern. No vLLM change.
  • Behavior change versus main: when the inner TP workers are profiled and the entry point is not installed in the vLLM environment (for example a prebuilt container with newer NeMo RL source mounted over it, or old venvs/), or it fails to import (vLLM's own loader only logs that), or VLLM_PLUGINS excludes it, engine startup fails with a message that says how to fix it. On main, the sync engine was patched in-process and the async engine silently wrote vLLM's default worker_process_<PID> reports instead. Rebuild such environments once with NRL_FORCE_REBUILD_VENVS=true. Setting policy.generation.vllm_kwargs.ray_workers_use_nsight is now rejected: NeMo RL sets it from NRL_NSYS_WORKER_PATTERNS, and true without profiling would run every inner worker under vLLM's always-on nsys.
  • NRL_NSYS_EXTRA_OPTIONS now also reaches the inner TP workers, and a null value removes a default (for example {"cuda-graph-trace": null}). Defaults are unchanged.
  • NRL_NSYS_EXTRA_OPTIONS='{"gpu-metrics-devices": "worker"}' gives every profiled process the GPU metrics of exactly the GPU it runs on: policy workers, vLLM generation workers at TP=1, and each vLLM inner TP worker. The GPU is the one Ray assigned to the worker's placement-group bundle (new get_bundle_gpu_id). Exactly one worker group samples each GPU: the shared RayVirtualCluster gives the GPU metrics to the first training group that claims them (claim_gpu_metrics), and colocated vLLM and TRT-LLM generation leave the shared GPUs to it. So two training groups on the same GPUs (distillation's teacher and student, PPO's policy and critic) no longer compete; a startup log line names the group whose reports hold the metrics. No new environment variable.
  • A nightly end-to-end suite, tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh (async engine, vLLM TP=2). It checks the reports themselves: per-class counts derived from the config, no worker_process_* report (vLLM's stock config), no unfinished .qdstrm, and CUDA activity in an inner report.
  • docs/nsys-profiling.md: which report files to use at each TP, what to do when engine startup reports the plugin missing (rebuild once, or add nemo_rl to VLLM_PLUGINS), null removal, and a new "GPU Metrics for Every Profiled Worker" section.
export NRL_NSYS_WORKER_PATTERNS="*policy*,*vllm*"
export NRL_NSYS_PROFILE_STEP_RANGE="2:4"
export NRL_NSYS_EXTRA_OPTIONS='{"gpu-metrics-devices": "worker"}'  # optional

Inner reports are written right after the profile window ends, while the workers keep running, so run a few steps past the window.

Files
File Change
nemo_rl/utils/vllm_plugin.py, nemo_rl/utils/vllm_nsight_plugin.py (new), pyproject.toml The nemo_rl entry point and its register(); the nsight installer it calls. The installer imports RayExecutorV2 directly, so if a vLLM upgrade moves it, a profiled run fails at engine startup instead of silently writing no inner reports. It also gives each inner worker its own GPU-metrics device, reading vLLM's VLLM_RAY_PER_WORKER_GPUS.
nemo_rl/models/generation/vllm/vllm_worker.py, vllm_generation.py, trtllm/trtllm_generation.py, patches.py A startup check that the nemo_rl entry point is installed, not excluded by VLLM_PLUGINS, and imports, when the inner TP workers are profiled; the vllm_kwargs.ray_workers_use_nsight rejection; vLLM and TRT-LLM generation leave shared GPUs' metrics to training; a note on the other RayExecutorV2 patch.
nemo_rl/utils/nsys.py build_inner_nsight_config(), apply_nsys_extra_options() (inner workers, null removal), the "worker" GPU-metrics value.
nemo_rl/distributed/worker_groups.py, worker_group_utils.py, virtual_cluster.py RayVirtualCluster.claim_gpu_metrics (one sampling group per cluster); RayWorkerGroup claims once and passes sample_gpu_metrics to each worker, and recreate_worker replays it; get_bundle_gpu_id. Outer and policy nsight defaults are unchanged.
docs/nsys-profiling.md As above.
tests/unit/... Plugin tests (entry point resolves, no-op when profiling is off, install once, overrides and null, fails loudly without RayExecutorV2, vllm-marked contract tests against the real executor), startup-check tests (missing, excluded, fails to import, duplicate names), the vllm_kwargs rejection, GPU-metrics claim, wiring, replay and bundle-probe tests.
tests/test_suites/..., nightly.txt, tests/unit/test_recipes_and_test_suites.py The nightly suite, its recipe, and the nightly GPU-hour cap (see below).

Issues

None.

Convergence / perf / functionality proof

N/A for convergence and speed: profiling is opt-in. Without NRL_NSYS_WORKER_PATTERNS nothing changes, and the nsight defaults are unchanged. Functionality proof:

Runs on this branch's head (after merging main at a3c461f, vLLM 0.33.0; rechecked after each later merge of main), on 4-GPU nodes, with the branch's source mounted in the matching nightly image and NeMo RL reinstalled in the vLLM worker environments so the entry point registers (the image predates it). Environment: NRL_NSYS_WORKER_PATTERNS="*policy*,*vllm*", NRL_NSYS_PROFILE_STEP_RANGE="1:3", NRL_NSYS_EXTRA_OPTIONS='{"t": "cuda-sw,nvtx", "cuda-graph-trace": null}'.

Case Engine, vLLM TP Vehicle Steps vllm_tp_worker (inner) megatron_policy_worker Outer generation reports
A async, TP=2 (colocated) grpo-qwen3-32b-4n4g performance recipe, 4 nodes 12/12 16 (8 engines × TP=2) 16 none
B async, TP=1 (non-colocated) grpo-llama3.1-8b-instruct-2n4g-async-1off, 2 nodes 6/6 none (no inner workers) 4 4
C sync, TP=2 (colocated) grpo-qwen3-32b-4n4g, 4 nodes 12/12 16 16 16 near-empty (pre-existing, see below)
D sync, TP=1 (colocated) grpo-llama3.1-8b-instruct-2n4g, 2 nodes 6/6 none (no inner workers) 8 8
E the new suite (public 1.5B model, 1 node × 4 GPUs) async, TP=2 20/20 4 4 none; the suite's own report check passed

A and C add ++policy.generation.vllm_cfg.async_engine=true|false grpo.max_num_steps=12 grpo.num_prompts_per_step=4 grpo.num_generations_per_prompt=4 policy.train_global_batch_size=16 policy.max_total_sequence_length=2048; B and D add grpo.max_num_steps=6 (D also ++policy.generation.vllm_cfg.async_engine=false).

  • All reports export cleanly (nsys export --type=sqlite). No worker_process_* report, no unfinished .qdstrm, no crashes. Each inner worker's effective nsight options, read from Ray's runtime_env logs, are the deferred-capture config plus the NRL_NSYS_EXTRA_OPTIONS values, for both engines.
  • Per-worker GPU metrics on vLLM 0.33.0 with {"gpu-metrics-devices": "worker"}, checked per report (the GPU in its metrics vs the GPU its kernels ran on): async TP=2 non-colocated (grpo-llama3.1-8b-instruct-2n4g-async-1off + TP=2, 2 nodes, 10/10 steps): every policy and every inner report samples exactly its own GPU; sync TP=2 colocated (case C): every policy report samples its own GPU and the vLLM reports have none.
  • The startup check agrees with vLLM's own plugin loader in each vLLM worker environment: entry point missing, excluded by VLLM_PLUGINS, VLLM_PLUGINS unset, and VLLM_PLUGINS naming it; with an installed entry point that names a moved module, the check fails at startup while vLLM's loader only logs Failed to load plugin nemo_rl. In the sync TP=2 run, the inner config came only from vLLM's plugin load.
  • Unit tests in the matching image: the 89 nsys, nsight and GPU-metrics tests; test_worker_groups.py (42); test_recreate_worker.py (9); test_virtual_cluster.py with CUDA_VISIBLE_DEVICES=0,1 as in CI (81); the TRT-LLM flag test; the vllm-marked plugin contract tests inside both vLLM worker environments; the recipe and suite checks (16, including the nightly budget). Also uv lock --check, pyrefly with CI's command and baseline (0 errors) and ruff.
  • The new suite with the default options (NRL_NSYS_EXTRA_OPTIONS unset: hardware CUDA trace, cuda-graph-trace=node), on a 4-GPU node with a public model of the same size: 20/20 steps, 4 policy + 4 inner reports, [INFO] nsys report check passed, twice. Its inner reports hold about 10x more kernel records than with the fallback options, because cuda-graph-trace=node expands each CUDA-graph replay, so the default options were really in effect.
  • Outer generation reports: with the async engine the outer actor never opens a capture (fix(sc): Fix Nsys profiling for vLLM async workers #4604), so it writes no report. With the sync engine at TP>1, the existing BaseVllmGenerationWorker.start_gpu_profiling still calls cudaProfilerStart in the outer actor, which writes near-empty vllm_generation_worker_* files (one CUDA API call, no kernels). This PR doesn't change that; the meaningful generation profiles are the inner ones.

Nightly budget (maintainer decision): nightly.txt is at its GPU-hour cap, so this PR raises test_nightly_compute_stays_below_*_hours by the new suite's cost, 4 GPU-hours per night (1 node × 8 GPUs × 30 min; our full run, case E, took about 13 min): 5784 → 5788. Happy to shorten the suite or move it to another list instead.

Earlier validation (before this merge): GPU metrics per case, before/after on main, removed teardown workarounds

Per-worker GPU metrics, vLLM 0.29.0, 4-GPU nodes, {"gpu-metrics-devices": "worker", "cuda-memory-usage": "true"}. Every report was exported and the GPU in its GPU-metrics data compared with the GPU its kernels ran on.

Case Engine, vLLM TP Vehicle Steps Inner Policy GPU metrics
A async, TP=2 (colocated) grpo-qwen3-32b-4n4g, 4 nodes 12/12 16 16 policy: own GPU each; vLLM: none (shared GPUs)
A2 async, TP=2 (non-colocated) grpo-llama3.1-8b-instruct-2n4g-async-1off + TP=2, 2 nodes 10/10 4 4 policy and every inner worker: own GPU each
B async, TP=1 (non-colocated) grpo-llama3.1-8b-instruct-2n4g-async-1off, 2 nodes 6/6 none 4 policy and vLLM: own GPU each
C sync, TP=2 (colocated) grpo-qwen3-32b-4n4g, 4 nodes 12/12 16 16 policy: own GPU each; vLLM: none
D sync, TP=1 (colocated) grpo-llama3.1-8b-instruct-2n4g, 2 nodes 6/6 none 8 policy: own GPU each; vLLM: none
  • One sampler per GPU on every node, no missing ranks; the same with the pattern that matches only vllm_async_generation_worker (inner workers inherit the outer worker's config). cuda-memory-usage is recorded in policy, vLLM generation and vLLM TP-worker reports.
  • With "all" instead of "worker", half of the policy and inner reports got the metrics of two GPUs each and the other half none (non-colocated, TP=2); in a colocated run most policy reports got none while several outer vLLM workers, which run no GPU work, took the metrics.
  • Before this PR, on an earlier main with vLLM 0.29.0 and the same 4-node TP=2 vehicles: *policy*,*vllm* gave 0 inner reports with the async engine and 0 with the sync engine; matching exactly vllm_async_generation_worker gave 16 (inherited config, named vllm_async_generation_worker_*).
  • An earlier version of this branch stopped stale nsys sessions at teardown and slept 30 s after the stop. Runs with both on, with both off, and with only the sleep off wrote every inner report with identical content and timing, so both were removed. The awaited cudaProfilerStop ends each inner capture range, and with capture-range-end=stop nsys writes the report while the worker is still running.

Needs upstream changes

None. The plugin works with stock vLLM 0.33.0 through the vllm.general_plugins entry point, and the async await fix it relies on (#4604) is already on main.

Follow-ups, out of scope: skip the outer cudaProfilerStart for the sync engine at TP>1 (the near-empty outer reports in case C), as #4604 did for the async engine; the pre-existing vllm_generation_worker vs vllm_async_generation_worker name check in vllm_worker.py; non-colocated distillation builds its separate generation cluster with max_colocated_worker_groups=3, so vLLM there samples no GPU metrics (unchanged by this PR). Coordination: #3517 also changes when ray_workers_use_nsight is set; only one of the two PRs should change that logic.

PR commands and CI
  • CI label, exactly one:
    • CI:Lfast: the default for most PRs. Runs a fast test subset.
    • CI:L1: dependency or container changes (pyproject.toml, uv.lock, Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.
    • CI:docs: docs-only changes. Runs doc tests only.
  • /ok to test <full-commit-sha>: start CI for that commit. Post again after each push.
  • /nightly-ci test-case=<test>: run NVIDIA's nightly CI for the PR head; eligible teams only.
  • /review: automated review comments. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

🤖 Generated with Claude Code

@zswerth
zswerth requested review from a team as code owners September 10, 2026 22:03
@copy-pr-bot

copy-pr-bot Bot commented Sep 10, 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.

@zswerth
zswerth force-pushed the fix_multirank_generation_profiling branch from eec9ed2 to c899af6 Compare September 10, 2026 22:09
Multi-rank generation (inner vLLM tensor-parallel worker) nsys profiling
previously produced NO usable traces: at teardown the inner workers are
SIGKILLed, so nsys never writes the stream footer and the .qdstrm is an
incomplete, unconvertible capture. On the async engine the inner workers
never even received cudaProfilerStart. On some platforms the default
cuda-graph-trace=node HW-CUPTI path also SIGSEGVs at cudaProfilerStart.

Four minimal changes:

- distributed/worker_group_utils.py: drop cuda-graph-trace=node from the
  policy/outer nsight config (fragile CUPTI; user can re-add via
  NRL_NSYS_EXTRA_OPTIONS).

- models/generation/vllm/vllm_worker.py (_patch_vllm_nsight_config): honor
  NRL_NSYS_EXTRA_OPTIONS so the trace target is overridable (e.g. cuda-sw),
  drop cuda-graph-trace, and also patch the v2 Ray executor
  (RayExecutorV2._build_runtime_env) -- the previous patch only rebound the v1
  executor, which is inert now that v2 is the default.

- models/generation/vllm/vllm_worker_async.py: override start/stop_gpu_profiling
  as async and AWAIT collective_rpc, so cudaProfilerStart/Stop actually reach
  every inner worker on the async engine (the inherited sync methods dropped the
  coroutine un-awaited); plus a short grace after stop so nsys can finalize.

- models/generation/vllm/vllm_backend.py (VllmInternalWorkerExtension.stop_gpu_profiling):
  after cudaProfilerStop, finalize each inner worker's live nsys capture
  NON-DESTRUCTIVELY via `nsys stop --session`. This writes a complete .nsys-rep
  without killing the process, so no worker death and no engine fault-tolerance
  cascade -- every rank finalizes (vs at most one before). Runs on all inner
  workers via the existing collective_rpc("stop_gpu_profiling") broadcast.

A companion vLLM change (vllm/v1/executor/ray_executor_v2.py _build_runtime_env
deferred-capture nsight config) is required for the v2 EngineCore subprocess,
which imports vLLM pristine and does not see the NeMo-RL monkey-patch; that will
be filed as a separate vllm-project/vllm PR.

Signed-off-by: zswerth <[email protected]>
@zswerth
zswerth force-pushed the fix_multirank_generation_profiling branch from c899af6 to 04069c2 Compare September 10, 2026 22:14
Makes multi-rank generation profiling self-contained in NeMo-RL: no vLLM
source change and nothing to bind-mount into the container.

The v2 RayExecutorV2 (default on vLLM >= 0.25) builds the inner TP-worker
runtime_env inside the vLLM EngineCore subprocess, which is started with
`spawn` and re-imports vLLM pristine -- so an in-process monkey-patch in
vllm_worker.py cannot reach it (it only ever rebinds the class in the outer
actor process). The prior commit's in-process RayExecutorV2._build_runtime_env
wrap was therefore inert on the real v2 path; the working v2 path relied on an
out-of-tree source patch to vllm/v1/executor/ray_executor_v2.py.

Instead, register a `vllm.general_plugins` entry point. vLLM calls
load_general_plugins() early in EVERY process it starts -- including the
EngineCore subprocess -- so the plugin monkey-patches
RayExecutorV2._build_runtime_env where it actually takes effect, installing the
same deferred-capture nsight config used for the outer/policy workers
(capture-range=cudaProfilerApi, gated by NRL_NSYS_PROFILE_STEP_RANGE, honoring
NRL_NSYS_EXTRA_OPTIONS for the trace target). Finalization is unchanged: the
awaited async start/stop_gpu_profiling reach every inner worker and
VllmInternalWorkerExtension.stop_gpu_profiling finalizes each trace via
`nsys stop --session`.

- nemo_rl/utils/vllm_nsight_plugin.py: the plugin (no-op unless
  NRL_NSYS_WORKER_PATTERNS is set; no-ops on vLLM without the v2 executor).
- pyproject.toml: register it under [project.entry-points."vllm.general_plugins"].
- vllm_worker.py: drop the inert in-process v2 wrap (the v1 executor patch,
  reachable in-process, is kept).

Validated on the fast qwen3-32b TP=2 vehicle (stock vLLM 0.25.1, no source
mount, v2 wrap removed): inner vllm_tp_worker traces flush for all ranks
(8 engines x TP2 = 16), 0 segfaults; inner files are named
vllm_tp_worker_<range>_%p (the plugin's template) not stock worker_process_%p,
proving the plugin ran inside the EngineCore subprocess. Non-regressive at
TP=1 (sync and async): gen + policy traces unchanged, plugin is a no-op there.

Signed-off-by: zswerth <[email protected]>
@zswerth
zswerth requested a review from a team as a code owner September 11, 2026 05:21

@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.

This PR makes nsys profiling produce a trace for every inner vLLM TP worker instead of dropping all but one rank at teardown. Both fixes hold up.

The awaited collective_rpc is right: AsyncLLM.collective_rpc is async def, and the inherited sync method called it bare, so the RPC was never driven to completion on the async engine.

Moving the v2 inner-worker config to a vllm.general_plugins entry point in the second commit is also the right call. An in-process monkey-patch cannot reach the spawned EngineCore process, which is where RayExecutorV2 builds the inner-worker runtime_env; the entry point runs in every process vLLM starts. The commit message backs this up with the filenames themselves — vllm_tp_worker_<range>_%p instead of stock worker_process_%p.

One caveat up front, since it applies to everything below: nobody on this review ran any of this on a GPU, and nobody had an nsys binary. Every claim comes from reading the source, the pinned dependency source, or NVIDIA's Nsight Systems docs — with one exception, the broken unit test, which was actually executed.

There is exactly one blocking item: deleting cuda-graph-trace from the outer defaults breaks a unit test that asserts the exact key set, and that test runs in both CI:Lfast and CI:L0. Everything else is a suggestion or a question — the session-sweep scope, the three drifting copies of the nsight config, the skipped JSON validation, missing tests for the new plugin, the 30s sleep, and a few description details that don't match the code at TP>1.

Generated by Claude Code

Comment thread nemo_rl/utils/vllm_nsight_plugin.py Resolved
Comment thread nemo_rl/utils/vllm_nsight_plugin.py Resolved
Comment thread nemo_rl/utils/vllm_nsight_plugin.py Resolved
Comment thread nemo_rl/utils/vllm_nsight_plugin.py Resolved
Comment thread nemo_rl/utils/vllm_nsight_plugin.py Resolved
zswerth and others added 3 commits October 31, 2026 10:31
- 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]>
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]>
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]>
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 31, 2026
@zswerth

zswerth commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. I pushed an update; each inline comment has a reply in its thread.

I updated the description with a validation table for the final branch: async/sync engine × vLLM TP 1/2, plus the new suite, with GPU metrics checked per report. One note on the nightly: the new suite adds 4 GPU-hours to the nightly budget, which needs a maintainer's OK.

Could a maintainer run /ok to test 0b2d0204 so the full CI runs?

@zswerth

zswerth commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0b2d020

@zswerth zswerth added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 3, 2026
@zswerth

zswerth commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0b2d020

zswerth and others added 3 commits November 3, 2026 14:21
Bring the fix branch up to date with main. No conflicts.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
With main at 4080612 the nightly suite totals 5215 GPU-hours: main's 5211
plus 4 for grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh. The previous
merge kept main's cap of 5213, so the nightly compute test would fail.
Raise the cap by the suite's 4 GPU-hours, keeping main's headroom.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6e55e4d

@terrykong terrykong added CI:L1 Run doctests, unit tests, and functional tests and removed CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Nov 5, 2026
Bring the fix branch up to date with main. Two conflicts, both in tests:

- tests/unit/test_recipes_and_test_suites.py: nightly GPU-hour cap set
  to 5240, main's 5236 plus the 4 GPU hours of this PR's nsys suite
  (DRYRUN total on the merged tree: 5240).
- tests/unit/distributed/test_worker_groups.py: main and this branch
  each added a test at the end of the file; kept both.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2643872

get_bundle_gpu_id cast the GPU id to int, while get_reordered_bundle
returns ray.get_gpu_ids() unchanged. When CUDA_VISIBLE_DEVICES is set
before Ray starts, as in CI, Ray returns the ids as strings, so
test_get_bundle_gpu_id_matches_bundle_probe failed in the L1 run
({0: 0, 1: 1} != {0: '0', 1: '1'}). The test is excluded in Lfast mode
and had not run in CI before.

Return the id as Ray gives it. The only caller,
set_worker_gpu_metrics_device, already passes it through str(), so the
nsys flag value is unchanged. The cast would also fail on GPU UUIDs in
CUDA_VISIBLE_DEVICES.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c14d69a

Bring the fix branch up to date with main. No conflicts. The nightly
GPU-hour cap stays at 5240: main's cap is still 5236, plus the 4 GPU
hours of this PR's nsys suite.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 38592bd

Bring the fix branch up to date with main. No conflicts. The nightly
GPU-hour cap stays at 5726: main's cap is still 5722, plus the 4 GPU
hours of this PR's nsys suite.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6264d87

@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 quick turnaround: all 12 round-1 comments are fixed and resolved. The main merge is clean: both nsight patches in _patch_vllm_nsight_config (the v1 one and #5153's in-process RayExecutorV2 wrapper) are gone along with the v1 tests, the cap is right at 5726, and the vLLM 0.33 reruns (16 inner reports for both sync and async TP=2) are exactly the evidence this needed. The find fix in 41dd764 also covers a bug we had found.

Prior art. #2156 (snivertynv) did this and silently stopped working at the vLLM 0.25 bump (#3280). #4604 (scsudhakaran) covers async, with the exact pattern only. #5153's patch reached only the sync engine and used repeat without wait=primary. So the gap this PR fills is real, and the plugin is the right tool: it is the only way to reach the async EngineCore process and to give each inner worker its own GPU for metrics.

Round 2:

  1. (C13) Two places still say the outer vLLM worker isn't profiled at TP>1. It is; fix the wording.
  2. (C14) Four gaps in per-worker GPU metrics: two training groups on one GPU (distillation, PPO; fixed by letting the shared cluster pick one sampler), a docs note, reading vLLM's own setting, and making the plugin visible to the next vLLM bump. Each item spells out the change and its test.
  3. (C16) Get one run of the nightly suite as committed (8 GPUs, default hardware trace) before merge.
  4. (C17) Shorten the docs addition to what a user does, and drop the "NOT applied to the outer worker" claim.
  5. (C18, low) Reject ray_workers_use_nsight in vllm_kwargs: NeMo-RL sets it from the pattern, and true without profiling runs the inner workers under always-on nsys.
  6. (C19, low) Keep nsys helpers in nsys.py and cluster state on RayVirtualCluster, not in the worker-group utilities.

Coordination. Open #3517 (ZhiyuLi-Nvidia) removes the same flag on the premise that inner workers can't be profiled. This PR shows they can. Only one PR should change the flag logic in _create_engine.

No GPU on the review side, so nothing here was run on GPUs.

Generated by Claude Code

Comment thread nemo_rl/utils/vllm_nsight_plugin.py Resolved
Comment thread docs/nsys-profiling.md Resolved

@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.

Follow-up on plugin compatibility: other packages' vLLM plugins (for example, one that adds a model) may be installed next to this one.

  1. (C20) Name the entry point after NeMo RL and route it through one register() before merge.
  2. (C21) Load the plugin in the startup check, since vLLM only logs a plugin that fails to import.

The rest of the plugin already coexists with other plugins: it wraps _build_runtime_env and calls the original, it registers nothing, it is safe to run twice, and the startup check covers a VLLM_PLUGINS list that leaves it out. A separate PR will add a contributing guide for vLLM patches and plugins; it does not block this one.

nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=6264d87

Comment thread pyproject.toml Resolved
@tzachicohen

Copy link
Copy Markdown

Have you tried using : --trace-fork-before-exec=true to capture spawned worker processes ?

zswerth and others added 2 commits December 1, 2026 03:41
Bring the fix branch up to date with main. One conflict, in
tests/unit/test_recipes_and_test_suites.py: the nightly GPU-hour cap is
now 5746, main's 5742 (which includes main's new chunk128 suite) plus the
4 GPU hours of this PR's nsys suite. vllm_worker.py, nightly.txt and
test_vllm_generation.py changed on both sides and merged cleanly; main's
changes there do not touch the profiling code.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
C13: the configure_worker comment and the _load_model warning no longer
say the outer vLLM worker is unprofiled at TP>1; they say that
_load_model sets ray_workers_use_nsight and NeMo RL's vLLM plugin
configures the internal TP workers.

C14 AI-1 / C19: RayVirtualCluster.claim_gpu_metrics picks one worker
group per cluster to sample nsys GPU metrics ("gpu-metrics-devices":
"worker"); a group that yields shared GPUs (colocated generation) never
takes the claim, and a refused group is named in a startup log line.
RayWorkerGroup claims once (new nsys_gpu_metrics_on_shared_gpu flag,
False for VllmGeneration and TrtllmGeneration) and passes
sample_gpu_metrics to create_worker, which also requires num_gpus > 0.
The decision is stored in each worker's creation spec and replayed by
recreate_worker. samples_own_gpu_metrics and the vLLM worker class
attribute are removed; this covers distillation's teacher and student,
PPO's policy and critic, and every other pair of training groups on one
cluster.

C14 AI-2: two docs bullets on who samples GPU metrics with colocated
generation and with two training groups on the same GPUs.

C14 AI-3: _engine_owns_its_gpus reads VLLM_RAY_PER_WORKER_GPUS from
vllm.envs (function-local import, stubbed in the tests that run without
vLLM); a vllm-marked test checks vLLM's own parse.

C14 AI-4: a note above the other RayExecutorV2 patch in patches.py, and
the vllm-marked executor contract test also requires
self._build_runtime_env() in _init_executor and a non-None module ray.

C17: the docs paragraph after the TensorRT-LLM sentence and the async
note under Supported Workers now say only what a user does and which
reports to read.

C18: _load_model rejects generation.vllm_kwargs.ray_workers_use_nsight;
NeMo RL sets it from NRL_NSYS_WORKER_PATTERNS.

C20: the vllm.general_plugins entry point is now
nemo_rl = "nemo_rl.utils.vllm_plugin:register"; register() calls the
unchanged nsight installer. The startup check, its messages, the docs,
the tests and the nsys suite use the new name.

C21: the startup check loads the entry point (the last one of that name,
which is the one vLLM keeps) and raises an actionable RuntimeError if it
does not import, since vLLM only logs a plugin that fails to import.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a8f7168

Bring the fix branch up to date with main. The only conflict is the
nightly GPU-hour cap: main's cap is 5752 after its new PPO suite, and
this PR's nsys suite adds 4 GPU hours, so the cap is 5756.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ce71b6a

@zswerth

zswerth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@tzachicohen Thanks for the suggestion. --trace-fork-before-exec doesn't reach the processes this PR is about.

  • At vLLM TP>1 the internal TP workers are Ray actors. vLLM's Ray executor creates them with ray.remote(...), and Ray's node daemon (the raylet) starts their processes, sometimes on another node. They aren't children of the profiled outer worker, so no nsys option on that worker can follow them; each one needs its own nsys. Ray provides that through the actor's nsight runtime_env, which vLLM turns on with ray_workers_use_nsight. The plugin only replaces vLLM's always-on config with NeMo RL's (deferred capture over NRL_NSYS_PROFILE_STEP_RANGE, report names, NRL_NSYS_EXTRA_OPTIONS, per-worker GPU metrics). In our runs, the raylet log records the start of every process that wrote a vllm_tp_worker_* report.
  • Where a worker is a child process, nsys already follows it. At TP=1 the async engine spawns its EngineCore (fork + exec), and every GPU kernel in the outer worker's report comes from that EngineCore process, with the default options.

--trace-fork-before-exec=true only adds tracing between fork and exec, which the nsys docs warn can crash or deadlock the application. None of these processes does GPU work in that window.

# on, then counts the .nsys-rep reports per worker class. Exit code alone proves nothing:
# a run whose inner vLLM workers write no report still completes.
#
# NRL_NSYS_EXTRA_OPTIONS is passed through unchanged, so a platform can adjust nsys flags.

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.

C22 · 1 action item.
TL;DR — the committed suite has still never run as committed: your run used 4 GPUs per node and a different model, so the 1n8g setup the nightly job uses is unchecked.

Follow-up on C16.

Fixed: your run shows the default hardware CUDA trace (NRL_NSYS_EXTRA_OPTIONS unset) does not crash on your nodes, every report exports, and the check passes. Keeping the suite as committed, with the fallback in the docs, is fine.

Still open: that run set cluster.gpus_per_node=4 and swapped the model, so it is not the script the nightly job runs (this file). The 8 + 8 report count, Llama-3.2-1B, and the nightly hardware (where the hardware trace may behave differently from your 4-GPU nodes) are untested. Your two /nightly-ci requests for this test case still have no result posted.

AI-1

Before merge, paste the result of one /nightly-ci test-case=tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh run (or any run of the unmodified script on an 8-GPU node): the report table and the nsys report check passed line, after "Expecting 8 megatron_policy_worker and 8 vllm_tp_worker reports". If the hardware trace crashes there, have the suite export the cuda-sw fallback itself, with a one-line comment saying why. Not a suggestion block: this is a run, not an edit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@terrykong Agreed, that run isn't the committed setup. I can't produce one myself: the nightly bot declined my /nightly-ci requests because the PR author isn't in an eligible team (automation or rl_autobot_approvers), and our nodes have 4 GPUs, with no access to the gated Llama-3.2-1B.

Could you post this on the PR (head ce71b6a)?

/nightly-ci test-case=tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh

I'll paste the report table and the nsys report check passed line here once it reports. If the hardware trace crashes on that hardware, I'll make the suite export the cuda-sw fallback itself, with a one-line comment saying why, and push that.

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.

C23 · 1 action item (for me).
TL;DR — fair: you can't run it, so I'll trigger it; C22 stays open until the result is posted here.

I'll post /nightly-ci test-case=tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh on the new head 706ff50 (your merge of main only changed the GPU-hour cap, 5784 + 4 = 5788, so that head is the one to test). Once it reports, please paste the report table and the nsys report check passed line here, as you offered. If the hardware trace crashes there, the cuda-sw fallback you described is the right fix.

@zswerth

zswerth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/nightly-ci test-case=tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh

Bring the fix branch up to date with main. Two conflicts:
- tests/unit/models/generation/test_vllm_generation.py: this PR adds a
  test right above the worker-extension quantization test, which main
  parametrized; both are kept.
- The nightly GPU-hour cap: main's cap is 5784, and this PR's nsys suite
  adds 4 GPU hours, so the cap is 5788.

Signed-off-by: zswerth <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zswerth

zswerth commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 706ff50

@terrykong

Copy link
Copy Markdown
Collaborator

/resolve-conflict

@terrykong

Copy link
Copy Markdown
Collaborator

/nightly-ci test-case=tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

/ok to test c9d23ef

@terrykong

Copy link
Copy Markdown
Collaborator

Started an internal CI run of tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh on head c9d23ef (H100, unmodified script), in place of /nightly-ci. Pipeline ID: 87886495. I will post the result and the metric check here when it finishes.

@terrykong terrykong added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Dec 4, 2026
@terrykong

Copy link
Copy Markdown
Collaborator

/resolve-conflict

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

/ok to test 2cb2c10

@terrykong

Copy link
Copy Markdown
Collaborator

/resolve-conflict

@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 649a981

1 similar comment
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

/ok to test 649a981

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

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) complexity:high Large or cross-cutting change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:none Cannot change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants