Large-Scale OCR Processing of Academic Papers Using AI Coding Agents and Serverless GPU Infrastructure

huggingface · Tech · 2026 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Large-scale document OCR for paper-chat RAG

Hugging Face needed Markdown versions for thousands of arXiv papers so Paper Pages could support HuggingChat's chat-with-paper feature even when arXiv HTML was unavailable. The team had to choose an open OCR model, run it economically across tens of thousands of papers, avoid proprietary API costs, write orchestration code for serverless GPU jobs, store mutable daily paper outputs efficiently, and integrate the result back into Paper Pages.

Constraints:

Architecture

Hugging Face selected Chandra-OCR 2 using the OlmOCRBench leaderboard, then used OpenAI Codex Desktop as a coding agent to implement and operate the pipeline. Codex was pointed at the model card, Hugging Face CLI skill, Jobs documentation, and the list of missing arXiv IDs. It wrote scripts to run Chandra-OCR-2 with vLLM on Hugging Face Jobs serverless GPUs, ran small-scale GPU comparisons over 120 papers, selected L40S over A10G based on throughput and total cost, launched 16 parallel L40S jobs, monitored progress, switched output from a dataset to mounted Hugging Face Buckets via hf-mount, and merged 16 buckets into a single bucket. Paper Pages then used the OCR Markdown for HuggingChat context.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  pages["Paper Pages"] --> chat["HuggingChat paper chat"]
  missing["Missing arXiv ID list"] --> codex["Codex coding agent"]
  leaderboard["OlmOCRBench leaderboard"] --> chandra["Chandra-OCR 2"]
  codex --> chandra
  codex --> scripts["OCR job scripts"]
  scripts --> jobs["Hugging Face Jobs"]
  jobs --> vllm["vLLM runtime"]
  vllm --> chandra
  jobs --> l40s["L40S parallel jobs"]
  l40s --> buckets["Hugging Face Buckets"]
  scripts --> mount["hf-mount"]
  mount --> buckets
  buckets --> markdown["OCR Markdown bucket"]
  markdown --> pages
  markdown --> chat
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Paper Pages Hugging Face paper hub surface that hosts papers, metadata, social interactions, and chat-with-paper access. HuggingChat paper chat, OCR Markdown bucket
HuggingChat paper chat Chat-with-paper feature that consumes Markdown paper context and feeds it to an LLM. Paper Pages, OCR Markdown bucket
Missing arXiv ID list Set of papers indexed by Hugging Face that lacked arXiv HTML and therefore needed OCR. Codex coding agent, OCR job scripts
Codex coding agent OpenAI coding agent used to generate scripts, compare GPUs, launch jobs, monitor progress, switch storage targets, and merge outputs. Missing arXiv ID list, Chandra-OCR 2, Hugging Face Jobs, Hugging Face Buckets, OCR job scripts
OlmOCRBench leaderboard Benchmark used to select the open OCR model based on evaluation results. Chandra-OCR 2
Chandra-OCR 2 Open OCR model used to convert PDFs into Markdown with image/table HTML. Codex coding agent, OCR job scripts, vLLM runtime
OCR job scripts Generated orchestration code for running Chandra-OCR-2 over paper subsets on serverless GPU jobs. Codex coding agent, Hugging Face Jobs, vLLM runtime, Hugging Face Buckets
Hugging Face Jobs Serverless CPU/GPU compute platform with pay-as-you-go pricing used for parallel OCR jobs. OCR job scripts, L40S parallel jobs, vLLM runtime
vLLM runtime Inference framework used to run Chandra-OCR-2 efficiently on GPU infrastructure. Chandra-OCR 2, Hugging Face Jobs
L40S parallel jobs Sixteen serverless GPU jobs selected after throughput and cost experiments. Hugging Face Jobs, Hugging Face Buckets
Hugging Face Buckets Mutable Xet-backed storage target for OCR Markdown outputs. OCR job scripts, hf-mount, OCR Markdown bucket
hf-mount Filesystem mount layer that lets job scripts write to Buckets as if they were local directories. Hugging Face Buckets, OCR job scripts
OCR Markdown bucket Merged bucket of OCR-derived Markdown files integrated into Paper Pages. Hugging Face Buckets, Paper Pages, HuggingChat paper chat

Data flow

Paper Pages identify arXiv papers without HTML versions. Codex-generated scripts feed the missing arXiv IDs to Chandra-OCR-2 running with vLLM on Hugging Face Jobs. Sixteen parallel L40S jobs process assigned paper subsets and write Markdown output through hf-mount to Hugging Face Buckets. The 16 buckets are merged into a consolidated bucket, then integrated into Paper Pages. HuggingChat uses the OCR-derived Markdown as paper context for chat-with-paper when the arXiv HTML-to-Markdown path is unavailable.

