Skip to content

Nemotron 3.5 vLLM embed: AsyncLLM with four UDF threads per actor - #2837

Merged
jperez999 merged 13 commits into
mainfrom
jioffe/n35-embed-async-vllm
Nov 10, 2026
Merged

jperez999 merged 13 commits into
mainfrom
jioffe/n35-embed-async-vllm

Conversation

@jioffe502

@jioffe502 jioffe502 commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Runs Nemotron 3.5 embedding through vLLM's async engine in its own process, and lets each embed actor keep 4 batches in flight. Stacked on #2836.

On main, the GPU sits idle while vLLM preprocesses images on the CPU. With this PR, the CPU prepares the next batches while the GPU runs the current one, so the GPU stays busy: embed GPU busy goes from 63% to 92% in an nsys trace.

Schematic: on main, CPU preprocessing and GPU embed take turns; with this PR, 4 batches in flight keep the GPU busy

The same thing in a real nsys trace (ViDoRe, 8 GPUs, GPU 7, a 10 s steady-state window). Red marks GPU idle time.

Real nsys intervals: GPU busy 63% on main vs 92% with this PR

Image-heavy ingest (ViDoRe) is ~2× faster than main; PDF/text is unchanged.

Dataset main pps PR pps Recall@10
ViDoRe v3 English, 8 GPUs 31.6 65.0 unchanged
ViDoRe v3 English, 1 GPU 5.0 17.3 unchanged
bo10k (PDF/text), 8 GPUs 331.1 338.0 unchanged

Every ViDoRe subset gets faster when ingested on its own. Smaller subsets gain less because model start-up is a fixed cost. Recall is unchanged on every subset.

ViDoRe subset (8 GPUs) main pps PR pps Δ
hr 7.1 7.7 +9%
computer_science 8.0 9.4 +18%
pharmaceuticals 13.4 16.4 +23%
finance_en 14.6 19.8 +36%
industrial 21.0 31.7 +51%

Confidence

  • Embeddings match main (cosine ≥ 0.9997), and recall is unchanged everywhere.
  • The tokenizer is shared across threads, so it's lock-guarded; we reproduced the race without the lock.
  • Only the Nemotron 3.5 vLLM embedder opts in. Every other embedder still runs one batch at a time.

What changed

  • AsyncEmbedEngine (models/inference/vllm.py) has the same call shape as LLM.embed, but runs over vLLM AsyncLLM and returns results in prompt order.
  • _BatchEmbedActor.UDF_THREADS = 4. The executor turns it into a multithreaded Ray actor pool; an explicit max_concurrency override still wins. Pool sizes and CPU/GPU reservations are unchanged.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Link to Devin session: https://nvidia-cloud.devinenterprise.com/sessions/bad125a41197410993e49df9e8ca2f37
Open in Devin Desktop: https://nvidia-cloud.devinenterprise.com/desktop/session/bad125a41197410993e49df9e8ca2f37?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>
@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>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@devin-ai-integration devin-ai-integration Bot changed the title Nemotron 3.5 vLLM embed: AsyncLLM with two UDF threads per actor Nemotron 3.5 vLLM embed: AsyncLLM with four UDF threads per actor Nov 8, 2026

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 1 finding. It is left for you to triage below.

View findings in Devin Review · Follow Devin's work

Devin Review

…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>
…-async-vllm

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 9, 2026 23:00
@devin-ai-integration
devin-ai-integration Bot requested review from a team as code owners November 9, 2026 23:00
@devin-ai-integration
devin-ai-integration Bot requested review from mahikaw and removed request for a team November 9, 2026 23:00
@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 2/5

[Medium impact] The PR changes concurrency within the GPU embedding ingest workflow.

The exception block in the new concurrency test must satisfy the explicit repository rule before merging.

Findings

  1. P0 Barrier errors are ignored ▶
