Repository navigation
Conversation
eec9ed2 to
c899af6
Compare
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]>
c899af6 to
04069c2
Compare
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]>
terrykong
left a comment
There was a problem hiding this comment.
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
- 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]>
|
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 0b2d020 |
|
/ok to test 0b2d020 |
Signed-off-by: zswerth <[email protected]>
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]>
|
/ok to test 6e55e4d |
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]>
|
/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]>
|
/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]>
|
/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]>
|
/ok to test 6264d87 |
terrykong
left a comment
There was a problem hiding this comment.
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:
- (C13) Two places still say the outer vLLM worker isn't profiled at TP>1. It is; fix the wording.
- (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.
- (C16) Get one run of the nightly suite as committed (8 GPUs, default hardware trace) before merge.
- (C17) Shorten the docs addition to what a user does, and drop the "NOT applied to the outer worker" claim.
- (C18, low) Reject
ray_workers_use_nsightinvllm_kwargs: NeMo-RL sets it from the pattern, andtruewithout profiling runs the inner workers under always-on nsys. - (C19, low) Keep nsys helpers in
nsys.pyand cluster state onRayVirtualCluster, 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
terrykong
left a comment
There was a problem hiding this comment.
Follow-up on plugin compatibility: other packages' vLLM plugins (for example, one that adds a model) may be installed next to this one.
- (C20) Name the entry point after NeMo RL and route it through one
register()before merge. - (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
|
Have you tried using : --trace-fork-before-exec=true to capture spawned worker processes ? |
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]>
|
/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]>
|
/ok to test ce71b6a |
|
@tzachicohen Thanks for the suggestion.
|
| # 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
|
/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]>
|
/ok to test 706ff50 |
|
/resolve-conflict |
|
/nightly-ci test-case=tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron-nsys.sh |
Signed-off-by: svcnemo-autobot <[email protected]>
|
/ok to test c9d23ef |
|
Started an internal CI run of |
|
/resolve-conflict |
Signed-off-by: svcnemo-autobot <[email protected]>
|
/ok to test 2cb2c10 |
|
/resolve-conflict |
Signed-off-by: svcnemo-autobot <[email protected]>
|
/ok to test 649a981 |
1 similar comment
|
/ok to test 649a981 |
What and why
Problem. nsys generation profiling does not work at vLLM tensor parallel > 1, and nsys GPU metrics collide between workers.
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.NRL_NSYS_EXTRA_OPTIONS. It cannot be adjusted where the hardware CUDA trace is unreliable, and it cannot take GPU metrics."gpu-metrics-devices": "all"makes them compete: some reports get the metrics of several GPUs, others none.Change.
vllm.general_pluginsentry point,nemo_rl = "nemo_rl.utils.vllm_plugin:register", one NeMo RL plugin for current and future vLLM patches. vLLM callsregister()in every process it starts, including EngineCore; when profiling is requested it installs NeMo RL's deferred-capture config onRayExecutorV2(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 completevllm_tp_worker_<range>_<pid>.nsys-rep, for both engines and with any pattern. No vLLM change.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 oldvenvs/), or it fails to import (vLLM's own loader only logs that), orVLLM_PLUGINSexcludes it, engine startup fails with a message that says how to fix it. Onmain, the sync engine was patched in-process and the async engine silently wrote vLLM's defaultworker_process_<PID>reports instead. Rebuild such environments once withNRL_FORCE_REBUILD_VENVS=true. Settingpolicy.generation.vllm_kwargs.ray_workers_use_nsightis now rejected: NeMo RL sets it fromNRL_NSYS_WORKER_PATTERNS, andtruewithout profiling would run every inner worker under vLLM's always-on nsys.NRL_NSYS_EXTRA_OPTIONSnow also reaches the inner TP workers, and anullvalue 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 (newget_bundle_gpu_id). Exactly one worker group samples each GPU: the sharedRayVirtualClustergives 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.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, noworker_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 addnemo_rltoVLLM_PLUGINS),nullremoval, and a new "GPU Metrics for Every Profiled Worker" section.Inner reports are written right after the profile window ends, while the workers keep running, so run a few steps past the window.
Files
nemo_rl/utils/vllm_plugin.py,nemo_rl/utils/vllm_nsight_plugin.py(new),pyproject.tomlnemo_rlentry point and itsregister(); the nsight installer it calls. The installer importsRayExecutorV2directly, 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'sVLLM_RAY_PER_WORKER_GPUS.nemo_rl/models/generation/vllm/vllm_worker.py,vllm_generation.py,trtllm/trtllm_generation.py,patches.pynemo_rlentry point is installed, not excluded byVLLM_PLUGINS, and imports, when the inner TP workers are profiled; thevllm_kwargs.ray_workers_use_nsightrejection; vLLM and TRT-LLM generation leave shared GPUs' metrics to training; a note on the otherRayExecutorV2patch.nemo_rl/utils/nsys.pybuild_inner_nsight_config(),apply_nsys_extra_options()(inner workers,nullremoval), the"worker"GPU-metrics value.nemo_rl/distributed/worker_groups.py,worker_group_utils.py,virtual_cluster.pyRayVirtualCluster.claim_gpu_metrics(one sampling group per cluster);RayWorkerGroupclaims once and passessample_gpu_metricsto each worker, andrecreate_workerreplays it;get_bundle_gpu_id. Outer and policy nsight defaults are unchanged.docs/nsys-profiling.mdtests/unit/...null, fails loudly withoutRayExecutorV2,vllm-marked contract tests against the real executor), startup-check tests (missing, excluded, fails to import, duplicate names), thevllm_kwargsrejection, GPU-metrics claim, wiring, replay and bundle-probe tests.tests/test_suites/...,nightly.txt,tests/unit/test_recipes_and_test_suites.pyIssues
None.
Convergence / perf / functionality proof
N/A for convergence and speed: profiling is opt-in. Without
NRL_NSYS_WORKER_PATTERNSnothing changes, and the nsight defaults are unchanged. Functionality proof:Runs on this branch's head (after merging
mainat a3c461f, vLLM 0.33.0; rechecked after each later merge ofmain), 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}'.vllm_tp_worker(inner)megatron_policy_workergrpo-qwen3-32b-4n4gperformance recipe, 4 nodesgrpo-llama3.1-8b-instruct-2n4g-async-1off, 2 nodesgrpo-qwen3-32b-4n4g, 4 nodesgrpo-llama3.1-8b-instruct-2n4g, 2 nodesA 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 addgrpo.max_num_steps=6(D also++policy.generation.vllm_cfg.async_engine=false).nsys export --type=sqlite). Noworker_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 theNRL_NSYS_EXTRA_OPTIONSvalues, for both engines.{"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.VLLM_PLUGINS,VLLM_PLUGINSunset, andVLLM_PLUGINSnaming it; with an installed entry point that names a moved module, the check fails at startup while vLLM's loader only logsFailed to load plugin nemo_rl. In the sync TP=2 run, the inner config came only from vLLM's plugin load.test_worker_groups.py(42);test_recreate_worker.py(9);test_virtual_cluster.pywithCUDA_VISIBLE_DEVICES=0,1as in CI (81); the TRT-LLM flag test; thevllm-marked plugin contract tests inside both vLLM worker environments; the recipe and suite checks (16, including the nightly budget). Alsouv lock --check, pyrefly with CI's command and baseline (0 errors) and ruff.NRL_NSYS_EXTRA_OPTIONSunset: 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, becausecuda-graph-trace=nodeexpands each CUDA-graph replay, so the default options were really in effect.BaseVllmGenerationWorker.start_gpu_profilingstill callscudaProfilerStartin the outer actor, which writes near-emptyvllm_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.txtis at its GPU-hour cap, so this PR raisestest_nightly_compute_stays_below_*_hoursby 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.grpo-qwen3-32b-4n4g, 4 nodesgrpo-llama3.1-8b-instruct-2n4g-async-1off+ TP=2, 2 nodesgrpo-llama3.1-8b-instruct-2n4g-async-1off, 2 nodesgrpo-qwen3-32b-4n4g, 4 nodesgrpo-llama3.1-8b-instruct-2n4g, 2 nodesvllm_async_generation_worker(inner workers inherit the outer worker's config).cuda-memory-usageis recorded in policy, vLLM generation and vLLM TP-worker reports."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.mainwith 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 exactlyvllm_async_generation_workergave 16 (inherited config, namedvllm_async_generation_worker_*).cudaProfilerStopends each inner capture range, and withcapture-range-end=stopnsys 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_pluginsentry point, and the async await fix it relies on (#4604) is already onmain.Follow-ups, out of scope: skip the outer
cudaProfilerStartfor the sync engine at TP>1 (the near-empty outer reports in case C), as #4604 did for the async engine; the pre-existingvllm_generation_workervsvllm_async_generation_workername check invllm_worker.py; non-colocated distillation builds its separate generation cluster withmax_colocated_worker_groups=3, so vLLM there samples no GPU metrics (unchanged by this PR). Coordination: #3517 also changes whenray_workers_use_nsightis set; only one of the two PRs should change that logic.PR commands and CI
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. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.🤖 Generated with Claude Code