Skip to content

draft: fix(nsys): make profiling work on SingleController and align throughput metrics - #3517

Open
ZhiyuLi-Nvidia wants to merge 1 commit into
mainfrom
zhiyul/nsys-sc-profiling
Open

ZhiyuLi-Nvidia wants to merge 1 commit into
mainfrom
zhiyul/nsys-sc-profiling

Conversation

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

Profiling an SC + TransferQueue run produced empty traces, and enabling it on vLLM generation reliably killed the job.

nsys fixes

  1. single_controller.py never called maybe_gpu_profile_step. Every other algorithm entrypoint does (grpo, ppo, sft, dpo, rm, distillation). Since the nsight config uses capture-range=cudaProfilerApi, nsys attached but cudaProfilerStart was never issued, so every .nsys-rep came out empty.

  2. Stop enabling ray_workers_use_nsight for vLLM. vLLM hardcodes an always-on nsight config for its internal TP workers (no capture-range), so nsys traced cuda,cudnn,cublas from process start for the whole run. That overhead skews ranks until a collective blows the NCCL watchdog: on a 6xGB200 SC run all 24 TP workers aborted on a 600s _ALLGATHER_BASE timeout on a 64K-element collective. vLLM offers no override -- the config is built inside a spawned EngineCore process -- so the only safe option is to leave the flag off. Generation is still covered by the outer worker's own profile.

  3. Remove _patch_vllm_nsight_config, which tried to override that config by rebinding the class method. It cannot work: the rebind happens in the worker actor, while vLLM configures the executor in a spawned subprocess. Confirmed from the runtime-env agent logs of a run where it was active -- 18 workers received vLLM's default worker_process_%p, none the intended vllm_tp_worker_*. It was silently letting the harmful config through.

  4. stop_gpu_profiling was unguarded, so a profiling teardown failure aborted the run at the diagnostic call rather than at real work. Now best-effort.

Adds NVTX ranges to the TransferQueue hops (tq_fetch, tq_write_back) and to prepare_for_training / prepare_for_lp_inference, which the SC loop calls every inner-loop iteration and which were invisible in traces. wrap_with_nvtx_name now delegates to torch.cuda.nvtx.range, a ContextDecorator that pops in a finally, so a raising call cannot leak an unbalanced range and mis-nest every later range in the trace.

Docs record two hardware traps: stop-shutdown ends the nsys session at the capture range, signalling the profiled workers to exit; and gpu-metrics-device is unsupported on some GPUs (GB200), where Ray's nsight plugin fails validation and silently drops the traces of workers that landed on a rejecting node.

metrics alignment

Throughput rates were split across three namespaces: timing/train/ (8 algorithms), performance/ (3, via print_performance_metrics) and train/ (distillation). timing/train/ also mixed rates with durations, so its printout formatted tokens/sec as seconds.

All rates now live under performance/, leaving timing/train/ for durations:

performance/valid_tokens_per_sec_per_gpu global_valid_toks / step / gpus
performance/tokens_per_sec_per_gpu total_num_tokens / step / gpus

Both keys are present in all 8 algorithms; five gained a prefix="performance" log call. Duplicates removed (distillation's train/ copy, and a redundant metric with the same formula as the helper's existing key). Per-algorithm guard conditions are preserved -- this is a namespace move, not a behaviour change.

BREAKING: timing/train/valid_tokens_per_sec_per_gpu is now performance/valid_tokens_per_sec_per_gpu. Dashboards keyed on the old path need updating; historical runs keep the old key.

Verified on 6xGB200 (SC + TQ, Nemotron-3-Nano-30B-A3B): 24/24 GPUs produced valid non-empty traces (16 trainer + 8 generation, 0.67 GB), zero NCCL watchdog timeouts, and the teardown guard fired as designed.

What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

Issues

List issues that this PR closes (syntax):

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

…metrics

Profiling an SC + TransferQueue run produced empty traces, and enabling it on
vLLM generation reliably killed the job.

