davanstrien HF Staff commited on
Commit
f86231b
·
verified ·
1 Parent(s): 2785476

Sync from GitHub via hub-sync

Browse files
dots-mocr.py CHANGED
@@ -4,15 +4,21 @@
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
7
- # "vllm>=0.15.1",
8
  # "tqdm",
9
  # "toolz",
10
- # "torch",
11
  # # dots.mocr's remote code (AutoProcessor.register with a string key)
12
  # # breaks on transformers v5; vllm pulls transformers unpinned.
 
 
13
  # "transformers<5",
14
  # ]
15
  #
 
 
 
 
 
 
16
  # ///
17
 
18
  """
@@ -37,6 +43,16 @@ SVG variant: rednote-hilab/dots.mocr-svg
37
  vLLM: Officially integrated since v0.11.0
38
  GitHub: https://github.com/rednote-hilab/dots.mocr
39
  Paper: https://arxiv.org/abs/2603.13032
 
 
 
 
 
 
 
 
 
 
40
  """
41
 
42
  import argparse
@@ -565,24 +581,24 @@ if __name__ == "__main__":
565
  print(" general - Free-form (use with --custom-prompt)")
566
  print("\nExample usage:")
567
  print("\n1. Basic OCR:")
568
- print(" uv run dots-mocr.py input-dataset output-dataset")
569
  print("\n2. SVG generation:")
570
  print(
571
- " uv run dots-mocr.py charts svg-output --prompt-mode svg --model rednote-hilab/dots.mocr-svg"
572
  )
573
  print("\n3. Web screen parsing:")
574
- print(" uv run dots-mocr.py screenshots parsed --prompt-mode web-parsing")
575
  print("\n4. Layout analysis with structure:")
576
- print(" uv run dots-mocr.py papers analyzed --prompt-mode layout-all")
577
  print("\n5. Running on HF Jobs:")
578
- print(" hf jobs uv run --flavor l4x1 \\")
579
- print(" -s HF_TOKEN \\")
580
  print(
581
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \\"
582
  )
583
  print(" input-dataset output-dataset")
584
  print("\n" + "=" * 80)
585
- print("\nFor full help, run: uv run dots-mocr.py --help")
586
  sys.exit(0)
587
 
588
  parser = argparse.ArgumentParser(
@@ -606,19 +622,19 @@ SVG Code Generation:
606
 
607
  Examples:
608
  # Basic text OCR (default)
609
- uv run dots-mocr.py my-docs analyzed-docs
610
 
611
  # SVG generation with optimized variant
612
- uv run dots-mocr.py charts svg-out --prompt-mode svg --model rednote-hilab/dots.mocr-svg
613
 
614
  # Web screen parsing
615
- uv run dots-mocr.py screenshots parsed --prompt-mode web-parsing
616
 
617
  # Full layout analysis with structure
618
- uv run dots-mocr.py papers structured --prompt-mode layout-all
619
 
620
  # Random sampling for testing
621
- uv run dots-mocr.py large-dataset test --max-samples 50 --shuffle
622
  """,
623
  )
624
 
 
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
 
7
  # "tqdm",
8
  # "toolz",
 
9
  # # dots.mocr's remote code (AutoProcessor.register with a string key)
10
  # # breaks on transformers v5; vllm pulls transformers unpinned.
11
+ # # Local `uv run --with vllm==...` only: on Jobs the header image's own
12
+ # # transformers wins via PYTHONPATH, so this pin has no effect there.
13
  # "transformers<5",
14
  # ]
15
  #
16
+ # [tool.hf-jobs]
17
+ # image = "vllm/vllm-openai:v0.29.0"
18
+ # python = "/usr/bin/python3"
19
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
20
+ # flavor = "a10g-small"
21
+ # secrets = ["HF_TOKEN"]
22
  # ///
23
 
24
  """
 
43
  vLLM: Officially integrated since v0.11.0
44
  GitHub: https://github.com/rednote-hilab/dots.mocr
45
  Paper: https://arxiv.org/abs/2603.13032
46
+
47
+ Run on HF Jobs (the [tool.hf-jobs] header sets image, flavor and secrets;
48
+ needs the hf CLI 1.32+):
49
+
50
+ hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \
51
+ input-dataset output-dataset
52
+
53
+ On your own GPU, vLLM is not in the dependencies (the Jobs image provides it):
54
+
55
+ uv run --with vllm==0.29.0 dots-mocr.py input-dataset output-dataset
56
  """
57
 
58
  import argparse
 
581
  print(" general - Free-form (use with --custom-prompt)")
582
  print("\nExample usage:")
583
  print("\n1. Basic OCR:")
584
+ print(" uv run --with vllm==0.29.0 dots-mocr.py input-dataset output-dataset")
585
  print("\n2. SVG generation:")
586
  print(
587
+ " uv run --with vllm==0.29.0 dots-mocr.py charts svg-output --prompt-mode svg --model rednote-hilab/dots.mocr-svg"
588
  )
589
  print("\n3. Web screen parsing:")
590
+ print(" uv run --with vllm==0.29.0 dots-mocr.py screenshots parsed --prompt-mode web-parsing")
591
  print("\n4. Layout analysis with structure:")
592
+ print(" uv run --with vllm==0.29.0 dots-mocr.py papers analyzed --prompt-mode layout-all")
593
  print("\n5. Running on HF Jobs:")
594
+ print(" # [tool.hf-jobs] header sets image/flavor/secrets (hf CLI 1.32+)")
595
+ print(" hf jobs uv run \\")
596
  print(
597
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \\"
598
  )
599
  print(" input-dataset output-dataset")
600
  print("\n" + "=" * 80)
601
+ print("\nFor full help, run: uv run --with vllm==0.29.0 dots-mocr.py --help")
602
  sys.exit(0)
603
 
604
  parser = argparse.ArgumentParser(
 
622
 
623
  Examples:
624
  # Basic text OCR (default)
625
+ uv run --with vllm==0.29.0 dots-mocr.py my-docs analyzed-docs
626
 
627
  # SVG generation with optimized variant
628
+ uv run --with vllm==0.29.0 dots-mocr.py charts svg-out --prompt-mode svg --model rednote-hilab/dots.mocr-svg
629
 
630
  # Web screen parsing
631
+ uv run --with vllm==0.29.0 dots-mocr.py screenshots parsed --prompt-mode web-parsing
632
 
633
  # Full layout analysis with structure
634
+ uv run --with vllm==0.29.0 dots-mocr.py papers structured --prompt-mode layout-all
635
 
636
  # Random sampling for testing
637
+ uv run --with vllm==0.29.0 dots-mocr.py large-dataset test --max-samples 50 --shuffle
638
  """,
639
  )
640
 
dots-ocr.py CHANGED
@@ -4,16 +4,22 @@
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
7
- # "vllm>=0.15.1",
8
  # "tqdm",
9
  # "toolz",
10
- # "torch",
11
  # # dots.ocr's remote code (AutoProcessor.register with a string key)
12
  # # breaks on transformers v5; vllm pulls transformers unpinned.
13
  # # Same fix as dots-mocr (#76).
 
 
14
  # "transformers<5",
15
  # ]
16
  #
 
 
 
 
 
 
17
  # ///
18
 
19
  """
@@ -31,6 +37,16 @@ Features:
31
 
32
  Model: rednote-hilab/dots.ocr
33
  vLLM: Officially tested with 0.9.1+ (native support via PR #24645)
 
 
 
 
 
 
 
 
 
 
34
  """
35
 
36
  import argparse
@@ -478,28 +494,25 @@ if __name__ == "__main__":
478
  print("- 📝 Layout-aware text extraction")
479
  print("\nExample usage:")
480
  print("\n1. Basic OCR:")
481
- print(" uv run dots-ocr.py input-dataset output-dataset")
482
  print("\n2. With custom settings:")
483
  print(
484
- " uv run dots-ocr.py docs analyzed-docs --batch-size 20 --max-samples 100"
485
  )
486
  print("\n3. Layout analysis with structure:")
487
  print(
488
- " uv run dots-ocr.py papers analyzed-structure --prompt-mode layout-all"
489
  )
490
  print("\n4. Layout detection only (no text):")
491
- print(" uv run dots-ocr.py docs layout-info --prompt-mode layout-only")
492
- print("\n5. Running on HF Jobs:")
493
- print(" hf jobs uv run --flavor l4x1 \\")
494
- print(
495
- ' -e HF_TOKEN=$(python3 -c "from huggingface_hub import get_token; print(get_token())") \\'
496
- )
497
  print(
498
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-ocr.py \\"
499
  )
500
  print(" input-dataset output-dataset")
501
  print("\n" + "=" * 80)
502
- print("\nFor full help, run: uv run dots-ocr.py --help")
503
  sys.exit(0)
504
 
505
  parser = argparse.ArgumentParser(
@@ -513,13 +526,13 @@ Prompt Modes (official DoTS.ocr prompts):
513
 
514
  Examples:
515
  # Basic text OCR (default)
516
- uv run dots-ocr.py my-docs analyzed-docs
517
 
518
  # Full layout analysis with structure
519
- uv run dots-ocr.py papers structured --prompt-mode layout-all
520
 
521
  # Random sampling for testing
522
- uv run dots-ocr.py large-dataset test --max-samples 50 --shuffle
523
  """,
524
  )
525
 
 
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
 
7
  # "tqdm",
8
  # "toolz",
 
9
  # # dots.ocr's remote code (AutoProcessor.register with a string key)
10
  # # breaks on transformers v5; vllm pulls transformers unpinned.
11
  # # Same fix as dots-mocr (#76).
12
+ # # Local `uv run --with vllm==...` only: on Jobs the header image's own
13
+ # # transformers wins via PYTHONPATH, so this pin has no effect there.
14
  # "transformers<5",
15
  # ]
16
  #
17
+ # [tool.hf-jobs]
18
+ # image = "vllm/vllm-openai:v0.29.0"
19
+ # python = "/usr/bin/python3"
20
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
21
+ # flavor = "a10g-small"
22
+ # secrets = ["HF_TOKEN"]
23
  # ///
24
 
25
  """
 
37
 
38
  Model: rednote-hilab/dots.ocr
39
  vLLM: Officially tested with 0.9.1+ (native support via PR #24645)
40
+
41
+ Run on HF Jobs (the [tool.hf-jobs] header sets image, flavor and secrets;
42
+ needs `hf` CLI 1.32+):
43
+
44
+ hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-ocr.py \\
45
+ input-dataset output-dataset
46
+
47
+ Run on your own GPU (vLLM and torch come from the image on Jobs, so add them):
48
+
49
+ uv run --with vllm==0.29.0 dots-ocr.py input-dataset output-dataset
50
  """
51
 
52
  import argparse
 
494
  print("- 📝 Layout-aware text extraction")
495
  print("\nExample usage:")
496
  print("\n1. Basic OCR:")
497
+ print(" uv run --with vllm==0.29.0 dots-ocr.py input-dataset output-dataset")
498
  print("\n2. With custom settings:")
499
  print(
500
+ " uv run --with vllm==0.29.0 dots-ocr.py docs analyzed-docs --batch-size 20 --max-samples 100"
501
  )
502
  print("\n3. Layout analysis with structure:")
503
  print(
504
+ " uv run --with vllm==0.29.0 dots-ocr.py papers analyzed-structure --prompt-mode layout-all"
505
  )
506
  print("\n4. Layout detection only (no text):")
507
+ print(" uv run --with vllm==0.29.0 dots-ocr.py docs layout-info --prompt-mode layout-only")
508
+ print("\n5. Running on HF Jobs (header sets image/flavor/secrets; hf CLI 1.32+):")
509
+ print(" hf jobs uv run \\")
 
 
 
510
  print(
511
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-ocr.py \\"
512
  )
513
  print(" input-dataset output-dataset")
514
  print("\n" + "=" * 80)
515
+ print("\nFor full help, run: uv run --with vllm==0.29.0 dots-ocr.py --help")
516
  sys.exit(0)
517
 
518
  parser = argparse.ArgumentParser(
 
526
 
527
  Examples:
528
  # Basic text OCR (default)
529
+ uv run --with vllm==0.29.0 dots-ocr.py my-docs analyzed-docs
530
 
531
  # Full layout analysis with structure
532
+ uv run --with vllm==0.29.0 dots-ocr.py papers structured --prompt-mode layout-all
533
 
534
  # Random sampling for testing
535
+ uv run --with vllm==0.29.0 dots-ocr.py large-dataset test --max-samples 50 --shuffle
536
  """,
537
  )
538
 
glm-ocr-bucket.py CHANGED
@@ -13,13 +13,16 @@
13
  # [tool.uv]
14
  # prerelease = "allow"
15
  # override-dependencies = ["transformers>=5.1.0"]
 
 
 
 
16
  # ///
17
 
18
  """
19
  OCR images and PDFs from a directory using GLM-OCR, writing markdown files.
20
 
21
- Designed to work with HF Buckets mounted as volumes via `hf jobs uv run -v ...`
22
- (requires huggingface_hub with PR #3936 volume mounting support).
23
 
24
  The script reads images/PDFs from INPUT_DIR, runs GLM-OCR via vLLM, and writes
25
  one .md file per image (or per PDF page) to OUTPUT_DIR, preserving directory structure.
@@ -36,11 +39,11 @@ Examples:
36
  # Local test
37
  uv run glm-ocr-bucket.py ./test-images ./test-output
38
 
39
- # HF Jobs with bucket volumes (PR #3936)
40
- hf jobs uv run --flavor l4x1 \\
41
- -s HF_TOKEN \\
42
- -v bucket/user/ocr-input:/input:ro \\
43
- -v bucket/user/ocr-output:/output \\
44
  glm-ocr-bucket.py /input /output
45
 
46
  Model: zai-org/GLM-OCR (0.9B, 94.62% OmniDocBench V1.5, MIT licensed)
@@ -102,15 +105,26 @@ def make_ocr_message(image: Image.Image, task: str = "ocr") -> list[dict]:
102
  ]
103
 
104
 
105
- def discover_files(input_dir: Path) -> list[Path]:
106
- """Walk input_dir recursively, returning sorted list of image and PDF files."""
 
 
 
 
 
 
107
  files = []
108
- for path in sorted(input_dir.rglob("*")):
 
 
 
109
  if not path.is_file():
110
  continue
111
  ext = path.suffix.lower()
112
  if ext in IMAGE_EXTENSIONS or ext == ".pdf":
113
  files.append(path)
 
 
114
  return files
115
 
116
 
@@ -175,10 +189,10 @@ Examples:
175
  uv run glm-ocr-bucket.py ./images ./output
176
  uv run glm-ocr-bucket.py /input /output --task table --pdf-dpi 200
177
 
178
- HF Jobs with bucket volumes (requires huggingface_hub PR #3936):
179
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
180
- -v bucket/user/input-bucket:/input:ro \\
181
- -v bucket/user/output-bucket:/output \\
182
  glm-ocr-bucket.py /input /output
183
  """,
184
  )