4 supporting quotes
“about 27,000 papers indexed on Hugging Face do not have a corresponding HTML web page on arXiv”article, stated
“We simply asked OpenAI's Codex model (via the Codex Desktop app) to implement a script”article, stated
“Codex spun up the 16 jobs and monitored their performance.”article, stated
“I then asked it to merge the 16 buckets into a single one.”article, stated

Why this architecture

The team used OCR rather than arXiv HTML because the affected papers lacked HTML pages. They chose Chandra-OCR 2 because it led the relevant open OCR leaderboard and had an OpenRAIL license. They used Hugging Face Jobs because OCR was a finite batch workload suitable for serverless pay-per-second GPUs. They selected L40S by total job cost rather than hourly price, because the cheaper A10G processed fewer papers per hour. Buckets plus hf-mount replaced git-versioned datasets because daily updates would create too many commits and mounted storage removed custom upload/download code.

4 supporting quotes
“making it not possible to chat with those papers. Hence, the idea was pretty simple: let's use an open Optical Character Recognition (OCR) model”article, stated
“we simply decided to use the best model at the time of writing, which is [Chandra-OCR 2]”article, stated
“16x A10G-large is cheaper per hour but slower overall, which would ultimately lead to a larger cost of about $1350.”article, stated
“as local filesystems. This means that we no longer require to write download/upload functionality”article, stated

Models used: OpenAI Codex · Chandra-OCR 2 · vLLM · HuggingChat · OlmOCRBench · Nvidia L40S · Nvidia A10G-large

Scale

Alternatives considered (roads not taken)

Use only arXiv HTML-to-Markdown conversion

Rejected because: About 27,000 Hugging Face indexed papers had no corresponding arXiv HTML page.

“Behind the scenes, this uses the HTML web page of the arXiv paper”article, stated
“about 27,000 papers indexed on Hugging Face do not have a corresponding HTML web page on arXiv”article, stated

Use Chandra's proprietary API

Rejected because: Self-managed Hugging Face Jobs with L40S GPUs were much cheaper in the reported estimate.

“For comparison, I also asked Codex how much this would cost with Chandra's [own API]”article, stated
“$1,841.07 for "fast/balanced" mode and $2,761.60 for "high-accuracy" mode.”article, stated

Run all papers on a single L40S GPU

Rejected because: A single L40S would take multiple weeks, so Codex recommended 16 parallel jobs.

“processing all papers on a single L40S GPU would take multiple weeks.”article, stated
“it recommended to run 16 jobs in parallel”article, stated

Choose the cheaper-per-hour A10G-large instances

Rejected because: A10G was slower enough that total cost would be higher than L40S.

“16x A10G-large is cheaper per hour but slower overall”article, stated
“which would ultimately lead to a larger cost of about $1350.”article, stated

Write OCR results to a Hugging Face dataset

Rejected because: Daily paper additions would create too many git commits, so Buckets were better for mutable storage.

“At first, we would simply let the script write the results to a Hugging Face dataset.”article, stated
“As new papers get added every day, this would result in a huge amount of git commits, hence Buckets are more suited here.”article, stated

Patterns

tool-use-orchestration (agentic-infrastructure)

Codex orchestrated model-card reading, CLI documentation, job-script generation, GPU experiments, job launch, monitoring, storage changes, and bucket merging.

“we can simply point a coding agent such as Claude Code, Cursor or Codex to a set of URLs and it will figure it out by itself.”article, stated
“We simply asked OpenAI's Codex model (via the Codex Desktop app) to implement a script”article, stated

eval-driven-development (model-selection)

The OCR model was selected from OlmOCRBench evaluation results rather than ad-hoc model choice.

“OlmOCRBench by AllenAI is the go-to benchmark for OCR.”article, stated
“we simply decided to use the best model at the time of writing, which is [Chandra-OCR 2]”article, stated

cost-aware-routing (infrastructure)

Codex compared GPU choices and API pricing, then chose 16 L40S jobs because total runtime and cost beat A10G and proprietary API options.

“I first asked Codex to do some comparisons on a small scale (120 papers) to see which GPUs to use and to estimate their costs.”article, stated
“16x A10G-large is cheaper per hour but slower overall, which would ultimately lead to a larger cost of about $1350.”article, stated

batch-offline-processing (document-processing)

The missing papers were processed as a parallel serverless batch workload over 16 GPU jobs and merged afterward.

“Codex spun up the 16 jobs and monitored their performance.”article, stated
“After about a day, all 16 jobs were finished.”article, stated

rag-retrieval (application)

The OCR output became Markdown context for HuggingChat's chat-with-paper feature.

“The HTML gets turned into Markdown, which is then fed to the LLM as context.”article, stated
“now you can chat with any paper on the hub, not just the ones which have an HTML version on arXiv!”article, stated

Tradeoffs

OCR model selection

Chose Chandra-OCR 2 from OlmOCRBench over Manual OCR model trial-and-error.

Rationale: OlmOCRBench provided a relevant benchmark and Chandra-OCR 2 was the top model at the time with a commercial-use license.

