Skip to content

Size batch defaults from the hardware: keep CPUs free for repartition and give every GPU its own workers - #2824

Merged
jioffe502 merged 15 commits into
mainfrom
devin/1793641892-repartition-cpu-reserve
Nov 3, 2026
Merged

jioffe502 merged 15 commits into
mainfrom
devin/1793641892-repartition-cpu-reserve

Conversation

@jioffe502

@jioffe502 jioffe502 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Batch defaults are now sized from the hardware: CPU and GPU workers follow the host's CPUs, GPU count and GPU memory. On large hosts the defaults no longer stall and match our hand-tuned layout. Settings you pass yourself are used as is.

Default settings, one run per cell main 64f85b2 pages/s this PR pages/s hand-tuned pages/s steady GPU util, main → PR recall@5 / @10, main → PR
8x RTX PRO 6000, 256 CPUs, bo10k 0 (stalls) 299.1 296.8 0% → 95.2% — → 0.711 / 0.766
4x L40S, 32 CPUs, bo767 18.5 65.8 27.4% → 79.8% 0.866 / 0.922 → 0.866 / 0.922
1x H100 NVL, 32 CPUs, bo767 23.2 35.6 36.3 not measurable → 95.0% 0.865 / 0.924 → 0.865 / 0.924

Setup: no ingest settings passed, fresh container per run. bo10k is 10,000 PDFs (213,538 pages), cold cache; bo767 is 767 PDFs (54,730 pages). PR head 21a6ddb on 8x RTX PRO 6000 and 4x L40S. On 1x H100 the run used 72bd8bf; later commits do not change the 1-GPU plan. One run per arm; single-run spread on the 8-GPU box is usually 0.4–2.7%.

What changed

  • CPU reserve. Preflight stops growing auto-sized actor pools while it still leaves free 1 CPU per Ray Data repartition step, a 10% margin (at most 8) on hosts with 32+ CPUs, and 1 CPU for the driver. PDF extraction books 1 CPU per worker instead of 2, because page rendering is single-threaded. Without the reserve, actors book every CPU, repartitions cannot start and no rows reach the GPUs.
  • Per-GPU worker set. On 2+ GPUs, page elements, OCR and embedding get the same set on every GPU, and its GPU shares add up to 1.0. Ray's first-fit placement then has to use every GPU. GPUs with at least 72 GiB get 4 PE x 0.21 + 2 OCR x 0.06 + 1 embed x 0.04 (the hand-tuned layout); smaller or unknown GPUs get 1 x 0.51 + 1 x 0.25 + 1 x 0.24.
  • Reshape before embedding. Targets 2 actors per GPU (1 on a single GPU) inside the CPU budget, instead of one fixed actor that capped 8 GPUs near 120 pages/s.
  • Regroups. With the per-GPU set, the repartitions before page elements and embedding default to off. Ray Data gave those task steps about 0.1 CPU of budget, so they starved the GPU pools. Batch sizes are unchanged, because map_batches still bundles rows up to the batch size.

Why it's safe

  • Explicit settings win. Any *_workers, *_cpus_per_actor, gpu_*, embed_reshape_workers or node_overrides value is used as is and never shrunk. page_elements_repartition and embed_repartition are now Optional[bool]: None means automatic, and True / False are honored.
  • Fallbacks keep earlier behavior. These keep the previous GPU defaults and both repartitions: 1 GPU, CPU-only, remote PE/OCR/embed endpoints, captioning, table structure, Nemotron Parse, audio, and page elements off. Multi-node clusters and clusters with mixed GPU memory get the small per-GPU set. The admission check is unchanged, so a plan that fits today still starts.
  • Guards. Only the PDF graph with local page elements, OCR and embedding gets the per-GPU set; text, HTML, image, audio, video and auto graphs keep the previous defaults. The large set needs at least 72 GiB of free memory on every GPU Ray uses (CUDA_VISIBLE_DEVICES), and the chosen set and reason are logged at INFO. After the GPU actors start, a WARNING names any pending actors or uneven per-GPU counts.
  • Tests and docs. Tests cover the reserve, default plans for 256/8, 128/8, 64/2, 32/4, 32/1 and 16/1 (the 8-GPU plan matches the hand-tuned layout setting for setting), first-fit placement, every fallback, and explicit overrides. Run: 392 passed, 6 skipped. docs/docs/extraction/performance_guide.md describes each default.