@@ -232,6 +246,14 @@ HF Jobs with bucket volumes (requires huggingface_hub PR #3936):
232
  default=1.1,
233
  help="Repetition penalty (default: 1.1)",
234
  )
 
 
 
 
 
 
 
 
235
  parser.add_argument(
236
  "--verbose",
237
  action="store_true",
@@ -239,6 +261,8 @@ HF Jobs with bucket volumes (requires huggingface_hub PR #3936):
239
  )
240
 
241
  args = parser.parse_args()
 
 
242
 
243
  check_cuda_availability()
244
 
@@ -254,8 +278,14 @@ HF Jobs with bucket volumes (requires huggingface_hub PR #3936):
254
  # Discover and prepare
255
  start_time = time.time()
256
 
257
- logger.info(f"Scanning {input_dir} for images and PDFs...")
258
- files = discover_files(input_dir)
 
 
 
 
 
 
259
  if not files:
260
  logger.error(f"No image or PDF files found in {input_dir}")
261
  sys.exit(1)
@@ -348,7 +378,7 @@ if __name__ == "__main__":
348
  print("GLM-OCR Bucket Script")
349
  print("=" * 60)
350
  print("\nOCR images/PDFs from a directory → markdown files.")
351
- print("Designed for HF Buckets mounted as volumes (PR #3936).")
352
  print()
353
  print("Usage:")
354
  print(" uv run glm-ocr-bucket.py INPUT_DIR OUTPUT_DIR")
@@ -357,10 +387,11 @@ if __name__ == "__main__":
357
  print(" uv run glm-ocr-bucket.py ./images ./output")
358
  print(" uv run glm-ocr-bucket.py /input /output --task table")
359
  print()
360
- print("HF Jobs with bucket volumes:")
361
- print(" hf jobs uv run --flavor l4x1 -s HF_TOKEN \\")
362
- print(" -v bucket/user/ocr-input:/input:ro \\")
363
- print(" -v bucket/user/ocr-output:/output \\")
 
364
  print(" glm-ocr-bucket.py /input /output")
365
  print()
366
  print("For full help: uv run glm-ocr-bucket.py --help")
 
13
  # [tool.uv]
14
  # prerelease = "allow"
15
  # override-dependencies = ["transformers>=5.1.0"]
16
+ #
17
+ # [tool.hf-jobs]
18
+ # flavor = "a10g-small"
19
+ # secrets = ["HF_TOKEN"]
20
  # ///
21
 
22
  """
23
  OCR images and PDFs from a directory using GLM-OCR, writing markdown files.
24
 
25
+ Designed to work with HF Buckets mounted as volumes via `hf jobs uv run -v ...`.
 
26
 
27
  The script reads images/PDFs from INPUT_DIR, runs GLM-OCR via vLLM, and writes
28
  one .md file per image (or per PDF page) to OUTPUT_DIR, preserving directory structure.
 
39
  # Local test
40
  uv run glm-ocr-bucket.py ./test-images ./test-output
41
 
42
+ # HF Jobs with bucket volumes (flavor + secrets come from the
43
+ # [tool.hf-jobs] header; needs hf CLI 1.32+)
44
+ hf jobs uv run \\
45
+ -v hf://buckets/user/ocr-input:/input:ro \\
46
+ -v hf://buckets/user/ocr-output:/output \\
47
  glm-ocr-bucket.py /input /output
48
 
49
  Model: zai-org/GLM-OCR (0.9B, 94.62% OmniDocBench V1.5, MIT licensed)
 
105
  ]
106
 
107
 
108
+ def discover_files(input_dir: Path, limit: int | None = None) -> list[Path]:
109
+ """Discover image and PDF files under input_dir.
110
+
111
+ Without `limit`, returns the full sorted list (deterministic order).
112
+ With `limit`, stops scanning once `limit` matching files are found
113
+ and returns them in filesystem order (much faster on huge mounted
114
+ buckets, but ordering is not deterministic).
115
+ """
116
  files = []
117
+ iterator = (
118
+ input_dir.rglob("*") if limit is not None else sorted(input_dir.rglob("*"))
119
+ )
120
+ for path in iterator:
121
  if not path.is_file():
122
  continue
123
  ext = path.suffix.lower()
124
  if ext in IMAGE_EXTENSIONS or ext == ".pdf":
125
  files.append(path)
126
+ if limit is not None and len(files) >= limit:
127
+ break
128
  return files
129
 
130
 
 
189
  uv run glm-ocr-bucket.py ./images ./output
190
  uv run glm-ocr-bucket.py /input /output --task table --pdf-dpi 200
191
 
192
+ HF Jobs with bucket volumes (flavor + secrets from the [tool.hf-jobs] header; hf CLI 1.32+):
193
+ hf jobs uv run \\
194
+ -v hf://buckets/user/input-bucket:/input:ro \\
195
+ -v hf://buckets/user/output-bucket:/output \\
196
  glm-ocr-bucket.py /input /output
197
  """,
198
  )
 
246
  default=1.1,
247
  help="Repetition penalty (default: 1.1)",
248
  )
249
+ parser.add_argument(
250
+ "--max-samples",
251
+ type=int,
252
+ default=None,
253
+ help="Limit the number of input files to process (files, not pages; "
254
+ "a PDF still yields all its pages). Stops scanning early once the "
255
+ "limit is reached; file order is then filesystem-dependent.",
256
+ )
257
  parser.add_argument(
258
  "--verbose",
259
  action="store_true",
 
261
  )
262
 
263
  args = parser.parse_args()
264
+ if args.max_samples is not None and args.max_samples < 1:
265
+ parser.error("--max-samples must be 1 or more")
266
 
267
  check_cuda_availability()
268
 
 
278
  # Discover and prepare
279
  start_time = time.time()
280
 
281
+ if args.max_samples is not None:
282
+ logger.info(
283
+ f"Scanning {input_dir} for up to {args.max_samples} images/PDFs "
284
+ f"(early termination, --max-samples)..."
285
+ )
286
+ else:
287
+ logger.info(f"Scanning {input_dir} for images and PDFs...")
288
+ files = discover_files(input_dir, limit=args.max_samples)
289
  if not files:
290
  logger.error(f"No image or PDF files found in {input_dir}")
291
  sys.exit(1)
 
378
  print("GLM-OCR Bucket Script")
379
  print("=" * 60)
380
  print("\nOCR images/PDFs from a directory → markdown files.")
381
+ print("Designed for HF Buckets mounted as volumes.")
382
  print()
383
  print("Usage:")
384
  print(" uv run glm-ocr-bucket.py INPUT_DIR OUTPUT_DIR")
 
387
  print(" uv run glm-ocr-bucket.py ./images ./output")
388
  print(" uv run glm-ocr-bucket.py /input /output --task table")
389
  print()
390
+ print("HF Jobs with bucket volumes (flavor + secrets from the")
391
+ print("[tool.hf-jobs] header; needs hf CLI 1.32+):")
392
+ print(" hf jobs uv run \\")
393
+ print(" -v hf://buckets/user/ocr-input:/input:ro \\")
394
+ print(" -v hf://buckets/user/ocr-output:/output \\")
395
  print(" glm-ocr-bucket.py /input /output")
396
  print()
397
  print("For full help: uv run glm-ocr-bucket.py --help")
lfm2-extract.py CHANGED
@@ -3,12 +3,17 @@
3
  # dependencies = [
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
- # "vllm",
7
  # "transformers",
8
  # "tqdm",
9
  # "toolz",
10
- # "torch",
11
  # ]
 
 
 
 
 
 
 
12
  # ///
13
  """
14
  Extract structured data (JSON / XML / YAML) from text using LiquidAI's LFM2-1.2B-Extract.
@@ -28,18 +33,20 @@ Pass `--schema` as inline text/JSON, a URL, or a file path describing the struct
28
  Model: https://huggingface.co/LiquidAI/LFM2-1.2B-Extract
29
  Docs: https://docs.liquid.ai/deployment/gpu-inference/vllm
30
 
31
- HF Jobs note: run on the vLLM image so the CUDA toolkit + prebuilt FlashInfer kernels are
32
- present and startup is fast (it reuses the image's CUDA-matched vLLM build):
 
33
 
34
- hf jobs uv run --flavor l4x1 --secrets HF_TOKEN \
35
- --image vllm/vllm-openai --python /usr/bin/python3 \
36
- -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \
37
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lfm2-extract.py \
38
  INPUT OUTPUT --text-column text --schema '{"field": "description"}'
39
 
40
- It also runs on the default uv image, just with a slower first-time vLLM build. Deps are left
41
- unpinned so uv resolves a recent vLLM; FlashInfer sampling is disabled (see below) so the engine
42
- never JIT-compiles a kernel that needs nvcc — absent from the default image.
 
 
 
43
  """
44
 
45
  import argparse
@@ -72,7 +79,7 @@ FORMATS = {"json": "JSON", "xml": "XML", "yaml": "YAML"}
72
  def check_cuda_availability() -> None:
73
  if not torch.cuda.is_available():
74
  logger.error("CUDA is not available. This script requires a GPU.")
75
- logger.error("Run on Hugging Face Jobs with: hf jobs uv run --flavor l4x1 ...")
76
  sys.exit(1)
77
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name()}")
78
 
@@ -264,13 +271,15 @@ if __name__ == "__main__":
264
  if len(sys.argv) == 1:
265
  print("LFM2-1.2B-Extract — structured extraction (JSON/XML/YAML) from text")
266
  print("\nUsage:")
267
- print(" uv run lfm2-extract.py INPUT OUTPUT --schema SCHEMA [--text-column text] [--format json]")
268
  print("\nExample:")
269
- print(' uv run lfm2-extract.py my-docs my-fields \\')
270
  print(' --text-column markdown \\')
271
  print(' --schema \'{"title": "the title", "date": "any date", "summary": "one sentence"}\'')
272
  print("\n --schema accepts inline text/JSON, a URL, or a file path.")
273
- print("\nFor full help: uv run lfm2-extract.py --help")
 
 
274
  sys.exit(0)
275
 
