Sync from GitHub via hub-sync
Browse files- glm-ocr-bucket.py +10 -16
- glm-ocr.py +17 -23
glm-ocr-bucket.py
CHANGED
|
@@ -3,18 +3,12 @@
|
|
| 3 |
# dependencies = [
|
| 4 |
# "pillow",
|
| 5 |
# "pymupdf",
|
| 6 |
-
# "vllm",
|
| 7 |
-
# "torch",
|
| 8 |
# ]
|
| 9 |
#
|
| 10 |
-
# [[tool.uv.index]]
|
| 11 |
-
# url = "https://wheels.vllm.ai/nightly/cu129"
|
| 12 |
-
#
|
| 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 |
# ///
|
|
@@ -37,7 +31,7 @@ Input: Output:
|
|
| 37 |
Examples:
|
| 38 |
|
| 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+)
|
|
@@ -186,8 +180,8 @@ Task modes:
|
|
| 186 |
table Table extraction (HTML)
|
| 187 |
|
| 188 |
Examples:
|
| 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 \\
|
|
@@ -381,11 +375,11 @@ if __name__ == "__main__":
|
|
| 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")
|
| 385 |
print()
|
| 386 |
print("Examples:")
|
| 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+):")
|
|
@@ -394,7 +388,7 @@ if __name__ == "__main__":
|
|
| 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")
|
| 398 |
sys.exit(0)
|
| 399 |
|
| 400 |
main()
|
|
|
|
| 3 |
# dependencies = [
|
| 4 |
# "pillow",
|
| 5 |
# "pymupdf",
|
|
|
|
|
|
|
| 6 |
# ]
|
| 7 |
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# [tool.hf-jobs]
|
| 9 |
+
# image = "vllm/vllm-openai:v0.29.0"
|
| 10 |
+
# python = "/usr/bin/python3"
|
| 11 |
+
# env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
|
| 12 |
# flavor = "a10g-small"
|
| 13 |
# secrets = ["HF_TOKEN"]
|
| 14 |
# ///
|
|
|
|
| 31 |
Examples:
|
| 32 |
|
| 33 |
# Local test
|
| 34 |
+
uv run --with vllm==0.29.0 glm-ocr-bucket.py ./test-images ./test-output
|
| 35 |
|
| 36 |
# HF Jobs with bucket volumes (flavor + secrets come from the
|
| 37 |
# [tool.hf-jobs] header; needs hf CLI 1.32+)
|
|
|
|
| 180 |
table Table extraction (HTML)
|
| 181 |
|
| 182 |
Examples:
|
| 183 |
+
uv run --with vllm==0.29.0 glm-ocr-bucket.py ./images ./output
|
| 184 |
+
uv run --with vllm==0.29.0 glm-ocr-bucket.py /input /output --task table --pdf-dpi 200
|
| 185 |
|
| 186 |
HF Jobs with bucket volumes (flavor + secrets from the [tool.hf-jobs] header; hf CLI 1.32+):
|
| 187 |
hf jobs uv run \\
|
|
|
|
| 375 |
print("Designed for HF Buckets mounted as volumes.")
|
| 376 |
print()
|
| 377 |
print("Usage:")
|
| 378 |
+
print(" uv run --with vllm==0.29.0 glm-ocr-bucket.py INPUT_DIR OUTPUT_DIR")
|
| 379 |
print()
|
| 380 |
print("Examples:")
|
| 381 |
+
print(" uv run --with vllm==0.29.0 glm-ocr-bucket.py ./images ./output")
|
| 382 |
+
print(" uv run --with vllm==0.29.0 glm-ocr-bucket.py /input /output --task table")
|
| 383 |
print()
|
| 384 |
print("HF Jobs with bucket volumes (flavor + secrets from the")
|
| 385 |
print("[tool.hf-jobs] header; needs hf CLI 1.32+):")
|
|
|
|
| 388 |
print(" -v hf://buckets/user/ocr-output:/output \\")
|
| 389 |
print(" glm-ocr-bucket.py /input /output")
|
| 390 |
print()
|
| 391 |
+
print("For full help: uv run --with vllm==0.29.0 glm-ocr-bucket.py --help")
|
| 392 |
sys.exit(0)
|
| 393 |
|
| 394 |
main()
|
glm-ocr.py
CHANGED
|
@@ -4,19 +4,13 @@
|
|
| 4 |
# "datasets>=3.1.0",
|
| 5 |
# "huggingface-hub",
|
| 6 |
# "pillow",
|
| 7 |
-
# "vllm",
|
| 8 |
# "toolz",
|
| 9 |
-
# "torch",
|
| 10 |
# ]
|
| 11 |
#
|
| 12 |
-
# [[tool.uv.index]]
|
| 13 |
-
# url = "https://wheels.vllm.ai/nightly/cu129"
|
| 14 |
-
#
|
| 15 |
-
# [tool.uv]
|
| 16 |
-
# prerelease = "allow"
|
| 17 |
-
# override-dependencies = ["transformers>=5.1.0"]
|
| 18 |
-
#
|
| 19 |
# [tool.hf-jobs]
|
|
|
|
|
|
|
|
|
|
| 20 |
# flavor = "a10g-small"
|
| 21 |
# secrets = ["HF_TOKEN"]
|
| 22 |
# ///
|
|
@@ -28,10 +22,10 @@ GLM-OCR is a compact 0.9B parameter OCR model achieving 94.62% on OmniDocBench V
|
|
| 28 |
Uses CogViT visual encoder with GLM-0.5B language decoder and Multi-Token Prediction
|
| 29 |
(MTP) loss for fast, accurate document parsing.
|
| 30 |
|
| 31 |
-
NOTE:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
Features:
|
| 37 |
- 0.9B parameters (ultra-compact)
|
|
@@ -43,7 +37,7 @@ Features:
|
|
| 43 |
- MIT licensed
|
| 44 |
|
| 45 |
Model: zai-org/GLM-OCR
|
| 46 |
-
vLLM:
|
| 47 |
Performance: 94.62% on OmniDocBench V1.5
|
| 48 |
"""
|
| 49 |
|
|
@@ -67,7 +61,7 @@ from toolz import partition_all
|
|
| 67 |
# default uv-script image lacks (engine init then crashes). Greedy OCR doesn't use it; this
|
| 68 |
# lets the plain default-image command work. On the vllm/vllm-openai image it's a harmless no-op.
|
| 69 |
os.environ.setdefault("VLLM_USE_FLASHINFER_SAMPLER", "0")
|
| 70 |
-
# Same story for DeepGEMM
|
| 71 |
# nvcc-less base image (a non-fatal warning that clutters the log and hides the real traceback).
|
| 72 |
# Greedy OCR doesn't need the DeepGEMM JIT path, so disable it explicitly.
|
| 73 |
os.environ.setdefault("VLLM_USE_DEEP_GEMM", "0")
|
|
@@ -524,20 +518,20 @@ if __name__ == "__main__":
|
|
| 524 |
print(" table - Table extraction")
|
| 525 |
print("\nExamples:")
|
| 526 |
print("\n1. Basic OCR:")
|
| 527 |
-
print(" uv run glm-ocr.py input-dataset output-dataset")
|
| 528 |
print("\n2. Formula recognition:")
|
| 529 |
-
print(" uv run glm-ocr.py docs results --task formula")
|
| 530 |
print("\n3. Table extraction:")
|
| 531 |
-
print(" uv run glm-ocr.py docs results --task table")
|
| 532 |
print("\n4. Test with small sample:")
|
| 533 |
-
print(" uv run glm-ocr.py large-dataset test --max-samples 10 --shuffle")
|
| 534 |
print("\n5. Running on HF Jobs (hardware and HF_TOKEN come from the")
|
| 535 |
print(" script's [tool.hf-jobs] header; --flavor/--timeout override it):")
|
| 536 |
print(
|
| 537 |
" hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \\"
|
| 538 |
)
|
| 539 |
print(" input-dataset output-dataset --batch-size 16")
|
| 540 |
-
print("\nFor full help: uv run glm-ocr.py --help")
|
| 541 |
sys.exit(0)
|
| 542 |
|
| 543 |
parser = argparse.ArgumentParser(
|
|
@@ -550,9 +544,9 @@ Task modes:
|
|
| 550 |
table Table extraction
|
| 551 |
|
| 552 |
Examples:
|
| 553 |
-
uv run glm-ocr.py my-docs analyzed-docs
|
| 554 |
-
uv run glm-ocr.py docs results --task formula
|
| 555 |
-
uv run glm-ocr.py large-dataset test --max-samples 50 --shuffle
|
| 556 |
""",
|
| 557 |
)
|
| 558 |
|
|
|
|
| 4 |
# "datasets>=3.1.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 |
# ///
|
|
|
|
| 22 |
Uses CogViT visual encoder with GLM-0.5B language decoder and Multi-Token Prediction
|
| 23 |
(MTP) loss for fast, accurate document parsing.
|
| 24 |
|
| 25 |
+
NOTE: On Jobs, vLLM, torch and transformers come from the vllm/vllm-openai:v0.29.0
|
| 26 |
+
image pinned in the [tool.hf-jobs] header (`hf` CLI 1.32+). GLM-OCR needs vLLM
|
| 27 |
+
>=0.16.0 (PR #33005) and transformers>=5.1.0; the image has both. To run on your
|
| 28 |
+
own GPU: `uv run --with vllm==0.29.0 glm-ocr.py ...`.
|
| 29 |
|
| 30 |
Features:
|
| 31 |
- 0.9B parameters (ultra-compact)
|
|
|
|
| 37 |
- MIT licensed
|
| 38 |
|
| 39 |
Model: zai-org/GLM-OCR
|
| 40 |
+
vLLM: vllm/vllm-openai:v0.29.0 image (see the header)
|
| 41 |
Performance: 94.62% on OmniDocBench V1.5
|
| 42 |
"""
|
| 43 |
|
|
|
|
| 61 |
# default uv-script image lacks (engine init then crashes). Greedy OCR doesn't use it; this
|
| 62 |
# lets the plain default-image command work. On the vllm/vllm-openai image it's a harmless no-op.
|
| 63 |
os.environ.setdefault("VLLM_USE_FLASHINFER_SAMPLER", "0")
|
| 64 |
+
# Same story for DeepGEMM: its init calls _find_cuda_home, which asserts on the
|
| 65 |
# nvcc-less base image (a non-fatal warning that clutters the log and hides the real traceback).
|
| 66 |
# Greedy OCR doesn't need the DeepGEMM JIT path, so disable it explicitly.
|
| 67 |
os.environ.setdefault("VLLM_USE_DEEP_GEMM", "0")
|
|
|
|
| 518 |
print(" table - Table extraction")
|
| 519 |
print("\nExamples:")
|
| 520 |
print("\n1. Basic OCR:")
|
| 521 |
+
print(" uv run --with vllm==0.29.0 glm-ocr.py input-dataset output-dataset")
|
| 522 |
print("\n2. Formula recognition:")
|
| 523 |
+
print(" uv run --with vllm==0.29.0 glm-ocr.py docs results --task formula")
|
| 524 |
print("\n3. Table extraction:")
|
| 525 |
+
print(" uv run --with vllm==0.29.0 glm-ocr.py docs results --task table")
|
| 526 |
print("\n4. Test with small sample:")
|
| 527 |
+
print(" uv run --with vllm==0.29.0 glm-ocr.py large-dataset test --max-samples 10 --shuffle")
|
| 528 |
print("\n5. Running on HF Jobs (hardware and HF_TOKEN come from the")
|
| 529 |
print(" script's [tool.hf-jobs] header; --flavor/--timeout override it):")
|
| 530 |
print(
|
| 531 |
" hf jobs uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \\"
|
| 532 |
)
|
| 533 |
print(" input-dataset output-dataset --batch-size 16")
|
| 534 |
+
print("\nFor full help: uv run --with vllm==0.29.0 glm-ocr.py --help")
|
| 535 |
sys.exit(0)
|
| 536 |
|
| 537 |
parser = argparse.ArgumentParser(
|
|
|
|
| 544 |
table Table extraction
|
| 545 |
|
| 546 |
Examples:
|
| 547 |
+
uv run --with vllm==0.29.0 glm-ocr.py my-docs analyzed-docs
|
| 548 |
+
uv run --with vllm==0.29.0 glm-ocr.py docs results --task formula
|
| 549 |
+
uv run --with vllm==0.29.0 glm-ocr.py large-dataset test --max-samples 50 --shuffle
|
| 550 |
""",
|
| 551 |
)
|
| 552 |
|