Not tested: other GPU models, text-only and audio pipelines, and Kubernetes/Helm deployments.

Details: formulas, measurement ladder, resolved plans

CPU reserve.

n_task = repartition steps across all executors (1 per node with target_num_rows_per_block > 0, 2 per REQUIRES_GLOBAL_BATCH node)
margin = min(8, ceil(0.10 * S)) if S >= 32 else 0           # S = available CPUs
actor growth budget = S - source_read - reserved - (n_task + margin + 1)

Growth order: CPU-only pools up to min(2 per GPU, target / 8), then GPU pools, then the rest. GPU actors count against the same budget. To restore the old PDF booking, set pdf_extract_num_cpus=2 or --pdf-extract-cpus-per-task 2.

8x RTX PRO 6000, 256 CPUs, bo10k, cold cache, one run per arm. Each row adds one change.

Code pages/s steady GPU util what limited it
main 64f85b2 0 0% PDF extraction booked 212 of 256 CPUs; the repartition before PE never ran
+ CPU reserve (250a24b) 123.6 32% PE and OCR packed onto GPUs 0-2
+ per-GPU set (408ecb0) 121.0 34% single reshape actor at ~0.9 core; OCR blocked downstream in 98% of samples
+ reshape sizing (00a717c) 228.2 53.6% PE repartition: median 1 task, ~0.1 CPU budget; median 9 of 32 PE actors busy
00a717c + page_elements_repartition=false 286.2 embed repartition at 0 spare CPU in 96% of samples
final head 21a6ddb 299.1 95.2% (lowest GPU 92.9%)
main + hand-tuned layout 296.8

Final head: 0 failed batches, 0 bad vectors, no OOM, nDCG@10 0.623, first embedding output at +160 s.

4x L40S (46 GiB usable), 32 CPUs, bo767, one run per arm.

main 64f85b2 408ecb0 (per-GPU set) 21a6ddb (final)
pages/s 18.49 57.70 65.77
GPU util, steady / whole run 27.4% / 22.7% 77.8% / 66.2% 79.8% / 75.4%
lowest GPU, whole run 0% 60.5% 69.0%
peak VRAM per GPU up to 43.8 GiB on GPU 0; GPUs 2-3 unused 18.5-25.1 GiB 17.7-22.0 GiB
first embedding output +925 s +99 s +100 s
recall@5 / @10 0.866 / 0.922 0.868 / 0.919 0.866 / 0.922

Final head plan: 9 PDF x 1 CPU, 2 reshape, 1 PE + 1 OCR + 1 embed on every GPU, both regroups off. Ray booked 31-32/32 CPUs for the first ~4.5 min, then 23/32. 0 failed batches, no OOM. The +14% over 408ecb0 is not split between removing the regroups and the extra PDF and reshape workers they free.

1x H100 NVL, 32 CPUs, bo767, one run per arm, OS page cache not dropped.

main 64f85b2 250a24b 72bd8bf main, hand-tuned (both regroups off)
pages/s 23.15 35.65 35.64 36.34
GPU util, steady / whole run not measurable / 51.4% 92.6% / 75.0% 95.0% / 78.1% / 79.9%
actors (PDF x CPU, PE, OCR, embed) 11 x 2, 3, 2, 1 13 x 1, 3, 3, 1 13 x 1, 3, 3, 1 11 x 2, 3, 2, 1

On main, the repartition before embedding had 0 CPU for ~27 min (586 queued blocks), so nothing was embedded until PDF extraction finished. With the reserve it never queued more than 1 block.

Resolved default plans (the real batch_tuning_to_node_overrides plus preflight on simulated clusters; CPUs booked includes the source read, PDF split and document-to-PDF actors):