nsys fixes
----------
1. `single_controller.py` never called `maybe_gpu_profile_step`. Every other
   algorithm entrypoint does (grpo, ppo, sft, dpo, rm, distillation). Since the
   nsight config uses `capture-range=cudaProfilerApi`, nsys attached but
   `cudaProfilerStart` was never issued, so every `.nsys-rep` came out empty.

2. Stop enabling `ray_workers_use_nsight` for vLLM. vLLM hardcodes an always-on
   nsight config for its internal TP workers (no `capture-range`), so nsys
   traced cuda,cudnn,cublas from process start for the whole run. That overhead
   skews ranks until a collective blows the NCCL watchdog: on a 6xGB200 SC run
   all 24 TP workers aborted on a 600s `_ALLGATHER_BASE` timeout on a
   64K-element collective. vLLM offers no override -- the config is built inside
   a spawned EngineCore process -- so the only safe option is to leave the flag
   off. Generation is still covered by the outer worker's own profile.

3. Remove `_patch_vllm_nsight_config`, which tried to override that config by
   rebinding the class method. It cannot work: the rebind happens in the worker
   actor, while vLLM configures the executor in a spawned subprocess. Confirmed
   from the runtime-env agent logs of a run where it was active -- 18 workers
   received vLLM's default `worker_process_%p`, none the intended
   `vllm_tp_worker_*`. It was silently letting the harmful config through.

4. `stop_gpu_profiling` was unguarded, so a profiling teardown failure aborted
   the run at the diagnostic call rather than at real work. Now best-effort.

Adds NVTX ranges to the TransferQueue hops (`tq_fetch`, `tq_write_back`) and to
`prepare_for_training` / `prepare_for_lp_inference`, which the SC loop calls
every inner-loop iteration and which were invisible in traces.
`wrap_with_nvtx_name` now delegates to `torch.cuda.nvtx.range`, a
ContextDecorator that pops in a `finally`, so a raising call cannot leak an
unbalanced range and mis-nest every later range in the trace.

Docs record two hardware traps: `stop-shutdown` ends the nsys session at the
capture range, signalling the profiled workers to exit; and
`gpu-metrics-device` is unsupported on some GPUs (GB200), where Ray's nsight
plugin fails validation and silently drops the traces of workers that landed on
a rejecting node.

metrics alignment
-----------------
Throughput rates were split across three namespaces: `timing/train/` (8
algorithms), `performance/` (3, via `print_performance_metrics`) and `train/`
(distillation). `timing/train/` also mixed rates with durations, so its printout
formatted tokens/sec as seconds.

All rates now live under `performance/`, leaving `timing/train/` for durations:

  performance/valid_tokens_per_sec_per_gpu   global_valid_toks / step / gpus
  performance/tokens_per_sec_per_gpu         total_num_tokens  / step / gpus

Both keys are present in all 8 algorithms; five gained a `prefix="performance"`
log call. Duplicates removed (distillation's `train/` copy, and a redundant
metric with the same formula as the helper's existing key). Per-algorithm guard
conditions are preserved -- this is a namespace move, not a behaviour change.

BREAKING: `timing/train/valid_tokens_per_sec_per_gpu` is now
`performance/valid_tokens_per_sec_per_gpu`. Dashboards keyed on the old path
need updating; historical runs keep the old key.

Verified on 6xGB200 (SC + TQ, Nemotron-3-Nano-30B-A3B): 24/24 GPUs produced
valid non-empty traces (16 trainer + 8 generation, 0.67 GB), zero NCCL watchdog
timeouts, and the teardown guard fired as designed.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: zhiyul <[email protected]>
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia requested review from a team as code owners August 6, 2026 09:33
@copy-pr-bot

copy-pr-bot Bot commented Aug 6, 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.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 6, 2026
@ZhiyuLi-Nvidia ZhiyuLi-Nvidia changed the title fix(nsys): make profiling work on SingleController and align throughput metrics draft: fix(nsys): make profiling work on SingleController and align throughput metrics Aug 6, 2026
@terrykong terrykong added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 5, 2026
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants