Make batch inference resumable and leak-free - #36
Conversation
Hardens the SGLang batch runner for long-horizon documents: - Resume: skip pages whose output already exists; add --overwrite to force - Atomic writes: stream each page to a .part file, rename on completion, so a present output file always means a fully parsed page (safe to resume on) - Fix temp-dir leak: rendered PDF pages now go to a temp dir that is cleaned up after the run; add --keep_temp to retain it - Emit <output_dir>/manifest.json with per-page status/tokens/timing/attempts - Ctrl-C: cancel pending jobs, keep finished pages, still write the manifest Adds tests/test_infer.py (mocks the SGLang endpoint, runs CPU-only without the model) and a GitHub Actions CI workflow, per CONTRIBUTING.md.
|
Well-designed PR — the atomic-write + resume + manifest combination is exactly what batch OCR pipelines need for production reliability. The implementation is clean throughout. A few observations: What's particularly strong
One functional gap: missing
|
gundam tiles a single image (crop_mode=True); multi-page/PDF inference only supports base, so reject the silently-wrong --pdf + gundam combo in parse_args() up front instead of producing wrong output. Also fix the README batch example, which used --image_mode gundam for a PDF, and add ParseArgsValidationTest covering reject/accept cases.
|
Added the --image_mode base guard for PDF mode in parse_args(). |
rajpratham1
left a comment
There was a problem hiding this comment.
This is a substantial and well-thought-out enhancement rather than just a bug fix. It makes long-running OCR jobs resumable, prevents partially written output files from being treated as completed work, adds interruption handling, introduces a manifest for tracking progress, and backs everything with comprehensive unit tests. The implementation also updates the documentation and CI, making the feature much easier to maintain.
Not in progress — it's complete. Added the --image_mode base guard kushdab requested, with tests and a README fix. Ready to merge. Thanks for the review! |
What
Hardens the SGLang batch runner (
infer.py) for long-horizon documents.--overwriteforces a re-run..partfile, renamed only on completion —a present output file always means a fully parsed page, so resume is safe.
after the run;
--keep_tempretains it.<output_dir>/manifest.jsonwith per-page status(
ok/skipped/failed), tokens, decode time, and retry attempts.Tests
Adds
tests/test_infer.py(mocks the SGLang endpoint — runs CPU-only, no GPU/model)and a GitHub Actions CI workflow, per CONTRIBUTING.md. All 11 tests pass locally.
Why
A long PDF that fails or is interrupted partway currently has to be re-run from page 1.
This makes batch runs idempotent and auditable.