Skip to content

Add opt-in NRL_NVTX profiling ranges - #2838

Open
jioffe502 wants to merge 34 commits into
mainfrom
jioffe/nrl-nvtx-profiling
Open

jioffe502 wants to merge 34 commits into
mainfrom
jioffe/nrl-nvtx-profiling

Conversation

@jioffe502

@jioffe502 jioffe502 commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Adds opt-in NVTX ranges that split GPU actor time by owner. NRL_NVTX=1 emits NRL, vLLM, and model-forward ranges for timing runs, and NRL_NVTX=full adds torch host-sync and Ray serialization ranges.
When the variable is unset, nothing is patched and span() returns a shared no-op context.

Stacked on #2837.

Workload GPUs #2837 PR, NRL_NVTX unset PR, NRL_NVTX=1 PR, NRL_NVTX=full Recall
bo767 (PDF/text, 764 docs) 8 251.0 s 252.8 s (+0.7%, noise) 253.1 s (+0.1% vs unset) 253.6 s (+0.3% vs unset) R@10 0.9173 → 0.9193 / 0.9183 / 0.9193
bo767 (PDF/text, 764 docs) 1 1350 s 1348 s (-0.1%) not run not run R@5 0.8860 → 0.8829

Setup: NVIDIA RTX PRO 6000 Blackwell Server Edition (8x and 1x), Nemotron 3.5 Embed BF16, default settings, one run per arm, no nsys attached. Startup time is flat across levels (164-166 s).

What changed

  • New nemo_retriever/common/nvtx_layers.py with span(layer, name) and an idempotent install(*groups). Each caller names only its own target group (page_elements, ocr, vllm), so actors do not import unrelated packages.
  • Callers are the Page Elements and OCR actors, plus register_nemotron35_vllm (the existing vLLM plugin entry point, which also runs in EngineCore). full adds the torch and ray groups and vLLM msgpack ranges.
  • NRL ranges wrap the embed call sites in with blocks: prompt rendering, request building, output validation, image decode, routing, group embed, and result assembly. vLLM ranges wrap AsyncLLM.wait and each per-image vision call. The spike opened three of these ranges by hand, and they leaked on exceptions.
  • performance_guide.md gets a short "Split GPU stage time by owner" section.

Why it's safe

  • Every range is a with block or a wrapper that closes in finally, so exceptions close ranges (no hand-opened ranges).
  • Third-party code is patched only when NRL_NVTX is 1 or full, once per group per process. Missing targets are logged and skipped.

Not tested: nsys traces of this exact head. Range coverage comes from earlier spike traces and an in-process check that every target is wrapped.

Details
  • An earlier revision installed every target group in every actor, so OCR and Page Elements actors imported vLLM. With tracing on, that cost +13% wall time, which is why install() takes per-actor groups.
  • Ranges were not observed in the runs above because nsys was not attached. Range coverage comes from earlier nsys traces of the spike on L40S and RTX PRO 6000 hosts, plus an in-process check against the pinned vLLM, Ray, and torch: 1 wraps the vllm/ocr/page_elements targets, full adds Tensor.item and msgpack, and OCR/Page Elements installs do not import vLLM.
  • Tests: 417 targeted tests passed, including tests/test_nvtx_layers.py (disabled no-op, range closes on exception, function/generator/coroutine wrappers, idempotent install with missing targets, full adds sync and serialization targets); pre-commit.

Link to Devin session: https://nvidia-cloud.devinenterprise.com/sessions/57f5368b39844a038449e009f6bdd631
Open in Devin Desktop: https://nvidia-cloud.devinenterprise.com/desktop/session/57f5368b39844a038449e009f6bdd631?variant=devin
Requested by: @jioffe502


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

…flash attention

The HF Pixtral vision tower concatenates every image in a vLLM multimodal batch into one sequence and runs SDPA with a dense block-diagonal mask. Run the tower once per image and drop the mask for a single image so SDPA can select flash attention. Per-image outputs keep the stock order and shape.

Text+image admission now counts expanded prompt tokens from the image size and the tokenizer instead of running the processor's pixel preprocessing a second time before vLLM. Images smaller than one merged patch still use the processor so its resize and error behavior is unchanged.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
… with two UDF threads