276
  parser = argparse.ArgumentParser(
 
3
  # dependencies = [
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
 
6
  # "transformers",
7
  # "tqdm",
8
  # "toolz",
 
9
  # ]
10
+ #
11
+ # [tool.hf-jobs]
12
+ # image = "vllm/vllm-openai:v0.29.0"
13
+ # python = "/usr/bin/python3"
14
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
15
+ # flavor = "a10g-small"
16
+ # secrets = ["HF_TOKEN"]
17
  # ///
18
  """
19
  Extract structured data (JSON / XML / YAML) from text using LiquidAI's LFM2-1.2B-Extract.
 
33
  Model: https://huggingface.co/LiquidAI/LFM2-1.2B-Extract
34
  Docs: https://docs.liquid.ai/deployment/gpu-inference/vllm
35
 
36
+ HF Jobs: the `[tool.hf-jobs]` header above pins the vLLM image (vLLM + torch come from the
37
+ image, not the deps), the GPU flavor and the HF_TOKEN secret, so no flags are needed
38
+ (requires `hf` CLI 1.32+):
39
 
40
+ hf jobs uv run \
 
 
41
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lfm2-extract.py \
42
  INPUT OUTPUT --text-column text --schema '{"field": "description"}'
43
 
44
+ On your own GPU, supply vLLM yourself:
45
+
46
+ uv run --with vllm==0.29.0 lfm2-extract.py INPUT OUTPUT --schema '{"field": "description"}'
47
+
48
+ FlashInfer sampling is disabled (see below) so the engine never JIT-compiles a kernel that
49
+ needs nvcc.
50
  """
51
 
52
  import argparse
 
79
  def check_cuda_availability() -> None:
80
  if not torch.cuda.is_available():
81
  logger.error("CUDA is not available. This script requires a GPU.")
82
+ logger.error("Run on Hugging Face Jobs with: hf jobs uv run lfm2-extract.py ...")
83
  sys.exit(1)
84
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name()}")
85
 
 
271
  if len(sys.argv) == 1:
272
  print("LFM2-1.2B-Extract — structured extraction (JSON/XML/YAML) from text")
273
  print("\nUsage:")
274
+ print(" uv run --with vllm==0.29.0 lfm2-extract.py INPUT OUTPUT --schema SCHEMA [--text-column text] [--format json]")
275
  print("\nExample:")
276
+ print(' uv run --with vllm==0.29.0 lfm2-extract.py my-docs my-fields \\')
277
  print(' --text-column markdown \\')
278
  print(' --schema \'{"title": "the title", "date": "any date", "summary": "one sentence"}\'')
279
  print("\n --schema accepts inline text/JSON, a URL, or a file path.")
280
+ print("\nOn HF Jobs (hf CLI 1.32+; image/flavor/secrets come from the script header):")
281
+ print(" hf jobs uv run lfm2-extract.py INPUT OUTPUT --schema SCHEMA")
282
+ print("\nFor full help: uv run --with vllm==0.29.0 lfm2-extract.py --help")
283
  sys.exit(0)
284
 