Fix with agent prompt
### Issue 1
nemo_retriever/tests/test_operator_flags_and_cpu_actors.py:405-406
The new test catches `threading.BrokenBarrierError` and does nothing. This violates the repository directive forbidding exception blocks that use `pass`, which also applies to tests. Record and assert the expected timeout for serial calls rather than silently ignoring it.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR lets Nemotron 3.5 embedding run through AsyncLLM with four batches in flight per actor.

  • Async vLLM embedding sends prompts together and returns results in input order.
  • GPU embed actors can prepare batches while Nemotron 3.5 vLLM runs.

Diagram

sequenceDiagram
    participant R as Ray actor threads
    participant M as Nemotron35Embedder
    participant A as AsyncEmbedEngine
    participant V as AsyncLLM
    R->>M: Concurrent batches
    M->>M: Lock shared tokenizer calls
    M->>A: embed(prompts)
    A->>V: Submit each prompt on private loop
    V-->>A: Completed outputs
    A-->>M: Outputs in prompt order
    M-->>R: Embeddings
Loading

Reviews (6) · Last reviewed commit: "test(embed): stub AsyncEngineArgs in eve..." · Reviewed by Greptile

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>

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

"""Graph embedding actor that loads a local embedder or calls a remote endpoint."""

# Ray UDF threads per actor, so batches prepare on the CPU while others wait on the engine.
UDF_THREADS = 4

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.

[P3] Scope the Ray scheduling opt-in and reuse its serialization

Nonblocking design/scope suggestion: this class-level constant enables a four-thread, true-multithreaded Ray pool for every GPU embedding actor, including HF, other local models, and remote endpoints. The new _serial lock serializes their inference, but their Ray batching/prefetch and thread scheduling still change. That is broader than the description's 'Only the Nemotron 3.5 vLLM embedder opts in' claim. Could the executor select this strategy only for the supported resolved model/backend and retain Ray's existing serialized-UDF path for the others? Ray already provides the serialization when enable_true_multi_threading is false, so this could also remove the extra per-actor lock/nullcontext dispatch. If the broader scheduling change is intentional, please describe and validate its effects on those other embedders.

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.

Agreed, the pool is wider than the description's wording. Every embed actor gets four Ray UDF threads. For models without supports_concurrent_calls, which is everything except the Nemotron 3.5 vLLM backend, _serial still runs inference one batch at a time. HF and remote actors can therefore hold up to four batches while they wait, but they never run them concurrently, so results are unaffected. I've left the code as is to keep this PR small. Scoping UDF_THREADS to the vLLM backend can be a follow-up if you'd like it.

@jioffe502
jioffe502 changed the base branch from jioffe/n35-embed-vision-fastpath to main November 10, 2026 19:43
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>

# Conflicts:
#	nemo_retriever/src/nemo_retriever/models/local/nemotron35_embedder.py
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>
@jioffe502
jioffe502 requested a review from jperez999 November 10, 2026 20:57
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@jperez999
jperez999 merged commit ca5b311 into main Nov 10, 2026
12 checks passed
Comment on lines +405 to +406
except threading.BrokenBarrierError:
pass

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.

P0 Barrier errors are ignored

The new test catches threading.BrokenBarrierError and does nothing. This violates the repository directive forbidding exception blocks that use pass, which also applies to tests. Record and assert the expected timeout for serial calls rather than silently ignoring it.

Rule Used: Never use bare 'except:' that silently swallows errors. Always catch specific exceptions where possible. Catching 'except Exception as e:' is acceptable ONLY at defined boundaries -- FastAPI endpoint handlers, CLI entry points (typer/click commands),... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/tests/test_operator_flags_and_cpu_actors.py
Line: 405-406

Comment:
**Barrier errors are ignored**

The new test catches `threading.BrokenBarrierError` and does nothing. This violates the repository directive forbidding exception blocks that use `pass`, which also applies to tests. Record and assert the expected timeout for serial calls rather than silently ignoring it.

**Rule Used:** Never use bare 'except:' that silently swallows errors. Always catch specific exceptions where possible. Catching 'except Exception as e:' is acceptable ONLY at defined boundaries -- FastAPI endpoint handlers, CLI entry points (typer/click commands),... ([source](https://github.com/nvidia/nemo-retriever/blob/e20f2abff67851062d46d70d94488a2d4af06792/.greptile/config.json))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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