CPUs / GPUs (memory) PDF x CPU PE OCR embed reshape repartitions CPUs booked
256 / 8 (96 GB) 128 x 1 32 x 0.21 16 x 0.06 8 x 0.04 16 pre-extraction 203 / 256
128 / 8 (96 GB) 52 x 1 32 x 0.21 16 x 0.06 8 x 0.04 7 pre-extraction 118 / 128
64 / 2 (96 GB) 32 x 1 8 x 0.21 4 x 0.06 2 x 0.04 4 pre-extraction 53 / 64
32 / 4 (48 GB) 9 x 1 4 x 0.51 4 x 0.25 4 x 0.24 2 pre-extraction 26 / 32
32 / 1 13 x 1 3 x 0.1 3 x 0.1 1 x 0.2 1 all three 24 / 32

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

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@jioffe502
jioffe502 requested a review from a team as a code owner November 2, 2026 17:56
@jioffe502
jioffe502 requested a review from a team as a code owner November 2, 2026 17:56
@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

@jioffe502
jioffe502 requested a review from edknv November 2, 2026 17:56

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

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

Devin Review

@greptile-apps

greptile-apps Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue was found.

Summary

Sizes batch workers from CPU capacity, GPU count, and free GPU memory.

  • Batch preflight leaves CPU room for Ray Data tasks.
  • Eligible PDF runs give every GPU a matching set of workers.
  • GPU actors report where they land during multi-GPU ingestion.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Ray CPU and GPU resources] --> B[Resolve batch defaults]
  C[Free memory on visible GPUs] --> B
  D[Explicit settings] --> B
  B --> E[Reserve CPUs for reads and repartitions]
  E --> F[Grow automatic worker pools]
  F --> G[Run PDF extraction, OCR, and embedding]
  G --> H[Report GPU placement]
Loading

Reviews (11) · Last reviewed commit: "Use the large per-GPU cell only when Ray..." · Reviewed by Greptile

@devin-ai-integration

Copy link
Copy Markdown
Contributor

The failing build check is not caused by this diff. It comes from .github/workflows/docker-release-publish.yml ("Build and Push Docker Image"), which fails while tagging the image, before anything is built:

invalid tag ".../nrl-service:refs/heads/pull-request/2824": invalid reference format

The workflow triggers on create with a branches: release/* filter. GitHub ignores branch filters on create events, so the workflow also runs when the pull-request/<N> mirror branch is created for a same-repo PR. BRANCH_NAME=${GITHUB_REF#refs/heads/release/} only strips the prefix for release/ branches, so every other branch produces an invalid Docker tag. The same error shows up on #2818, #2819, #2820 and #2822. This PR changes no workflow files. All other checks pass, including the unit tests and the Docker build-and-test job.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
greptile-apps[bot]

This comment was marked as resolved.

…L errors

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

This comment was marked as resolved.

…d probe memory only when the driver holds every GPU

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@jioffe502 jioffe502 changed the title Keep Ray CPUs free for repartition tasks in batch preflight Size batch defaults from the hardware: keep CPUs free for repartition and give every GPU its own workers Nov 2, 2026
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
When the per-GPU cell sizes the GPU stages, page_elements_repartition and embed_repartition default to off unless set explicitly. The repartition tasks get too little Ray Data budget to feed the larger GPU pools. Single-GPU and fallback paths keep both repartitions.

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

This comment was marked as resolved.

greptile-apps[bot]

This comment was marked as resolved.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…ay's GPUs, and check placement

- Only the PDF graph gets the per-GPU cell; text, HTML, image, audio, video and auto graphs keep the previous defaults and repartitions.
- The large cell needs the smallest free memory among the GPUs named by CUDA_VISIBLE_DEVICES to be at least 72 GiB; the chosen cell and the reason are logged at INFO.
- Fractional-GPU actors report their GPU when they start, and the executor logs a WARNING when a pool has pending actors or an uneven count per GPU.

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

This comment was marked as resolved.

…est ends

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

This comment was marked as resolved.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
greptile-apps[bot]

This comment was marked as resolved.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
and getattr(extract_params, "use_page_elements", False)
and any(
getattr(extract_params, name, False)
for name in ("extract_text", "extract_tables", "extract_charts", "extract_infographics")

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.

[P2] Gate the cell on the stages the graph actually creates. For method='pdfium', extract_text=True, and extract_tables/extract_charts/extract_infographics=False, this predicate is true, but build_graph only sets OCR extract_text for pdfium_hybrid/ocr; needs_ocr and page_elements_needed are both false. The resulting graph has neither PE nor OCR, yet receives the cell's tiny embedding GPU share and loses its embedding repartition. On eight large GPUs all eight 0.04-share embedding actors can pack onto one GPU. This contradicts the stated restriction to a PDF graph containing all three local pools. Please share the graph builder's needs_ocr/page_elements_needed calculation with this guard and cover the native-text-only PDF case.

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.

Good catch, fixed in 8820636. build_graph and the cell guard now share one helper, _pdf_ocr_needed(extract_params). The guard already requires use_page_elements and excludes table structure, so whenever this helper is true the graph builds page elements and OCR (page_elements_needed reduces to needs_ocr). A native-text-only pdfium graph therefore keeps the previous defaults. That case is now in test_per_gpu_cell_skips_graphs_with_other_gpu_pools. The default pdfium_hybrid plans on 256/8, 32/4 and 32/1 are byte-identical to 21a6ddb.

(extract_params, "page_elements_invoke_url"),
(extract_params, "ocr_invoke_url"),
(embed_params, "embed_invoke_url"),
)

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.

[P2] Include the supported embedding_endpoint alias in the remote-embedding exclusion. EmbedParams(embedding_endpoint='http://embed:8000/v1/embeddings') leaves embed_invoke_url unset (normalization only copies the other direction), so this guard enables the cell for an HTTP embedder. That changes PE/OCR shares and disables both repartitions even though the description promises the previous defaults for remote embedding. Please reuse a normalized endpoint predicate here; _local_embed_requested above already checks both names. Add the embedding_endpoint variant alongside the existing embed_invoke_url fallback test.

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.

Fixed in 8820636. The remote-endpoint check now covers embedding_endpoint as well as embed_invoke_url, matching what _local_embed_requested accepts. EmbedParams(embedding_endpoint=...) sits next to the embed_invoke_url case in the fallback test.

…bedding_endpoint

Share build_graph's OCR-stage check with the cell guard so a native-text-only pdfium graph (no page elements or OCR) keeps the previous defaults, and treat embedding_endpoint like embed_invoke_url.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@jioffe502
jioffe502 requested a review from jperez999 November 3, 2026 16:22

@jperez999 jperez999 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 is a gotcha but your call on whether to fix, we are only responsible for single node. So all GPUs should be local.

if gpus is None:
logger.info("CUDA_VISIBLE_DEVICES does not name GPU indices or UUIDs; using the small per-GPU cell")
return 0
if len(gpus) < cluster_gpu_count:

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.

[P2] A local GPU count cannot establish that the available Ray GPUs are local. The caller passes available_gpu_count, so this check permits the large cell whenever the driver exposes at least that many physical GPUs, even if Ray will schedule on remote, smaller GPUs. For example, a driver host with eight 96-GiB GPUs can connect to a Ray cluster whose four available GPUs are remote 48-GiB cards (the driver GPUs need not be registered as Ray resources); len(gpus)=8 >= 4 and the local NVML probe selects the large layout for those workers. A partially occupied multi-node cluster has the same ambiguity. I verified the helper returns 97,000 MiB for eight local 97,000-MiB entries and a cluster count of two. This contradicts the stated multi-node fallback and can oversubscribe worker VRAM. Please conservatively choose the small cell unless the schedulable GPU node identity is verified to be this host, or gather memory on eligible Ray nodes. Add coverage where the local NVML count exceeds the available remote GPU count; the existing fewer-local-GPUs check does not cover that case.

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.

Made the conservative change in df13654. The large cell is now used only when Ray's available GPU count equals the number of GPUs this host exposes to Ray (!= instead of <); in every other case the small cell is used and the counts are logged at INFO. test_gpu_cell_memory_needs_ray_gpus_to_match_local_gpus covers 8 local GPUs against 2 or 4 Ray GPUs. Resolved plans on 256/8, 32/4 and 32/1 are byte-identical to 8820636. Supporting multi-node clusters (probing memory on the Ray nodes themselves) stays out of scope, since NRL supports only single-node.

…t exposes

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
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