285
  parser = argparse.ArgumentParser(
lift-extract.py CHANGED
@@ -8,6 +8,10 @@
8
  # "toolz",
9
  # "tqdm",
10
  # ]
 
 
 
 
11
  # ///
12
  """
13
  Extract structured JSON from document images OR multi-page PDFs using Datalab's
@@ -46,15 +50,19 @@ OpenRAIL-M license — free for research, personal use, and startups under $5M
46
  funding/revenue, but restricted from competitive use against Datalab's API.
47
  Confirm you are within those terms before using it. https://huggingface.co/datalab-to/lift
48
 
49
- HF Jobs — HF backend (default image is fine; 9B needs a roomy GPU):
 
 
50
 
51
- hf jobs uv run --flavor a100-large -s HF_TOKEN \\
52
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lift-extract.py \\
53
  INPUT_DATASET OUTPUT_DATASET \\
54
  --schema '{"type":"object","properties":{"title":{"type":"string"}}}' \\
55
  --max-samples 5 --shuffle --seed 42
56
 
57
- HF Jobs — vLLM offline backend (use the vllm image so vLLM is present):
 
 
58
 
59
  hf jobs uv run --flavor a100-large -s HF_TOKEN \\
60
  --image vllm/vllm-openai --python /usr/bin/python3 \\
@@ -105,7 +113,8 @@ def check_cuda_availability() -> None:
105
  if not torch.cuda.is_available():
106
  logger.error("CUDA is not available. This script requires a GPU.")
107
  logger.error(
108
- "Run on Hugging Face Jobs with: hf jobs uv run --flavor a100-large ..."
 
109
  )
110
  sys.exit(1)
111
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
 
8
  # "toolz",
9
  # "tqdm",
10
  # ]
11
+ #
12
+ # [tool.hf-jobs]
13
+ # flavor = "a100-large"
14
+ # secrets = ["HF_TOKEN"]
15
  # ///
16
  """
17
  Extract structured JSON from document images OR multi-page PDFs using Datalab's
 
50
  funding/revenue, but restricted from competitive use against Datalab's API.
51
  Confirm you are within those terms before using it. https://huggingface.co/datalab-to/lift
52
 
53
+ HF Jobs — HF backend. The [tool.hf-jobs] header above sets the flavor
54
+ (a100-large; 9B needs a roomy GPU) and the HF_TOKEN secret, so no flags are
55
+ needed (requires `hf` CLI 1.32+):
56
 
57
+ hf jobs uv run \\
58
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lift-extract.py \\
59
  INPUT_DATASET OUTPUT_DATASET \\
60
  --schema '{"type":"object","properties":{"title":{"type":"string"}}}' \\
61
  --max-samples 5 --shuffle --seed 42
62
 
63
+ HF Jobs — vLLM offline backend (use the vllm image so vLLM is present). The
64
+ header does not cover this path: pass the image flags explicitly. This path is
65
+ not tested with the header; treat it as unsupported for now:
66
 
67
  hf jobs uv run --flavor a100-large -s HF_TOKEN \\
68
  --image vllm/vllm-openai --python /usr/bin/python3 \\
 
113
  if not torch.cuda.is_available():
114
  logger.error("CUDA is not available. This script requires a GPU.")
115
  logger.error(
116
+ "Run on Hugging Face Jobs with: hf jobs uv run lift-extract.py ... "
117
+ "(the script header sets flavor a100-large; hf CLI 1.32+)"
118
  )
119
  sys.exit(1)
120
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
lighton-ocr2-saturate.py CHANGED
@@ -125,7 +125,8 @@ def main():
125
  ap.add_argument("--split", default="train")
126
  ap.add_argument("--id-column", default=None,
127
  help="Column to use as row id (default: split-index ids)")
128
- ap.add_argument("--limit", type=int, default=None)
 
129
  ap.add_argument("--max-tokens", type=int, default=SERVING["max_tokens"])
130
  ap.add_argument("--temperature", type=float, default=SERVING["temperature"])
131
  ap.add_argument("--target-size", type=int, default=SERVING["target_size"])
 
125
  ap.add_argument("--split", default="train")
126
  ap.add_argument("--id-column", default=None,
127
  help="Column to use as row id (default: split-index ids)")
128
+ ap.add_argument("--max-samples", "--limit", dest="limit", type=int, default=None,
129
+ help="Process at most N rows (same name as the other OCR recipes; --limit still works)")
130
  ap.add_argument("--max-tokens", type=int, default=SERVING["max_tokens"])
131
  ap.add_argument("--temperature", type=float, default=SERVING["temperature"])
132
  ap.add_argument("--target-size", type=int, default=SERVING["target_size"])
nuextract3.py CHANGED
@@ -4,11 +4,16 @@
4
  # "datasets>=3.1.0",
5
  # "huggingface-hub",
6
  # "pillow",
7
- # "vllm",
8
  # "toolz",
9
- # "torch",
10
  # "numind",
11
  # ]
 
 
 
 
 
 
 
12
  # ///
13
 
14
  """
@@ -36,19 +41,16 @@ Modes are selected via flags:
36
  schema can be hosted (e.g. on an HF dataset's raw URL) and reused across jobs:
37
  --template https://huggingface.co/datasets/ORG/REPO/raw/main/card.json
38
 
39
- HF Jobs invocation (recommended): use the vllm/vllm-openai:latest image so the
40
- pre-built CUDA kernels (flashinfer etc.) are reused — the default uv-script
41
- image lacks nvcc and flashinfer's JIT compile fails at engine warmup.
42
 
43
  hf jobs uv run \\
44
- --image vllm/vllm-openai:latest \\
45
- --flavor a100-large \\
46
- --python /usr/bin/python3 \\
47
- -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\
48
- -s HF_TOKEN \\
49
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nuextract3.py \\
50
  INPUT_DATASET OUTPUT_DATASET --max-samples 5 --shuffle --seed 42
51
 
 
 
52
  Model: numind/NuExtract3
53
  License: Apache-2.0
54
  """
@@ -590,28 +592,24 @@ if __name__ == "__main__":
590
  print(" --template / --schema - Image -> JSON shaped like the template")
591
  print("\nExamples:")
592
  print("\n1. Markdown OCR:")
593
- print(" uv run nuextract3.py input-dataset output-dataset")
594
  print("\n2. Structured extraction with an inline template:")
595
- print(" uv run nuextract3.py input output \\")
596
  print(' --template \'{"title": "verbatim-string", "date": "date"}\'')
597
  print("\n3. Structured extraction from a JSON Schema (e.g. Pydantic):")
598
- print(" uv run nuextract3.py input output --schema schema.json")
599
  print("\n (--template / --schema also accept a URL or a local file path)")
600
  print("\n4. Reasoning mode for harder documents:")
601
- print(" uv run nuextract3.py input output --enable-thinking")
602
  print("\n5. Test with 10 samples:")
603
- print(" uv run nuextract3.py large-ds test --max-samples 10 --shuffle")
604
- print("\n6. Running on HF Jobs (use vllm/vllm-openai image for built kernels):")
605
- print(" hf jobs uv run --flavor a100-large \\")
606
- print(" --image vllm/vllm-openai:latest \\")
607
- print(" --python /usr/bin/python3 \\")
608
- print(" -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\")
609
- print(" -s HF_TOKEN \\")
610
  print(
611
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nuextract3.py \\"
612
  )
613
  print(" input-dataset output-dataset --batch-size 16")
614
- print("\nFor full help: uv run nuextract3.py --help")
615
  sys.exit(0)
616
 
617
  parser = argparse.ArgumentParser(
@@ -629,11 +627,11 @@ Modes:
629
  (e.g. Pydantic Model.model_json_schema())
630
 
631
  Examples:
632
- uv run nuextract3.py my-docs analyzed-docs
633
- uv run nuextract3.py receipts extracted \\
634
  --template '{"store": "verbatim-string", "total": "number"}'
635
- uv run nuextract3.py contracts extracted --schema contract_schema.json
636
- uv run nuextract3.py hard-docs out --enable-thinking
637
  """,
638
  )
639
 
 
4
  # "datasets>=3.1.0",
5
  # "huggingface-hub",
6
  # "pillow",
 
7
  # "toolz",
 
8
  # "numind",
9
  # ]
10
+ #
11
+ # [tool.hf-jobs]
12
+ # image = "vllm/vllm-openai:v0.29.0"
13
+ # python = "/usr/bin/python3"
14
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
15
+ # flavor = "a10g-small"
16
+ # secrets = ["HF_TOKEN"]
17
  # ///
18
 
19
  """
 
41
  schema can be hosted (e.g. on an HF dataset's raw URL) and reused across jobs:
42
  --template https://huggingface.co/datasets/ORG/REPO/raw/main/card.json
43
 
44
+ HF Jobs invocation: the [tool.hf-jobs] header above sets the vllm/vllm-openai
45
+ image (vLLM + torch come from the image, with pre-built CUDA kernels), the
46
+ flavor and the HF_TOKEN secret. Needs `hf` CLI 1.32+.
47
 
48
  hf jobs uv run \\
 
 
 
 
 
49
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nuextract3.py \\
50
  INPUT_DATASET OUTPUT_DATASET --max-samples 5 --shuffle --seed 42
51
 
52
+ On your own GPU: uv run --with vllm==0.29.0 nuextract3.py INPUT_DATASET OUTPUT_DATASET
53
+
54
  Model: numind/NuExtract3
55
  License: Apache-2.0
56
  """
 
592
  print(" --template / --schema - Image -> JSON shaped like the template")
593
  print("\nExamples:")
594
  print("\n1. Markdown OCR:")
595
+ print(" uv run --with vllm==0.29.0 nuextract3.py input-dataset output-dataset")
596
  print("\n2. Structured extraction with an inline template:")
597
+ print(" uv run --with vllm==0.29.0 nuextract3.py input output \\")
598
  print(' --template \'{"title": "verbatim-string", "date": "date"}\'')
599
  print("\n3. Structured extraction from a JSON Schema (e.g. Pydantic):")
600
+ print(" uv run --with vllm==0.29.0 nuextract3.py input output --schema schema.json")
601
  print("\n (--template / --schema also accept a URL or a local file path)")
602
  print("\n4. Reasoning mode for harder documents:")
603
+ print(" uv run --with vllm==0.29.0 nuextract3.py input output --enable-thinking")
604
  print("\n5. Test with 10 samples:")
605
+ print(" uv run --with vllm==0.29.0 nuextract3.py large-ds test --max-samples 10 --shuffle")
606
+ print("\n6. Running on HF Jobs (image/flavor/secrets from the script header, hf 1.32+):")
607
+ print(" hf jobs uv run \\")
 
 
 
 
608
  print(
609
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nuextract3.py \\"
610
  )
611
  print(" input-dataset output-dataset --batch-size 16")
612
+ print("\nFor full help: uv run --with vllm==0.29.0 nuextract3.py --help")
613
  sys.exit(0)
614
 
615
  parser = argparse.ArgumentParser(
 
627
  (e.g. Pydantic Model.model_json_schema())
628
 
629
  Examples:
630
+ uv run --with vllm==0.29.0 nuextract3.py my-docs analyzed-docs
631
+ uv run --with vllm==0.29.0 nuextract3.py receipts extracted \\
632
  --template '{"store": "verbatim-string", "total": "number"}'
633
+ uv run --with vllm==0.29.0 nuextract3.py contracts extracted --schema contract_schema.json
634
+ uv run --with vllm==0.29.0 nuextract3.py hard-docs out --enable-thinking
635
  """,
636
  )
637
 
olmocr2-vllm.py CHANGED
@@ -4,13 +4,17 @@
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
7
- # "vllm",
8
  # "tqdm",
9
  # "toolz",
10
- # "torch",
11
  # "pyyaml", # For parsing YAML front matter
12
  # ]
13
  #
 
 
 
 
 
 
14
  # ///
15
 
16
  """
@@ -30,6 +34,13 @@ Features:
30
 
31
  Model: allenai/olmOCR-2-7B-1025-FP8
32
  Based on: Qwen2.5-VL-7B-Instruct fine-tuned on olmOCR-mix
 
 
 
 
 
 
 
33
  """
34
 
35
  import argparse
@@ -265,15 +276,14 @@ Each row contains:
265
  ## Reproduction
266
 
267
  ```bash
268
- # Using HF Jobs (recommended)
269
- hf jobs uv run --flavor l4x1 \\
270
- -s HF_TOKEN \\
271
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
272
  {source_dataset} \\
273
  your-username/output-dataset
274
 
275
  # Local with GPU
276
- uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
277
  {source_dataset} \\
278
  your-username/output-dataset
279
  ```
@@ -551,32 +561,30 @@ if __name__ == "__main__":
551
  Examples:
552
 
553
  1. Basic OCR on a dataset:
554
- uv run olmocr2-vllm.py input-dataset output-dataset
555
 
556
  2. Test with first 10 samples:
557
- uv run olmocr2-vllm.py input-dataset output-dataset --max-samples 10
558
 
559
  3. Process with custom batch size:
560
- uv run olmocr2-vllm.py input-dataset output-dataset --batch-size 8
561
 
562
  4. Custom image column:
563
- uv run olmocr2-vllm.py input-dataset output-dataset --image-column page_image
564
 
565
  5. Private output dataset:
566
- uv run olmocr2-vllm.py input-dataset output-dataset --private
567
 
568
  6. Random sampling:
569
- uv run olmocr2-vllm.py input-dataset output-dataset --max-samples 100 --shuffle
570
 
571
- 7. Running on HuggingFace Jobs:
572
- hf jobs uv run --flavor l4x1 \\
573
- -s HF_TOKEN \\
574
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
575
  input-dataset output-dataset
576
 
577
  8. Real example with historical documents:
578
- hf jobs uv run --flavor l4x1 \\
579
- -s HF_TOKEN \\
580
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
581
  NationalLibraryOfScotland/Britain-and-UK-Handbooks-Dataset \\
582
  your-username/handbooks-olmocr \\
 
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
 
7
  # "tqdm",
8
  # "toolz",
 
9
  # "pyyaml", # For parsing YAML front matter
10
  # ]
11
  #
12
+ # [tool.hf-jobs]
13
+ # image = "vllm/vllm-openai:v0.29.0"
14
+ # python = "/usr/bin/python3"
15
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
16
+ # flavor = "a10g-small"
17
+ # secrets = ["HF_TOKEN"]
18
  # ///
19
 
20
  """
 
34
 
35
  Model: allenai/olmOCR-2-7B-1025-FP8
36
  Based on: Qwen2.5-VL-7B-Instruct fine-tuned on olmOCR-mix
37
+
38
+ Run on HF Jobs (the [tool.hf-jobs] header sets image, flavor and secrets;
39
+ needs `hf` CLI 1.32+):
40
+ hf jobs uv run olmocr2-vllm.py input-dataset output-dataset
41
+
42
+ Run on your own GPU (vLLM and torch come from the Jobs image, so add vLLM):
43
+ uv run --with vllm==0.29.0 olmocr2-vllm.py input-dataset output-dataset
44
  """
45
 
46
  import argparse
 
276
  ## Reproduction
277
 
278
  ```bash
279
+ # Using HF Jobs (recommended; the script header sets image/flavor/secrets, hf CLI 1.32+)
280
+ hf jobs uv run \\
 
281
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
282
  {source_dataset} \\
283
  your-username/output-dataset
284
 
285
  # Local with GPU
286
+ uv run --with vllm==0.29.0 https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
287
  {source_dataset} \\
288
  your-username/output-dataset
289
  ```
 
561
  Examples:
562
 
563
  1. Basic OCR on a dataset:
564
+ uv run --with vllm==0.29.0 olmocr2-vllm.py input-dataset output-dataset
565
 
566
  2. Test with first 10 samples:
567
+ uv run --with vllm==0.29.0 olmocr2-vllm.py input-dataset output-dataset --max-samples 10
568
 
569
  3. Process with custom batch size:
570
+ uv run --with vllm==0.29.0 olmocr2-vllm.py input-dataset output-dataset --batch-size 8
571
 
572
  4. Custom image column:
573
+ uv run --with vllm==0.29.0 olmocr2-vllm.py input-dataset output-dataset --image-column page_image
574
 
575
  5. Private output dataset:
576
+ uv run --with vllm==0.29.0 olmocr2-vllm.py input-dataset output-dataset --private
577
 
578
  6. Random sampling:
579
+ uv run --with vllm==0.29.0 olmocr2-vllm.py input-dataset output-dataset --max-samples 100 --shuffle
580
 
581
+ 7. Running on HuggingFace Jobs (header sets image/flavor/secrets; hf CLI 1.32+):
582
+ hf jobs uv run \\
 
583
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
584
  input-dataset output-dataset
585
 
586
  8. Real example with historical documents:
587
+ hf jobs uv run --timeout 2h \\
 
588
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \\
589
  NationalLibraryOfScotland/Britain-and-UK-Handbooks-Dataset \\
590
  your-username/handbooks-olmocr \\
ovis-ocr2-saturate.py CHANGED
@@ -6,7 +6,7 @@
6
  # ]
7
  #
8
  # [tool.hf-jobs]
9
- # image = "vllm/vllm-openai:latest"
10
  # flavor = "a10g-small"
11
  # secrets = ["HF_TOKEN"]
12
  # ///
@@ -35,6 +35,10 @@ secret (`hf` CLI 1.32+). Pass --timeout for a long run; flags override the heade
35
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/ovis-ocr2-saturate.py \\
36
  <input-dataset> <output-dataset>
37
 
 
 
 
 
38
  Output layout (differs from the -server recipe, which pushes input+markdown):
39
  the output repo holds `data/part-*.parquet` with rows
40
  `{id, markdown, model, prompt_tokens, completion_tokens, error}` keyed by the
@@ -78,7 +82,7 @@ import sys
78
  # Throughput receipt (a10g-small, 20 pages): 4,057 tok/s, window ramped to 32.
79
  SERVING = {
80
  "model": "ATH-MaaS/OvisOCR2",
81
- "image": "vllm/vllm-openai:latest",
82
  "max_model_len": 32768,
83
  "serve_args": [
84
  "--limit-mm-per-prompt", '{"image": 1}',
@@ -183,7 +187,8 @@ def main():
183
  ap.add_argument("--split", default="train")
184
  ap.add_argument("--id-column", default=None,
185
  help="Column to use as row id (default: split-index ids)")
186
- ap.add_argument("--limit", type=int, default=None)
 
187
  ap.add_argument("--max-tokens", type=int, default=SERVING["max_tokens"])
188
  ap.add_argument("--keep-image-tags", action="store_true",
189
  help="Keep the bbox <img> placeholder blocks in the output")
 
6
  # ]
7
  #
8
  # [tool.hf-jobs]
9
+ # image = "vllm/vllm-openai:v0.22.1"
10
  # flavor = "a10g-small"
11
  # secrets = ["HF_TOKEN"]
12
  # ///
 
35
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/ovis-ocr2-saturate.py \\
36
  <input-dataset> <output-dataset>
37
 
38
+ Smoke test first with --max-samples 3. On your own GPU (vllm on PATH):
39
+
40
+ uv run --with vllm==0.22.1 ovis-ocr2-saturate.py <input-dataset> <output-dataset>
41
+
42
  Output layout (differs from the -server recipe, which pushes input+markdown):
43
  the output repo holds `data/part-*.parquet` with rows
44
  `{id, markdown, model, prompt_tokens, completion_tokens, error}` keyed by the
 
82
  # Throughput receipt (a10g-small, 20 pages): 4,057 tok/s, window ramped to 32.
83
  SERVING = {
84
  "model": "ATH-MaaS/OvisOCR2",
85
+ "image": "vllm/vllm-openai:v0.22.1",
86
  "max_model_len": 32768,
87
  "serve_args": [
88
  "--limit-mm-per-prompt", '{"image": 1}',
 
187
  ap.add_argument("--split", default="train")
188
  ap.add_argument("--id-column", default=None,
189
  help="Column to use as row id (default: split-index ids)")
190
+ ap.add_argument("--max-samples", "--limit", dest="limit", type=int, default=None,
191
+ help="Process only the first N rows (smoke test)")
192
  ap.add_argument("--max-tokens", type=int, default=SERVING["max_tokens"])
193
  ap.add_argument("--keep-image-tags", action="store_true",
194
  help="Keep the bbox <img> placeholder blocks in the output")
ovis-ocr2.py CHANGED
@@ -4,10 +4,15 @@
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
7
- # "vllm>=0.22.1",
8
  # "toolz",
9
- # "torch",
10
  # ]
 
 
 
 
 
 
 
11
  # ///
12
 
13
  """
@@ -24,6 +29,16 @@ Model: ATH-MaaS/OvisOCR2 (Apache-2.0)
24
  vLLM: stock Qwen3_5ForConditionalGeneration arch, in stable vLLM >= 0.22.1
25
  (the version the model card installs); no trust_remote_code needed.
26
 
 
 
 
 
 
 
 
 
 
 
27
  Features:
28
  - 0.9B parameters (ultra-compact, runs on l4x1)
29
  - Markdown output with LaTeX formulas + HTML tables
@@ -525,20 +540,19 @@ if __name__ == "__main__":
525
  print(" - Visual-region <img> tags filtered by default")
526
  print(" (--keep-image-tags to retain them)")
527
  print("\nExamples:")
528
- print("\n1. Basic OCR:")
529
- print(" uv run ovis-ocr2.py input-dataset output-dataset")
530
  print("\n2. Keep visual-region image tags:")
531
- print(" uv run ovis-ocr2.py docs results --keep-image-tags")
532
  print("\n3. Test with small sample:")
533
- print(" uv run ovis-ocr2.py large-dataset test --max-samples 10 --shuffle")
534
- print("\n4. Running on HF Jobs:")
535
- print(" hf jobs uv run --flavor l4x1 \\")
536
- print(" -s HF_TOKEN \\")
537
  print(
538
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/ovis-ocr2.py \\"
539
  )
540
  print(" input-dataset output-dataset --batch-size 16")
541
- print("\nFor full help: uv run ovis-ocr2.py --help")
542
  sys.exit(0)
543
 
544
  parser = argparse.ArgumentParser(
@@ -546,9 +560,9 @@ if __name__ == "__main__":
546
  formatter_class=argparse.RawDescriptionHelpFormatter,
547
  epilog="""
548
  Examples:
549
- uv run ovis-ocr2.py my-docs analyzed-docs
550
- uv run ovis-ocr2.py docs results --keep-image-tags
551
- uv run ovis-ocr2.py large-dataset test --max-samples 50 --shuffle
552
  """,
553
  )
554
 
 
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
 
7
  # "toolz",
 
8
  # ]
9
+ #
10
+ # [tool.hf-jobs]
11
+ # image = "vllm/vllm-openai:v0.29.0"
12
+ # python = "/usr/bin/python3"
13
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
14
+ # flavor = "a10g-small"
15
+ # secrets = ["HF_TOKEN"]
16
  # ///
17
 
18
  """
 
29
  vLLM: stock Qwen3_5ForConditionalGeneration arch, in stable vLLM >= 0.22.1
30
  (the version the model card installs); no trust_remote_code needed.
31
 
32
+ Run on HF Jobs (needs `hf` CLI 1.32+; the [tool.hf-jobs] header above sets the
33
+ vllm/vllm-openai:v0.29.0 image, a10g-small flavor and HF_TOKEN secret):
34
+
35
+ hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/ovis-ocr2.py \\
36
+ input-dataset output-dataset --batch-size 16
37
+
38
+ Run on your own GPU (vLLM and torch come from the image on Jobs, so add them here):
39
+
40
+ uv run --with vllm==0.29.0 ovis-ocr2.py input-dataset output-dataset
41
+
42
  Features:
43
  - 0.9B parameters (ultra-compact, runs on l4x1)
44
  - Markdown output with LaTeX formulas + HTML tables
 
540
  print(" - Visual-region <img> tags filtered by default")
541
  print(" (--keep-image-tags to retain them)")
542
  print("\nExamples:")
543
+ print("\n1. Basic OCR (own GPU):")
544
+ print(" uv run --with vllm==0.29.0 ovis-ocr2.py input-dataset output-dataset")
545
  print("\n2. Keep visual-region image tags:")
546
+ print(" uv run --with vllm==0.29.0 ovis-ocr2.py docs results --keep-image-tags")
547
  print("\n3. Test with small sample:")
548
+ print(" uv run --with vllm==0.29.0 ovis-ocr2.py large-dataset test --max-samples 10 --shuffle")
549
+ print("\n4. Running on HF Jobs (hf CLI 1.32+; image/flavor/secrets from the script header):")
550
+ print(" hf jobs uv run \\")
 
551
  print(
552
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/ovis-ocr2.py \\"
553
  )
554
  print(" input-dataset output-dataset --batch-size 16")
555
+ print("\nFor full help: uv run --with vllm==0.29.0 ovis-ocr2.py --help")
556
  sys.exit(0)
557
 
558
  parser = argparse.ArgumentParser(
 
560
  formatter_class=argparse.RawDescriptionHelpFormatter,
561
  epilog="""
562
  Examples:
563
+ uv run --with vllm==0.29.0 ovis-ocr2.py my-docs analyzed-docs
564
+ uv run --with vllm==0.29.0 ovis-ocr2.py docs results --keep-image-tags
565
+ uv run --with vllm==0.29.0 ovis-ocr2.py large-dataset test --max-samples 50 --shuffle
566
  """,
567
  )
568
 
paddleocr-vl-1.6.py CHANGED
@@ -4,13 +4,17 @@
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
7
- # "vllm>=0.15.1",
8
  # "tqdm",
9
  # "toolz",
10
- # "torch",
11
  # "pyarrow",
12
- # "transformers",
13
  # ]
 
 
 
 
 
 
 
14
  # ///
15
 
16
  """
@@ -34,14 +38,12 @@ Features:
34
  Model: PaddlePaddle/PaddleOCR-VL-1.6
35
  Backend: vLLM offline (batch inference)
36
 
37
- HF Jobs note: PaddleOCR-VL-1.6 is supported by stable vLLM, but on HF Jobs you must run
38
- with the pre-built vLLM image so flashinfer's CUDA kernels are reused. The default
39
- uv-script image has the CUDA runtime but no `nvcc`, so vLLM's flashinfer sampler crashes
40
- at warmup with "Could not find nvcc". Use image-mode (see the example at the bottom):
41
- --image vllm/vllm-openai:latest --flavor a100-large
42
- --python /usr/bin/python3 -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages
43
- This is the same image-mode pattern as nuextract3.py. Verified end-to-end on a100-large
44
- (2026-06-01): 5/5 clean markdown on davanstrien/ufo-ColPali, ~194 tok/s, 0 errors.
45
  """
46
 
47
  import argparse
@@ -338,13 +340,10 @@ for info in inference_info:
338
  ## Reproduction
339
 
340
  This dataset was generated using the [uv-scripts/ocr](https://huggingface.co/datasets/uv-scripts/ocr) PaddleOCR-VL-1.6 script.
341
- On HF Jobs, run with the pre-built vLLM image (image-mode) so flashinfer kernels are reused:
342
 
343
  ```bash
344
  hf jobs uv run \\
345
- --image vllm/vllm-openai:latest --flavor a100-large \\
346
- --python /usr/bin/python3 -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\
347
- -s HF_TOKEN \\
348
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.6.py \\
349
  {source_dataset} \\
350
  <output-dataset> \\
@@ -459,12 +458,8 @@ def main(
459
  except Exception as e:
460
  logger.error(f"Failed to initialize PaddleOCR-VL-1.6 with vLLM: {e}")
461
  logger.error(
462
- "On HF Jobs, run with the pre-built vLLM image so flashinfer kernels are "
463
- "reused (the default uv-script image has no nvcc):"
464
- )
465
- logger.error(
466
- " --image vllm/vllm-openai:latest --flavor a100-large "
467
- "--python /usr/bin/python3 -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages"
468
  )
469
  sys.exit(1)
470
 
@@ -649,32 +644,26 @@ if __name__ == "__main__":
649
  print(f" {mode:8} - {description}")
650
  print("\nExample usage:")
651
  print("\n1. Basic OCR (default mode):")
652
- print(" uv run paddleocr-vl-1.6.py input-dataset output-dataset")
653
  print("\n2. Table extraction:")
654
- print(" uv run paddleocr-vl-1.6.py docs tables-extracted --task-mode table")
655
  print("\n3. Formula recognition:")
656
  print(
657
- " uv run paddleocr-vl-1.6.py papers formulas --task-mode formula --batch-size 32"
658
  )
659
  print("\n4. Chart analysis:")
660
- print(" uv run paddleocr-vl-1.6.py diagrams charts-analyzed --task-mode chart")
661
  print("\n5. Test with small sample:")
662
- print(" uv run paddleocr-vl-1.6.py dataset test --max-samples 10 --shuffle")
663
- print("\n6. Running on HF Jobs (image-mode required — see note below):")
664
  print(" hf jobs uv run \\")
665
- print(" --image vllm/vllm-openai:latest --flavor a100-large \\")
666
- print(
667
- " --python /usr/bin/python3 -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\"
668
- )
669
- print(" -s HF_TOKEN \\")
670
  print(
671
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.6.py \\"
672
  )
673
  print(" input-dataset output-dataset --task-mode ocr")
674
- print("\n NOTE: the default uv-script image has no nvcc, so vLLM's flashinfer")
675
- print(" sampler crashes at warmup. The vllm/vllm-openai image ships the kernels.")
676
  print("\n" + "=" * 80)
677
- print("\nFor full help, run: uv run paddleocr-vl-1.6.py --help")
678
  sys.exit(0)
679
 
680
  parser = argparse.ArgumentParser(
@@ -691,22 +680,22 @@ Task Modes:
691
 
692
  Examples:
693
  # Basic text OCR
694
- uv run paddleocr-vl-1.6.py my-docs analyzed-docs
695
 
696
  # Extract tables from documents
697
- uv run paddleocr-vl-1.6.py papers tables --task-mode table
698
 
699
  # Recognize mathematical formulas
700
- uv run paddleocr-vl-1.6.py textbooks formulas --task-mode formula
701
 
702
  # Analyze charts and diagrams
703
- uv run paddleocr-vl-1.6.py reports charts --task-mode chart
704
 
705
  # Test with random sampling
706
- uv run paddleocr-vl-1.6.py large-dataset test --max-samples 50 --shuffle --task-mode ocr
707
 
708
  # Disable smart resize for original resolution
709
- uv run paddleocr-vl-1.6.py images output --no-smart-resize
710
  """,
711
  )
712
 
 
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
 
7
  # "tqdm",
8
  # "toolz",
 
9
  # "pyarrow",
 
10
  # ]
11
+ #
12
+ # [tool.hf-jobs]
13
+ # image = "vllm/vllm-openai:v0.29.0"
14
+ # python = "/usr/bin/python3"
15
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
16
+ # flavor = "a10g-small"
17
+ # secrets = ["HF_TOKEN"]
18
  # ///
19
 
20
  """
 
38
  Model: PaddlePaddle/PaddleOCR-VL-1.6
39
  Backend: vLLM offline (batch inference)
40
 
41
+ HF Jobs: the [tool.hf-jobs] header above pins the image (vllm/vllm-openai:v0.29.0),
42
+ python, PYTHONPATH, flavor (a10g-small) and HF_TOKEN secret, so no launch flags are
43
+ needed (requires `hf` CLI 1.32+):
44
+ hf jobs uv run paddleocr-vl-1.6.py input-dataset output-dataset
45
+ In image mode the image's vLLM/torch win over the venv copies via PYTHONPATH.
46
+ On your own GPU: uv run --with vllm==0.29.0 paddleocr-vl-1.6.py input-dataset output-dataset
 
 
47
  """
48
 
49
  import argparse
 
340
  ## Reproduction
341
 
342
  This dataset was generated using the [uv-scripts/ocr](https://huggingface.co/datasets/uv-scripts/ocr) PaddleOCR-VL-1.6 script.
343
+ On HF Jobs (`hf` CLI 1.32+; the script's [tool.hf-jobs] header sets image, flavor and secrets):
344
 
345
  ```bash
346
  hf jobs uv run \\
 
 
 
347
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.6.py \\
348
  {source_dataset} \\
349
  <output-dataset> \\
 
458
  except Exception as e:
459
  logger.error(f"Failed to initialize PaddleOCR-VL-1.6 with vLLM: {e}")
460
  logger.error(
461
+ "On HF Jobs, use `hf` CLI 1.32+ so the script's [tool.hf-jobs] header "
462
+ "(vllm/vllm-openai image) applies; the default uv-script image has no nvcc."
 
 
 
 
463
  )
464
  sys.exit(1)
465
 
 
644
  print(f" {mode:8} - {description}")
645
  print("\nExample usage:")
646
  print("\n1. Basic OCR (default mode):")
647
+ print(" uv run --with vllm==0.29.0 paddleocr-vl-1.6.py input-dataset output-dataset")
648
  print("\n2. Table extraction:")
649
+ print(" uv run --with vllm==0.29.0 paddleocr-vl-1.6.py docs tables-extracted --task-mode table")
650
  print("\n3. Formula recognition:")
651
  print(
652
+ " uv run --with vllm==0.29.0 paddleocr-vl-1.6.py papers formulas --task-mode formula --batch-size 32"
653
  )
654
  print("\n4. Chart analysis:")
655
+ print(" uv run --with vllm==0.29.0 paddleocr-vl-1.6.py diagrams charts-analyzed --task-mode chart")
656
  print("\n5. Test with small sample:")
657
+ print(" uv run --with vllm==0.29.0 paddleocr-vl-1.6.py dataset test --max-samples 10 --shuffle")
658
+ print("\n6. Running on HF Jobs (hf CLI 1.32+; header sets image/flavor/secrets):")
659
  print(" hf jobs uv run \\")
 
 
 
 
 
660
  print(
661
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.6.py \\"
662
  )
663
  print(" input-dataset output-dataset --task-mode ocr")
664
+ print("\n NOTE: the [tool.hf-jobs] header pins vllm/vllm-openai:v0.29.0 on a10g-small.")
 
665
  print("\n" + "=" * 80)
666
+ print("\nFor full help, run: uv run --with vllm==0.29.0 paddleocr-vl-1.6.py --help")
667
  sys.exit(0)
668
 
669
  parser = argparse.ArgumentParser(
 
680
 
681
  Examples:
682
  # Basic text OCR
683
+ uv run --with vllm==0.29.0 paddleocr-vl-1.6.py my-docs analyzed-docs
684
 
685
  # Extract tables from documents
686
+ uv run --with vllm==0.29.0 paddleocr-vl-1.6.py papers tables --task-mode table
687
 
688
  # Recognize mathematical formulas
689
+ uv run --with vllm==0.29.0 paddleocr-vl-1.6.py textbooks formulas --task-mode formula
690
 
691
  # Analyze charts and diagrams
692
+ uv run --with vllm==0.29.0 paddleocr-vl-1.6.py reports charts --task-mode chart
693
 
694
  # Test with random sampling
695
+ uv run --with vllm==0.29.0 paddleocr-vl-1.6.py large-dataset test --max-samples 50 --shuffle --task-mode ocr
696
 
697
  # Disable smart resize for original resolution
698
+ uv run --with vllm==0.29.0 paddleocr-vl-1.6.py images output --no-smart-resize
699
  """,
700
  )
701
 
pp-doclayout.py CHANGED
@@ -28,6 +28,10 @@
28
  #
29
  # [tool.uv.sources]
30
  # paddlepaddle-gpu = { index = "paddle" }
 
 
 
 
31
  # ///
32
 
33
  """
@@ -51,22 +55,22 @@ Output schema (column `layout` is a JSON string):
51
 
52
  Coordinates are in the original input-image pixel space.
53
 
54
- Example commands:
55
 
56
- # Dataset -> dataset (smoke on L4)
57
- hf jobs uv run --flavor l4x1 -s HF_TOKEN https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
58
  davanstrien/ufo-ColPali pp-doclayout-smoke \\
59
  --max-samples 3 --shuffle --seed 42 --private
60
 
61
  # Dataset -> bucket (incremental shards, resumable)
62
  hf buckets create davanstrien/pp-doclayout-scratch --exist-ok
63
- hf jobs uv run --flavor l4x1 -s HF_TOKEN https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
64
  davanstrien/ufo-ColPali \\
65
  hf://buckets/davanstrien/pp-doclayout-scratch/run1 \\
66
  --max-samples 20 --shard-size 5
67
 
68
  # Bucket of images -> dataset
69
- hf jobs uv run --flavor l4x1 -s HF_TOKEN https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
70
  hf://buckets/davanstrien/pp-doclayout-images \\
71
  pp-doclayout-from-bucket --private
72
  """
@@ -840,7 +844,7 @@ for det in detections:
840
  ## Reproduction
841
 
842
  ```bash
843
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
844
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
845
  {source} <output> --model-name {model_name}
846
  ```
@@ -1078,13 +1082,13 @@ def _print_usage_banner() -> None:
1078
  print(" - HF bucket (incremental shards, resumable):")
1079
  print(" hf://buckets/namespace/bucket/run-name")
1080
  print("\nExamples:")
1081
- print("\n # Smoke test on L4 (dataset -> dataset)")
1082
- print(" hf jobs uv run --flavor l4x1 -s HF_TOKEN https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\")
1083
  print(" davanstrien/ufo-ColPali pp-doclayout-smoke \\")
1084
  print(" --max-samples 3 --shuffle --seed 42 --private")
1085
  print("\n # Dataset -> bucket (incremental shards)")
1086
  print(
1087
- " hf jobs uv run --flavor l4x1 -s HF_TOKEN https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\"
1088
  )
1089
  print(" davanstrien/ufo-ColPali \\")
1090
  print(
@@ -1093,7 +1097,7 @@ def _print_usage_banner() -> None:
1093
  print(" --max-samples 20 --shard-size 5")
1094
  print("\n # Bucket of images -> dataset")
1095
  print(
1096
- " hf jobs uv run --flavor l4x1 -s HF_TOKEN https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\"
1097
  )
1098
  print(
1099
  " hf://buckets/davanstrien/pp-doclayout-images \\"
 
28
  #
29
  # [tool.uv.sources]
30
  # paddlepaddle-gpu = { index = "paddle" }
31
+ #
32
+ # [tool.hf-jobs]
33
+ # flavor = "t4-small"
34
+ # secrets = ["HF_TOKEN"]
35
  # ///
36
 
37
  """
 
55
 
56
  Coordinates are in the original input-image pixel space.
57
 
58
+ Example commands (the [tool.hf-jobs] header sets flavor + secrets; needs `hf` CLI 1.32+):
59
 
60
+ # Dataset -> dataset (smoke test)
61
+ hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
62
  davanstrien/ufo-ColPali pp-doclayout-smoke \\
63
  --max-samples 3 --shuffle --seed 42 --private
64
 
65
  # Dataset -> bucket (incremental shards, resumable)
66
  hf buckets create davanstrien/pp-doclayout-scratch --exist-ok
67
+ hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
68
  davanstrien/ufo-ColPali \\
69
  hf://buckets/davanstrien/pp-doclayout-scratch/run1 \\
70
  --max-samples 20 --shard-size 5
71
 
72
  # Bucket of images -> dataset
73
+ hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
74
  hf://buckets/davanstrien/pp-doclayout-images \\
75
  pp-doclayout-from-bucket --private
76
  """
 
844
  ## Reproduction
845
 
846
  ```bash
847
+ hf jobs uv run \\
848
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\
849
  {source} <output> --model-name {model_name}
850
  ```
 
1082
  print(" - HF bucket (incremental shards, resumable):")
1083
  print(" hf://buckets/namespace/bucket/run-name")
1084
  print("\nExamples:")
1085
+ print("\n # Smoke test (dataset -> dataset; header needs hf CLI 1.32+)")
1086
+ print(" hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\")
1087
  print(" davanstrien/ufo-ColPali pp-doclayout-smoke \\")
1088
  print(" --max-samples 3 --shuffle --seed 42 --private")
1089
  print("\n # Dataset -> bucket (incremental shards)")
1090
  print(
1091
+ " hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\"
1092
  )
1093
  print(" davanstrien/ufo-ColPali \\")
1094
  print(
 
1097
  print(" --max-samples 20 --shard-size 5")
1098
  print("\n # Bucket of images -> dataset")
1099
  print(
1100
+ " hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-doclayout.py \\"
1101
  )
1102
  print(
1103
  " hf://buckets/davanstrien/pp-doclayout-images \\"
pp-ocrv6.py CHANGED
@@ -29,6 +29,10 @@
29
  #
30
  # [tool.uv.sources]
31
  # paddlepaddle-gpu = { index = "paddle" }
 
 
 
 
32
  # ///
33
  """
34
  OCR images with PP-OCRv6 — a lightweight detection+recognition pipeline from
@@ -46,16 +50,17 @@ Model tiers (pick with `--model-tier`):
46
  All tiers are Apache 2.0 licensed. Runs via PaddleOCR's default Paddle engine
47
  (`paddle_static`) — same proven header pattern as `pp-doclayout.py`.
48
 
49
- HF Jobs examples:
 
50
 
51
  # Tiny on a cheap GPU
52
- hf jobs uv run --flavor t4-small -s HF_TOKEN \\
53
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-ocrv6.py \\
54
  INPUT_DATASET OUTPUT_DATASET \\
55
  --model-tier tiny --max-samples 5
56
 
57
  # Medium on a small GPU (recommended for quality)
58
- hf jobs uv run --flavor t4-small -s HF_TOKEN \\
59
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-ocrv6.py \\
60
  INPUT_DATASET OUTPUT_DATASET \\
61
  --model-tier medium --max-samples 10
@@ -795,7 +800,7 @@ for block in json.loads(ds[0]["pp_ocr_blocks"]):
795
  ## Reproduction
796
 
797
  ```bash
798
- hf jobs uv run --flavor t4-small -s HF_TOKEN \\
799
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-ocrv6.py \\
800
  {source} <output> --model-tier {tier}
801
  ```
 
29
  #
30
  # [tool.uv.sources]
31
  # paddlepaddle-gpu = { index = "paddle" }
32
+ #
33
+ # [tool.hf-jobs]
34
+ # flavor = "t4-small"
35
+ # secrets = ["HF_TOKEN"]
36
  # ///
37
  """
38
  OCR images with PP-OCRv6 — a lightweight detection+recognition pipeline from
 
50
  All tiers are Apache 2.0 licensed. Runs via PaddleOCR's default Paddle engine
51
  (`paddle_static`) — same proven header pattern as `pp-doclayout.py`.
52
 
53
+ HF Jobs examples (flavor and secrets come from the [tool.hf-jobs] header,
54
+ which needs `hf` CLI 1.32+):
55
 
56
  # Tiny on a cheap GPU
57
+ hf jobs uv run \\
58
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-ocrv6.py \\
59
  INPUT_DATASET OUTPUT_DATASET \\
60
  --model-tier tiny --max-samples 5
61
 
62
  # Medium on a small GPU (recommended for quality)
63
+ hf jobs uv run \\
64
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-ocrv6.py \\
65
  INPUT_DATASET OUTPUT_DATASET \\
66
  --model-tier medium --max-samples 10
 
800
  ## Reproduction
801
 
802
  ```bash
803
+ hf jobs uv run \\
804
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/pp-ocrv6.py \\
805
  {source} <output> --model-tier {tier}
806
  ```
qianfan-ocr.py CHANGED
@@ -4,11 +4,16 @@
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
7
- # "vllm>=0.15.1",
8
  # "tqdm",
9
  # "toolz",
10
- # "torch",
11
  # ]
 
 
 
 
 
 
 
12
  # ///
13
 
14
  """
@@ -28,6 +33,16 @@ Features:
28
  Model: baidu/Qianfan-OCR
29
  License: Apache 2.0
30
  Paper: https://arxiv.org/abs/2603.13398
 
 
 
 
 
 
 
 
 
 
31
  """
32
 
33
  import argparse
@@ -484,25 +499,26 @@ if __name__ == "__main__":
484
  print("- Key information extraction with custom prompts")
485
  print("\nExample usage:")
486
  print("\n1. Basic OCR:")
487
- print(" uv run qianfan-ocr.py input-dataset output-dataset")
488
  print("\n2. With Layout-as-Thought (complex documents):")
489
- print(" uv run qianfan-ocr.py docs output --think")
490
  print("\n3. Table extraction:")
491
- print(" uv run qianfan-ocr.py docs output --prompt-mode table")
492
  print("\n4. Formula extraction:")
493
- print(" uv run qianfan-ocr.py docs output --prompt-mode formula")
494
  print("\n5. Key information extraction:")
495
  print(
496
- ' uv run qianfan-ocr.py invoices output --prompt-mode kie --custom-prompt "Extract: name, date, total. Output JSON."'
497
  )
498
- print("\n6. Running on HF Jobs:")
499
- print(" hf jobs uv run --flavor l4x1 \\")
500
- print(" -s HF_TOKEN \\")
501
  print(
502
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/qianfan-ocr.py \\"
503
  )
504
  print(" input-dataset output-dataset --max-samples 10")
505
- print("\nFor full help, run: uv run qianfan-ocr.py --help")
 
 
506
  sys.exit(0)
507
 
508
  parser = argparse.ArgumentParser(
@@ -518,10 +534,10 @@ Prompt modes:
518
  kie Key information extraction (requires --custom-prompt)
519
 
520
  Examples:
521
- uv run qianfan-ocr.py my-docs analyzed-docs
522
- uv run qianfan-ocr.py docs output --think --max-samples 50
523
- uv run qianfan-ocr.py docs output --prompt-mode table
524
- uv run qianfan-ocr.py invoices data --prompt-mode kie --custom-prompt "Extract: name, date, total."
525
  """,
526
  )
527
 
 
4
  # "datasets>=4.0.0",
5
  # "huggingface-hub",
6
  # "pillow",
 
7
  # "tqdm",
8
  # "toolz",
 
9
  # ]
10
+ #
11
+ # [tool.hf-jobs]
12
+ # image = "vllm/vllm-openai:v0.29.0"
13
+ # python = "/usr/bin/python3"
14
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
15
+ # flavor = "a10g-small"
16
+ # secrets = ["HF_TOKEN"]
17
  # ///
18
 
19
  """
 
33
  Model: baidu/Qianfan-OCR
34
  License: Apache 2.0
35
  Paper: https://arxiv.org/abs/2603.13398
36
+
37
+ Run on HF Jobs (the [tool.hf-jobs] header sets image, flavor and secrets;
38
+ needs `hf` CLI 1.32+):
39
+
40
+ hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/qianfan-ocr.py \
41
+ input-dataset output-dataset --max-samples 10
42
+
43
+ Run on your own GPU:
44
+
45
+ uv run --with vllm==0.29.0 qianfan-ocr.py input-dataset output-dataset
46
  """
47
 
48
  import argparse
 
499
  print("- Key information extraction with custom prompts")
500
  print("\nExample usage:")
501
  print("\n1. Basic OCR:")
502
+ print(" uv run --with vllm==0.29.0 qianfan-ocr.py input-dataset output-dataset")
503
  print("\n2. With Layout-as-Thought (complex documents):")
504
+ print(" uv run --with vllm==0.29.0 qianfan-ocr.py docs output --think")
505
  print("\n3. Table extraction:")
506
+ print(" uv run --with vllm==0.29.0 qianfan-ocr.py docs output --prompt-mode table")
507
  print("\n4. Formula extraction:")
508
+ print(" uv run --with vllm==0.29.0 qianfan-ocr.py docs output --prompt-mode formula")
509
  print("\n5. Key information extraction:")
510
  print(
511
+ ' uv run --with vllm==0.29.0 qianfan-ocr.py invoices output --prompt-mode kie --custom-prompt "Extract: name, date, total. Output JSON."'
512
  )
513
+ print("\n6. Running on HF Jobs (header sets image/flavor/secrets; hf CLI 1.32+):")
514
+ print(" hf jobs uv run \\")
 
515
  print(
516
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/qianfan-ocr.py \\"
517
  )
518
  print(" input-dataset output-dataset --max-samples 10")
519
+ print("\n7. Running on your own GPU:")
520
+ print(" uv run --with vllm==0.29.0 qianfan-ocr.py input-dataset output-dataset")
521
+ print("\nFor full help, run: uv run --with vllm==0.29.0 qianfan-ocr.py --help")
522
  sys.exit(0)
523
 
524
  parser = argparse.ArgumentParser(
 
534
  kie Key information extraction (requires --custom-prompt)
535
 
536
  Examples:
537
+ uv run --with vllm==0.29.0 qianfan-ocr.py my-docs analyzed-docs
538
+ uv run --with vllm==0.29.0 qianfan-ocr.py docs output --think --max-samples 50
539
+ uv run --with vllm==0.29.0 qianfan-ocr.py docs output --prompt-mode table
540
+ uv run --with vllm==0.29.0 qianfan-ocr.py invoices data --prompt-mode kie --custom-prompt "Extract: name, date, total."
541
  """,
542
  )
543
 
surya-ocr-bucket.py CHANGED
@@ -14,6 +14,13 @@
14
  # # this recipe injects into); an unpinned/loosened resolve backtracks to an ancient
15
  # # surya without it. huggingface-hub is left unpinned: at runtime PYTHONPATH puts the
16
  # # pinned image's hub (with the buckets API) ahead of the venv, so no version tension.
 
 
 
 
 
 
 
17
  # ///
18
  """
19
  Structured OCR over a **bucket of document files** (images + PDFs) with Datalab's
@@ -55,27 +62,27 @@ OpenRAIL-M license — free for research, personal use, and startups under $5M
55
  funding/revenue, restricted from competitive use against Datalab's API. Confirm you
56
  are within those terms. https://huggingface.co/datalab-to/surya-ocr-2
57
 
58
- HF Jobs — MUST use the pinned vLLM image + the site-packages python path (the model
59
- is the recent, version-sensitive `qwen3_5` architecture; v0.20.1 is Surya's
60
- known-good build, and it puts python/vLLM under /usr/local, NOT /usr/bin):
 
 
61
 
62
  # copy input -> dataset output
63
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
64
- --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 \\
65
- -e PYTHONPATH=/usr/local/lib/python3.12/site-packages \\
66
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr-bucket.py \\
67
  hf://buckets/<ns>/<bucket> --io-mode copy --glob "*.jp2" \\
68
  --output-dataset <ns>/<out> --private
69
 
70
  # mount input -> per-file bucket output (mirrors dir structure)
71
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
72
- --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 \\
73
- -e PYTHONPATH=/usr/local/lib/python3.12/site-packages \\
74
  -v hf://buckets/<ns>/<bucket>:/in:ro \\
75
  -v hf://buckets/<ns>/<out-bucket>:/out \\
76
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr-bucket.py \\
77
  /in --io-mode mount --glob "*.jp2" --output-bucket /out
78
 
 
 
79
  Model: datalab-to/surya-ocr-2 (package: surya-ocr, https://github.com/datalab-to/surya)
80
  """
81
 
@@ -127,8 +134,8 @@ def check_cuda_availability() -> None:
127
  if not torch.cuda.is_available():
128
  logger.error("CUDA is not available. This script requires a GPU.")
129
  logger.error(
130
- "Run on Hugging Face Jobs with: hf jobs uv run --flavor l4x1 "
131
- "--image vllm/vllm-openai:v0.20.1 ..."
132
  )
133
  sys.exit(1)
134
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
@@ -1211,10 +1218,10 @@ Outputs (at least one required):
1211
  hf://buckets/... URL); resumable, O(1) memory
1212
  --output-dataset parquet dataset push (one row per file)
1213
 
1214
- Run on the vllm/vllm-openai:v0.20.1 image (offline vLLM batch; qwen3_5 is
1215
- version-sensitive — the site-packages python path is load-bearing):
1216
- --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 \\
1217
- -e PYTHONPATH=/usr/local/lib/python3.12/site-packages
1218
  """,
1219
  )
1220
  parser.add_argument(
@@ -1274,7 +1281,9 @@ version-sensitive — the site-packages python path is load-bearing):
1274
  help="DPI for PDF rendering (default: Surya's IMAGE_DPI_HIGHRES)",
1275
  )
1276
  parser.add_argument(
1277
- "--max-samples", type=int, help="Limit number of files (for testing)"
 
 
1278
  )
1279
  parser.add_argument(
1280
  "--shuffle", action="store_true", help="Shuffle before sampling"
@@ -1359,10 +1368,8 @@ def _print_banner() -> None:
1359
  print(" --glob '*.jp2' --output-dataset me/news-ocr --private")
1360
  print("\n # mount a bucket -> per-file .md + .json in an output bucket")
1361
  print(" uv run surya-ocr-bucket.py /in --io-mode mount --output-bucket /out")
1362
- print("\nRun on the vllm/vllm-openai:v0.20.1 image (offline vLLM batch):")
1363
- print(" hf jobs uv run --flavor l4x1 -s HF_TOKEN \\")
1364
- print(" --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 \\")
1365
- print(" -e PYTHONPATH=/usr/local/lib/python3.12/site-packages \\")
1366
  print(" -v hf://buckets/me/news:/in:ro -v hf://buckets/me/news-ocr:/out \\")
1367
  print(
1368
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr-bucket.py \\"
 
14
  # # this recipe injects into); an unpinned/loosened resolve backtracks to an ancient
15
  # # surya without it. huggingface-hub is left unpinned: at runtime PYTHONPATH puts the
16
  # # pinned image's hub (with the buckets API) ahead of the venv, so no version tension.
17
+ #
18
+ # [tool.hf-jobs]
19
+ # image = "vllm/vllm-openai:v0.20.1"
20
+ # python = "/usr/local/bin/python3"
21
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/site-packages" }
22
+ # flavor = "a10g-small"
23
+ # secrets = ["HF_TOKEN"]
24
  # ///
25
  """
26
  Structured OCR over a **bucket of document files** (images + PDFs) with Datalab's
 
62
  funding/revenue, restricted from competitive use against Datalab's API. Confirm you
63
  are within those terms. https://huggingface.co/datalab-to/surya-ocr-2
64
 
65
+ HF Jobs — the `[tool.hf-jobs]` header above pins the vLLM image + the site-packages
66
+ python path (the model is the recent, version-sensitive `qwen3_5` architecture;
67
+ v0.20.1 is Surya's known-good build, and it puts python/vLLM under /usr/local, NOT
68
+ /usr/bin), plus flavor and HF_TOKEN. The header needs `hf` CLI 1.32+; CLI flags
69
+ override it:
70
 
71
  # copy input -> dataset output
72
+ hf jobs uv run \\
 
 
73
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr-bucket.py \\
74
  hf://buckets/<ns>/<bucket> --io-mode copy --glob "*.jp2" \\
75
  --output-dataset <ns>/<out> --private
76
 
77
  # mount input -> per-file bucket output (mirrors dir structure)
78
+ hf jobs uv run \\
 
 
79
  -v hf://buckets/<ns>/<bucket>:/in:ro \\
80
  -v hf://buckets/<ns>/<out-bucket>:/out \\
81
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr-bucket.py \\
82
  /in --io-mode mount --glob "*.jp2" --output-bucket /out
83
 
84
+ On your own GPU (no image): `uv run --with vllm==0.20.1 surya-ocr-bucket.py ...`
85
+
86
  Model: datalab-to/surya-ocr-2 (package: surya-ocr, https://github.com/datalab-to/surya)
87
  """
88
 
 
134
  if not torch.cuda.is_available():
135
  logger.error("CUDA is not available. This script requires a GPU.")
136
  logger.error(
137
+ "Run on Hugging Face Jobs with: hf jobs uv run surya-ocr-bucket.py ... "
138
+ "(the script's [tool.hf-jobs] header sets image + GPU; hf CLI 1.32+)"
139
  )
140
  sys.exit(1)
141
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
 
1218
  hf://buckets/... URL); resumable, O(1) memory
1219
  --output-dataset parquet dataset push (one row per file)
1220
 
1221
+ HF Jobs: the script's [tool.hf-jobs] header pins vllm/vllm-openai:v0.20.1 + the
1222
+ site-packages python path (qwen3_5 is version-sensitive), flavor and HF_TOKEN, so
1223
+ `hf jobs uv run surya-ocr-bucket.py ...` needs no flags (hf CLI 1.32+).
1224
+ Own GPU: uv run --with vllm==0.20.1 surya-ocr-bucket.py ...
1225
  """,
1226
  )
1227
  parser.add_argument(
 
1281
  help="DPI for PDF rendering (default: Surya's IMAGE_DPI_HIGHRES)",
1282
  )
1283
  parser.add_argument(
1284
+ "--max-samples",
1285
+ type=int,
1286
+ help="Limit number of input files, not pages (a PDF counts once)",
1287
  )
1288
  parser.add_argument(
1289
  "--shuffle", action="store_true", help="Shuffle before sampling"
 
1368
  print(" --glob '*.jp2' --output-dataset me/news-ocr --private")
1369
  print("\n # mount a bucket -> per-file .md + .json in an output bucket")
1370
  print(" uv run surya-ocr-bucket.py /in --io-mode mount --output-bucket /out")
1371
+ print("\nHF Jobs (the [tool.hf-jobs] header sets image + GPU; hf CLI 1.32+):")
1372
+ print(" hf jobs uv run \\")
 
 
1373
  print(" -v hf://buckets/me/news:/in:ro -v hf://buckets/me/news-ocr:/out \\")
1374
  print(
1375
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr-bucket.py \\"
surya-ocr.py CHANGED
@@ -8,6 +8,13 @@
8
  # "toolz",
9
  # "tqdm",
10
  # ]
 
 
 
 
 
 
 
11
  # ///
12
  """
13
  Document intelligence on images OR multi-page PDFs with Datalab's **Surya OCR 2**
@@ -49,15 +56,16 @@ OpenRAIL-M license — free for research, personal use, and startups under $5M
49
  funding/revenue, but restricted from competitive use against Datalab's API.
50
  Confirm you are within those terms. https://huggingface.co/datalab-to/surya-ocr-2
51
 
52
- HF Jobs (use the pinned vLLM image so vLLM + qwen3_5 support are present):
 
53
 
54
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
55
- --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 \\
56
- -e PYTHONPATH=/usr/local/lib/python3.12/site-packages \\
57
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr.py \\
58
  INPUT_DATASET OUTPUT_DATASET \\
59
  --max-samples 5 --shuffle --seed 42
60
 
 
 
61
  Model: datalab-to/surya-ocr-2 (package: surya-ocr, https://github.com/datalab-to/surya)
62
  """
63
 
@@ -97,8 +105,8 @@ def check_cuda_availability() -> None:
97
  if not torch.cuda.is_available():
98
  logger.error("CUDA is not available. This script requires a GPU.")
99
  logger.error(
100
- "Run on Hugging Face Jobs with: hf jobs uv run --flavor l4x1 "
101
- "--image vllm/vllm-openai:v0.20.1 ..."
102
  )
103
  sys.exit(1)
104
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
@@ -118,13 +126,14 @@ def check_vllm_available() -> None:
118
  if importlib.util.find_spec("vllm") is None:
119
  logger.error("vLLM is not importable — this recipe cannot run on the bare uv image.")
120
  logger.error(
121
- "Surya-2 needs the pinned vLLM build; re-run with the image + interpreter flags:"
 
122
  )
 
123
  logger.error(
124
- " hf jobs uv run --flavor l4x1 -s HF_TOKEN \\\n"
125
- " --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 \\\n"
126
- " -e PYTHONPATH=/usr/local/lib/python3.12/site-packages \\\n"
127
- " <script_url> INPUT_DATASET OUTPUT_DATASET ..."
128
  )
129
  sys.exit(1)
130
 
@@ -775,9 +784,10 @@ Input (one document per row):
775
  --image-column COL one image per row (default: image)
776
  --pdf-column COL PDF bytes per row (multi-page; honors --page-range)
777
 
778
- Run on the vllm/vllm-openai:v0.20.1 image:
779
- --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 \\
780
- -e PYTHONPATH=/usr/local/lib/python3.12/site-packages
 
781
  """,
782
  )
783
  parser.add_argument(
 
8
  # "toolz",
9
  # "tqdm",
10
  # ]
11
+ #
12
+ # [tool.hf-jobs]
13
+ # image = "vllm/vllm-openai:v0.20.1"
14
+ # python = "/usr/local/bin/python3"
15
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/site-packages" }
16
+ # flavor = "a10g-small"
17
+ # secrets = ["HF_TOKEN"]
18
  # ///
19
  """
20
  Document intelligence on images OR multi-page PDFs with Datalab's **Surya OCR 2**
 
56
  funding/revenue, but restricted from competitive use against Datalab's API.
57
  Confirm you are within those terms. https://huggingface.co/datalab-to/surya-ocr-2
58
 
59
+ HF Jobs (the [tool.hf-jobs] header pins the vLLM image, interpreter, PYTHONPATH,
60
+ flavor and HF_TOKEN secret; needs `hf` CLI 1.32+):
61
 
62
+ hf jobs uv run \\
 
 
63
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/surya-ocr.py \\
64
  INPUT_DATASET OUTPUT_DATASET \\
65
  --max-samples 5 --shuffle --seed 42
66
 
67
+ On your own GPU: uv run --with vllm==0.20.1 surya-ocr.py INPUT_DATASET OUTPUT_DATASET ...
68
+
69
  Model: datalab-to/surya-ocr-2 (package: surya-ocr, https://github.com/datalab-to/surya)
70
  """
71
 
 
105
  if not torch.cuda.is_available():
106
  logger.error("CUDA is not available. This script requires a GPU.")
107
  logger.error(
108
+ "Run on Hugging Face Jobs with: hf jobs uv run <script> ... "
109
+ "(the script's [tool.hf-jobs] header sets the GPU + vLLM image; hf CLI 1.32+)"
110
  )
111
  sys.exit(1)
112
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
 
126
  if importlib.util.find_spec("vllm") is None:
127
  logger.error("vLLM is not importable — this recipe cannot run on the bare uv image.")
128
  logger.error(
129
+ "Surya-2 needs the pinned vLLM build. With hf CLI 1.32+ the script's "
130
+ "[tool.hf-jobs] header applies the image + interpreter automatically:"
131
  )
132
+ logger.error(" hf jobs uv run <script_url> INPUT_DATASET OUTPUT_DATASET ...")
133
  logger.error(
134
+ "Older hf CLIs: add --flavor a10g-small -s HF_TOKEN --image vllm/vllm-openai:v0.20.1 --python /usr/local/bin/python3 "
135
+ "-e PYTHONPATH=/usr/local/lib/python3.12/site-packages. "
136
+ "On your own GPU: uv run --with vllm==0.20.1 <script> ..."
 
137
  )
138
  sys.exit(1)
139
 
 
784
  --image-column COL one image per row (default: image)
785
  --pdf-column COL PDF bytes per row (multi-page; honors --page-range)
786
 
787
+ HF Jobs (hf CLI 1.32+; the [tool.hf-jobs] header sets image/flavor/secrets):
788
+ hf jobs uv run surya-ocr.py INPUT_DATASET OUTPUT_DATASET --max-samples 5
789
+ Own GPU:
790
+ uv run --with vllm==0.20.1 surya-ocr.py INPUT_DATASET OUTPUT_DATASET
791
  """,
792
  )
793
  parser.add_argument(
tesseract-ocr.py CHANGED
@@ -7,6 +7,10 @@
7
  # "pillow",
8
  # "tqdm",
9
  # ]
 
 
 
 
10
  # ///
11
  """
12
  Plain-text OCR with **Tesseract** — the classical CPU OCR engine, as a baseline.
@@ -26,9 +30,10 @@ root). For non-English languages it also tries to install the matching
26
  `tesseract-ocr-<lang>` data pack. If your Jobs image blocks apt, bake Tesseract
27
  into a custom `--image` instead.
28
 
29
- HF Jobs (CPU — no GPU needed):
 
30
 
31
- hf jobs uv run --flavor cpu-upgrade -s HF_TOKEN \\
32
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/tesseract-ocr.py \\
33
  input-dataset output-dataset \\
34
  --max-samples 100 --shuffle
@@ -512,8 +517,8 @@ if __name__ == "__main__":
512
  print("\n3. Test with a small sample, no push:")
513
  print(" uv run tesseract-ocr.py large-dataset out --max-samples 5 --dry-run")
514
  print("\n4. Running on HF Jobs (CPU flavor):")
515
- print(" hf jobs uv run --flavor cpu-upgrade \\")
516
- print(" -s HF_TOKEN \\")
517
  print(
518
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/tesseract-ocr.py \\"
519
  )
 
7
  # "pillow",
8
  # "tqdm",
9
  # ]
10
+ #
11
+ # [tool.hf-jobs]
12
+ # flavor = "cpu-upgrade"
13
+ # secrets = ["HF_TOKEN"]
14
  # ///
15
  """
16
  Plain-text OCR with **Tesseract** — the classical CPU OCR engine, as a baseline.
 
30
  `tesseract-ocr-<lang>` data pack. If your Jobs image blocks apt, bake Tesseract
31
  into a custom `--image` instead.
32
 
33
+ HF Jobs (CPU — no GPU needed). The script header sets the flavor
34
+ (`cpu-upgrade`) and the HF_TOKEN secret; this needs `hf` CLI 1.32+:
35
 
36
+ hf jobs uv run \\
37
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/tesseract-ocr.py \\
38
  input-dataset output-dataset \\
39
  --max-samples 100 --shuffle
 
517
  print("\n3. Test with a small sample, no push:")
518
  print(" uv run tesseract-ocr.py large-dataset out --max-samples 5 --dry-run")
519
  print("\n4. Running on HF Jobs (CPU flavor):")
520
+ print(" # header sets flavor + HF_TOKEN secret (hf CLI 1.32+)")
521
+ print(" hf jobs uv run \\")
522
  print(
523
  " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/tesseract-ocr.py \\"
524
  )
unlimited-ocr-vllm.py CHANGED
@@ -7,6 +7,13 @@
7
  # "tqdm",
8
  # "toolz",
9
  # ]
 
 
 
 
 
 
 
10
  # ///
11
 
12
  """
@@ -30,15 +37,16 @@ hallucination in our tests, where the model's own SGLang build held up better
30
  robust multi-page path. (vLLM's upstream PR, vllm-project/vllm#46564, benchmarks single-page only.)
31
 
32
  IMPORTANT: Unlimited-OCR's architecture is not in a stable vLLM pip wheel, so this script MUST run on
33
- Baidu's dedicated vLLM image (vllm and torch come from the image, not the PEP 723 deps):
 
 
34
 
35
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
36
- --image vllm/vllm-openai:unlimited-ocr --python /usr/bin/python3 \\
37
- -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\
38
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/unlimited-ocr-vllm.py \\
39
  your-input-dataset your-output-dataset --max-samples 10
40
 
41
- Use the vllm/vllm-openai:unlimited-ocr-cu129 tag on Hopper GPUs (h100/h200).
 
42
 
43
  Model card: https://huggingface.co/baidu/Unlimited-OCR
44
  vLLM recipe: https://recipes.vllm.ai/baidu/Unlimited-OCR
@@ -197,12 +205,11 @@ print(ds[0]["{output_column}"])
197
  ## Reproduction
198
 
199
  Generated with the [uv-scripts/ocr](https://huggingface.co/datasets/uv-scripts/ocr) Unlimited-OCR
200
- vLLM recipe. Unlimited-OCR needs Baidu's dedicated vLLM image:
 
201
 
202
  ```bash
203
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
204
- --image vllm/vllm-openai:unlimited-ocr --python /usr/bin/python3 \\
205
- -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\
206
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/unlimited-ocr-vllm.py \\
207
  {source_dataset} <output-dataset>
208
  ```
@@ -434,13 +441,10 @@ if __name__ == "__main__":
434
  print("=" * 80)
435
  print("\nBaidu Unlimited-OCR (3.3B, MIT) — one image per row -> markdown.")
436
  print("\nMUST run on the dedicated image: vllm/vllm-openai:unlimited-ocr")
437
- print("(use the -cu129 tag on Hopper GPUs).")
 
438
  print("\nExample:")
439
- print(" hf jobs uv run --flavor l4x1 -s HF_TOKEN \\")
440
- print(
441
- " --image vllm/vllm-openai:unlimited-ocr --python /usr/bin/python3 \\"
442
- )
443
- print(" -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\")
444
  print(" unlimited-ocr-vllm.py my-images my-markdown --max-samples 10")
445
  print(
446
  "\nMulti-page documents: serve the model instead (see serving-unlimited-ocr.md)."
@@ -459,10 +463,8 @@ Examples:
459
  # Clean text (strip grounding tags)
460
  uv run unlimited-ocr-vllm.py my-images ocr-results --strip-grounding
461
 
462
- # On HF Jobs (dedicated image required)
463
- hf jobs uv run --flavor l4x1 -s HF_TOKEN \\
464
- --image vllm/vllm-openai:unlimited-ocr --python /usr/bin/python3 \\
465
- -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \\
466
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/unlimited-ocr-vllm.py \\
467
  my-dataset my-output --max-samples 10
468
  """,
 
7
  # "tqdm",
8
  # "toolz",
9
  # ]
10
+ #
11
+ # [tool.hf-jobs]
12
+ # image = "vllm/vllm-openai:unlimited-ocr"
13
+ # python = "/usr/bin/python3"
14
+ # env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
15
+ # flavor = "a10g-small"
16
+ # secrets = ["HF_TOKEN"]
17
  # ///
18
 
19
  """
 
37
  robust multi-page path. (vLLM's upstream PR, vllm-project/vllm#46564, benchmarks single-page only.)
38
 
39
  IMPORTANT: Unlimited-OCR's architecture is not in a stable vLLM pip wheel, so this script MUST run on
40
+ Baidu's dedicated vLLM image (vllm and torch come from the image, not the PEP 723 deps). The
41
+ [tool.hf-jobs] header above sets the image, python, PYTHONPATH, flavor and HF_TOKEN secret, so the
42
+ run command needs no flags (the header needs `hf` CLI 1.32+):
43
 
44
+ hf jobs uv run \\
 
 
45
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/unlimited-ocr-vllm.py \\
46
  your-input-dataset your-output-dataset --max-samples 10
47
 
48
+ On Hopper GPUs (h100/h200) add --image vllm/vllm-openai:unlimited-ocr-cu129 (a CLI flag overrides
49
+ the header). On your own GPU, run inside that image: no stable vLLM wheel has this architecture yet.
50
 
51
  Model card: https://huggingface.co/baidu/Unlimited-OCR
52
  vLLM recipe: https://recipes.vllm.ai/baidu/Unlimited-OCR
 
205
  ## Reproduction
206
 
207
  Generated with the [uv-scripts/ocr](https://huggingface.co/datasets/uv-scripts/ocr) Unlimited-OCR
208
+ vLLM recipe. Unlimited-OCR needs Baidu's dedicated vLLM image, which the script's `[tool.hf-jobs]` header
209
+ sets (`hf` CLI 1.32+):
210
 
211
  ```bash
212
+ hf jobs uv run \\
 
 
213
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/unlimited-ocr-vllm.py \\
214
  {source_dataset} <output-dataset>
215
  ```
 
441
  print("=" * 80)
442
  print("\nBaidu Unlimited-OCR (3.3B, MIT) — one image per row -> markdown.")
443
  print("\nMUST run on the dedicated image: vllm/vllm-openai:unlimited-ocr")
444
+ print("(set by the script's [tool.hf-jobs] header, hf CLI 1.32+;")
445
+ print("on Hopper GPUs add --image vllm/vllm-openai:unlimited-ocr-cu129).")
446
  print("\nExample:")
447
+ print(" hf jobs uv run \\")
 
 
 
 
448
  print(" unlimited-ocr-vllm.py my-images my-markdown --max-samples 10")
449
  print(
450
  "\nMulti-page documents: serve the model instead (see serving-unlimited-ocr.md)."
 
463
  # Clean text (strip grounding tags)
464
  uv run unlimited-ocr-vllm.py my-images ocr-results --strip-grounding
465
 
466
+ # On HF Jobs (image, flavor and secret come from the [tool.hf-jobs] header; hf CLI 1.32+)
467
+ hf jobs uv run \\
 
 
468
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/unlimited-ocr-vllm.py \\
469
  my-dataset my-output --max-samples 10
470
  """,