“OlmOCRBench by AllenAI is the go-to benchmark for OCR.”article, stated
“As the model is openly available with an OpenRAIL license, we can freely use it for commercial purposes”article, stated

Execution platform

Chose Hugging Face Jobs serverless GPUs over Persistent self-managed GPU cluster.

Rationale: The workload was a finite batch job, and Jobs charged by seconds used across CPU/GPU options.

“Jobs supports both CPUs and GPUs, from an Nvidia T4 all the way to a 8x Nvidia H200s”article, stated
“pay-as-you-go pricing where you only pay for seconds used.”article, stated

GPU choice

Chose 16 L40S parallel jobs over A10G-large jobs or a single L40S.

Rationale: L40S was faster than A10G and 16-way parallelism reduced a multi-week single-GPU run to about 29-30 hours.

“Running 16 parallel jobs would take about 29-30 hours.”article, stated
“processing all papers on a single L40S GPU would take multiple weeks.”article, stated

Storage target

Chose Mounted Buckets over Git-versioned Hugging Face dataset outputs.

Rationale: Buckets were more suitable for fast, cheap, mutable daily paper outputs, and hf-mount removed custom upload/download code.

“Buckets are more suited here.”article, stated
“This means that we no longer require to write download/upload functionality”article, stated

Gotchas (what bit them)

A cheaper GPU per hour can cost more for a finite batch.

Root cause: A10G-large was cheaper hourly but processed fewer papers per hour than L40S.

Resolution: Run a 120-paper experiment and optimize for total workload cost, not hourly rate.

“it was able to process papers faster (about 60/hour when parsing at most 30 pages for each paper compared to 32/hour on the A10G).”article, stated
“16x A10G-large is cheaper per hour but slower overall”article, stated

Git-versioned datasets are a poor fit for frequently updated OCR outputs.

Root cause: New papers are added every day, which would create a huge number of commits.

Resolution: Use Xet-backed Hugging Face Buckets for fast, cheap, mutable storage.

“As new papers get added every day, this would result in a huge amount of git commits”article, stated
“Buckets are not versioned by git, and instead powered by Xet for fast, cheap and mutable storage.”article, stated

Custom upload/download code adds complexity for agent-generated scripts.

Root cause: Remote storage synchronization would otherwise need explicit download/upload implementation.

Resolution: Mount Hugging Face Buckets with hf-mount so scripts write as if to local files.

“we no longer require to write download/upload functionality”article, stated
“the script (or coding agents in general) can just write to the bucket as it it were local.”article, stated

Benchmark-leading OCR does not automatically guarantee downstream chat quality.

Root cause: The source selects by leaderboard but does not report post-OCR user-facing chat quality checks.

Resolution: Use the leaderboard as a selection gate, but treat downstream chat quality as a separate validation need.

“It's a pretty good place to find which open models are best at converting documents into Markdown”article, stated
“The HTML gets turned into Markdown, which is then fed to the LLM as context.”article, stated

Parallel batches can still have uneven completion times.

Root cause: Some assigned papers had more pages to parse than others.

Resolution: Monitor the 16 jobs and wait for all to complete before merging buckets.

“Some jobs took longer than others, mainly because they contained many papers with more pages to parse.”article, stated
“I then asked it to merge the 16 buckets into a single one.”article, stated

Evaluation

The workflow used leaderboard-based OCR model selection, small-scale GPU throughput/cost experiments on 120 papers, job-completion monitoring through Codex, and economic comparison against proprietary API modes. The source does not describe a post-run OCR quality audit beyond the benchmark-driven model choice.

Metrics: OlmOCRBench model rank · 120-paper GPU comparison sample · papers per hour by GPU · parallel job count · estimated runtime · estimated infrastructure cost · API cost comparison · job restart count · completed job count

4 supporting quotes
“OlmOCRBench by AllenAI is the go-to benchmark for OCR.”article, stated
“I first asked Codex to do some comparisons on a small scale (120 papers) to see which GPUs to use and to estimate their costs.”article, stated
“No jobs had to be restarted, they all worked from the first try.”article, stated
“$1,841.07 for "fast/balanced" mode and $2,761.60 for "high-accuracy" mode.”article, stated

Outcomes

The source reports 30,000 OCR'd papers in the title, about 27,000 missing HTML papers, a 120-paper GPU test, L40S throughput around 60 papers/hour versus 32/hour on A10G for up to 30 pages per paper, 16 parallel jobs, about 29-30 hours estimated runtime, about $850 estimated cost, and API comparison costs of $1,841.07 and $2,761.60.

4 supporting quotes
“After about a day, all 16 jobs were finished.”article, stated
“Finally, Mishig integrated them into Paper Pages”article, stated
“now you can chat with any paper on the hub, not just the ones which have an HTML version on arXiv!”article, stated
“Find the code here and the resulting bucket [here]”article, stated