The synchronous LLM.embed loop idles the GPU while an actor prepares its next batch. AsyncEmbedEngine wraps vLLM AsyncLLM on a private event loop, submits each prompt as its own request, and keeps LLM.embed's call shape. The GPU embed actor runs two Ray UDF threads on a true multithreaded actor pool, so one batch prepares while the other waits on the engine. Models that do not support concurrent calls stay serialized per actor, and the shared fast tokenizer is guarded because mixed truncation settings mutate it. CUDA graphs stay enabled.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Set NRL_NVTX=1 to split GPU actor time across NRL, vLLM, Ray, and torch NVTX domains. Ranges are context managers or wrappers with finally blocks, so exceptions close them. Third-party vLLM, Ray, torch, Page Elements, and OCR targets are wrapped once per process, in GPU actors and through vLLM model registration in EngineCore, only when the variable is set. When it is unset, span() returns a shared no-op context and nothing is patched. The performance guide documents the domains and a profile command.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Wrap prompt rendering, request building, output validation, image decode,
routing, group embedding, result assembly and per-image vision calls in
with-block ranges so exceptions close them.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
NRL_NVTX=1 keeps NRL, vLLM and model-forward ranges. Tensor host syncs,
torch.cuda syncs, Ray serialization and vLLM msgpack ranges move to
NRL_NVTX=full. install() takes target groups so OCR and Page Elements
actors no longer import vLLM, and the embed actor no longer imports the
OCR and Page Elements packages.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

…on test

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…ling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 finding. Devin automatically fixed it.

Fixed by Devin (1)
  • Early close defers async generator cleanup — Reversing the earlier rejection after jperez999 reproduced it: the wrapper now iterates under contextlib.aclosing, so aclose() awaits the target's finally; the early-close test asserts the inner async finally ran.

View findings in Devin Review · Follow Devin's work

Devin Review

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…nvtx-profiling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…readed operators

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
… array

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…-async-vllm

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…ling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Devin Review finding "Profiling drops generator input values" (_wrap in common/nvtx_layers.py doesn't forward send()/asend() values): rejected, no change. Nothing in the repo calls send()/asend() into a wrapped generator; AsyncLLM.encode is consumed with async for. The wrapper only runs when NRL_NVTX is set.

Written by Devin

…-async-vllm

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…ling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Run each prompt in an asyncio.TaskGroup so a failing prompt cancels the
rest of the call before its error propagates, and document the
AsyncEmbedEngine, create_vllm_llm and supports_concurrent_calls APIs.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…ling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>

# Conflicts:
#	nemo_retriever/src/nemo_retriever/models/inference/vllm.py
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>

# Conflicts:
#	nemo_retriever/src/nemo_retriever/models/local/nemotron35_embedder.py
…ling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
AsyncEmbedEngine keeps its loop thread; shutdown() and garbage collection
stop the loop, join the thread and close the loop. Nemotron35Embedder
loads the model under a lock, so concurrent first calls build one engine.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…ling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…ling

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@jioffe502
jioffe502 changed the base branch from jioffe/n35-embed-async-vllm to main November 10, 2026 22:46
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@jioffe502
jioffe502 marked this pull request as ready for review November 10, 2026 23:39
@jioffe502
jioffe502 requested review from a team as code owners November 10, 2026 23:39
@jioffe502
jioffe502 requested a review from ChrisJar November 10, 2026 23:39
@greptile-apps

greptile-apps Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the remaining documentation finding is fixed.

Summary

Adds opt-in NVTX ranges to help separate library, vLLM, PyTorch, and Ray time.

  • GPU traces show owner-labeled ranges when NRL_NVTX is enabled.
  • Embedding profiles show separate ranges for key batch stages.
  • OCR and Page Elements actors get their own profiling ranges.
  • vLLM work gets separate ranges for engine and image calls.

Reviews (7) · Last reviewed commit: "Document span and install arguments and ..." · Reviewed by Greptile

greptile-apps[bot]

This comment was marked as resolved.

greptile-apps[bot]

This comment was marked as resolved.

…async-range docs

Tensor.to no longer formats tensor arguments to decide whether a call copies
to the CPU. Tests cover async-generator completion, early close and
cancellation plus the tensor wrappers, and the performance guide no longer
says async ranges nest.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
vLLM 0.32 uses Model Runner V2 by default, so the V1 GPUModelRunner targets emitted no runner ranges.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Ray caches actor methods when the actor is created, before the GPU actor installs its wrappers, so _MapWorker.submit was never wrapped for running tasks.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
to("cpu", non_blocking=True) only queues the copy; vLLM waits on it later in the runner.output_copy_sync range.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
aclose() on the wrapper now waits for the target's finally (via contextlib.aclosing) instead of leaving it to async-generator finalization.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants