Nemotron-Parse PDF Pipeline
Nemotron-Parse PDF Pipeline
Convert PDF datasets into interleaved Parquet output using NVIDIA’s Nemotron-Parse vision-language model. Unlike traditional text-only PDF parsers, Nemotron-Parse extracts text, images, and reading order in one pass — producing rows directly compatible with the interleaved dataset format.
How it Works
NemotronParsePDFReader is a composite stage that expands into four underlying sub-stages:
PDFPartitioningStage— reads a JSONL manifest of PDF entries and packs them intoFileGroupTaskobjects.PDFPreprocessStage— extracts PDF bytes from the configured source, renders pages to images with scale-to-fit safeguarding against OOM on large pages.NemotronParseInferenceStage— runs Nemotron-Parse via vLLM (recommended) or Hugging Face Transformers, withtext_in_picandenforce_eagerflags and free-port retry on collisions.NemotronParsePostprocessStage— parses model output, aligns images and captions, crops images, and emits the final interleaved rows.
The output is interleaved Parquet ready to be filtered with Interleaved Filters and written to MINT-1T-style WebDataset shards.
Before You Start
Choose your PDF source and confirm the prerequisites:
- GPU: Required. Nemotron-Parse runs on GPU via vLLM (recommended) or Hugging Face Transformers.
- vLLM: Strongly recommended for throughput. Falls back to HF Transformers if
backend="hf"is set. pypdfium2: Required Python dependency for PDF rendering. Installed automatically with theinterleaved_cpuorinterleaved_cuda12extras (e.g.,uv sync --extra interleaved_cuda12).- Manifest: A JSONL file listing the PDFs to process. Each line should specify the PDF location relative to the source directory you choose.
Choosing a PDF Source
Pass exactly one of pdf_dir, zip_base_dir, or jsonl_base_dir so the preprocess stage knows where to find the PDF bytes:
Backend Selection
The inference stage retries transient port collisions when starting vLLM. Non-retryable startup failures, such as invalid configuration or GPU out-of-memory errors, fail immediately.
Usage
A minimal end-to-end pipeline that reads PDFs from a directory and writes interleaved Parquet:
For executor options and configuration, refer to Execution Backends.
Example: CC-MAIN PDF Dump
Parse a Common Crawl PDF dump from its zip hierarchy:
Example: JSONL-Encoded PDFs
Parse a JSONL-encoded dataset (e.g., GitHub-hosted PDFs where each line contains the bytes):
Parameters
Tune the vLLM Engine
NemotronParseInferenceStage.engine_kwargs is None by default. It passes additional settings to NeMo Curator’s shared vLLM initializer: vLLM engine settings are forwarded to vllm.LLM, while helper settings such as max_port_retries control initialization itself. Use this field when you compose the pipeline from individual stages and need controls that are not exposed by NemotronParsePDFReader:
The installed vLLM version performs final validation of forwarded engine settings. Check the matching vLLM documentation before using additional keys.
Keys in engine_kwargs take precedence over the stage’s max_num_seqs and enforce_eager values. Prefer the dedicated stage fields for those two settings and reserve engine_kwargs for other vLLM controls so the effective configuration remains clear.
Common tuning controls include:
Ray Data Fanout
PDFPartitioningStage is a Ray Data fanout stage. It reads the manifest on one worker, emits one FileGroupTask per pdfs_per_task group, and Ray Data repartitions the result to one emitted task per block. Downstream preprocess and inference stages can then consume those blocks in parallel instead of receiving the whole manifest as one block.
This behavior is automatic with RayDataExecutor; no stage-spec override is required. pdfs_per_task still controls the work in each emitted task:
- Lower values create more tasks and expose more downstream parallelism, with more scheduling overhead.
- Higher values reduce scheduling overhead but can leave GPUs idle when the number of tasks is smaller than the available workers.
max_pdfsis applied before tasks are created, so it remains useful for small validation runs.
Xenna uses its own task dispatch and does not consume the Ray Data fanout marker.
Output Format
Each output row represents a single item (text, image, or metadata) from a parsed PDF page. Rows sharing a sample_id belong to the same document. Example output JSON:
Output Schema
The output is directly compatible with Interleaved IO readers and writers — the schema matches INTERLEAVED_SCHEMA exactly.
Inspect Inference Metrics
NemotronParseInferenceStage records additive custom metrics on each output task. Aggregate the final pipeline results with TaskPerfUtils:
aggregate_task_metrics() appends _sum, _mean, and _std to each flattened metric. Use _sum for additive counts and total durations. Measure end-to-end throughput against pipeline wall time rather than the sum of per-task inference times, because tasks can run concurrently.
Metric Reference
The HF backend records image-loading and page-count metrics, but it does not expose vLLM token, character, truncation, or retry metrics.
Use the quality signals alongside throughput. A high num_output_length_truncated value means outputs are reaching the stage’s built-in 9,000-token generation limit and warrants inspection of those pages; num_empty_outputs and num_skipped_pages identify model-output and image-decoding failures that raw pages-per-second figures can hide.
vLLM Retry Behavior
There are two separate retry paths:
- Engine startup:
create_vllm_llm()chooses a newMASTER_PORTand retries up tomax_port_retries=3times for direct address-in-use errors or vLLM v1’s wrappedEngine core initialization failederror. Retries wait two to five seconds with jitter. Known non-retryable failures, including out-of-memory, device-side assertion, and invalid configuration errors, are raised immediately. - Inference: vLLM generation is attempted up to three times. After a failed attempt, the stage resets the engine before retrying. Successful retries contribute to the
vllm_retriestask metric; the final exception is raised after the third failed attempt.
If startup retries are exhausted, first check the worker log for the original failure. For repeated port collisions, reduce the number of vLLM replicas starting simultaneously or set a larger stage-level max_port_retries through engine_kwargs. Do not mask CUDA out-of-memory or invalid-model errors by increasing retries; tune memory-related engine settings or correct the model configuration instead.
Render Timeout
The preprocess stage replaces signal.SIGALRM with a multiprocessing fork-based timeout (_RENDER_TIMEOUT_S = 60 by default). This is required because Xenna runs stage workers inside Ray actor processes on non-main threads, where SIGALRM raises ValueError: signal only works in main thread. The forked child inherits the PDF bytes via copy-on-write and is killed if it exceeds the timeout, reliably escaping any hung C-extension code inside pypdfium2.
You don’t need to configure this — it works automatically. If you find legitimate PDFs that take longer than 60 seconds to render, the constant lives at nemo_curator/stages/interleaved/pdf/nemotron_parse/preprocess.py.
Benchmarking
A standalone benchmark script ships at benchmarking/scripts/nemotron_parse_pdf_benchmark.py. It uses the same TaskPerfUtils aggregation shown above and reports end-to-end pages per second and output tokens per second. Use a representative manifest and the public tutorial arguments to compare configurations before scaling to your full corpus; the repository’s nightly benchmark orchestration is not required.
Best Practices
- Use vLLM unless you can’t: the
vllmbackend is substantially faster thanhf. Only fall back tohffor debugging or in environments where vLLM is unavailable. - Cap
max_pagesfor outliers: very long PDFs (1000+ pages) can dominate runtime. The default 50 pages handles most academic papers and articles; raise to 200+ for book-length sources. - Tune
pdfs_per_taskfor parallelism: smaller values (5–10) parallelize better across many GPUs; larger values (20–50) reduce per-task overhead on smaller clusters. - Set
enforce_eager=Truein restricted environments: vLLM’s torch.compile path can fail on certain hosts. Disabling compilation trades throughput for compatibility. - Pair with interleaved filters: PDF parsing produces noisy output. Chain with the Interleaved Filters (blur, CLIP score) to drop low-quality samples before training.
Related Topics
- Interleaved IO — readers and writers that consume the Parquet output of this pipeline.
- Interleaved Filters — sample-level filters to apply after parsing.
- Common Crawl — companion source for web-scale PDF input via CC-MAIN dumps.