Commit ·
d4c220a
1
Parent(s): c37f5fc
Fix dots-ocr.py OCR failures: pin vLLM, add limit_mm_per_prompt, per-image fallback
Browse files- Pin vLLM >=0.15.1 (was >=0.9.1) to match other production scripts
- Add limit_mm_per_prompt={"image": 1} to LLM init for stable batch processing
- On batch failure, retry images individually so only broken images get [OCR ERROR]
Tested: 20/20 samples clean on A100 (davanstrien/ufo-ColPali, seed 42)
Co-Authored-By: Claude Opus 4.6 <[email protected]>
- dots-ocr.py +13 -4
dots-ocr.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
# "datasets",
|
| 5 |
# "huggingface-hub",
|
| 6 |
# "pillow",
|
| 7 |
-
# "vllm>=0.
|
| 8 |
# "tqdm",
|
| 9 |
# "toolz",
|
| 10 |
# "torch",
|
|
@@ -299,6 +299,7 @@ def main(
|
|
| 299 |
trust_remote_code=True,
|
| 300 |
max_model_len=max_model_len,
|
| 301 |
gpu_memory_utilization=gpu_memory_utilization,
|
|
|
|
| 302 |
)
|
| 303 |
|
| 304 |
sampling_params = SamplingParams(
|
|
@@ -333,9 +334,17 @@ def main(
|
|
| 333 |
all_outputs.append(text)
|
| 334 |
|
| 335 |
except Exception as e:
|
| 336 |
-
logger.
|
| 337 |
-
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
# Calculate processing time
|
| 341 |
processing_duration = datetime.now() - start_time
|
|
|
|
| 4 |
# "datasets",
|
| 5 |
# "huggingface-hub",
|
| 6 |
# "pillow",
|
| 7 |
+
# "vllm>=0.15.1",
|
| 8 |
# "tqdm",
|
| 9 |
# "toolz",
|
| 10 |
# "torch",
|
|
|
|
| 299 |
trust_remote_code=True,
|
| 300 |
max_model_len=max_model_len,
|
| 301 |
gpu_memory_utilization=gpu_memory_utilization,
|
| 302 |
+
limit_mm_per_prompt={"image": 1},
|
| 303 |
)
|
| 304 |
|
| 305 |
sampling_params = SamplingParams(
|
|
|
|
| 334 |
all_outputs.append(text)
|
| 335 |
|
| 336 |
except Exception as e:
|
| 337 |
+
logger.warning(
|
| 338 |
+
f"Batch failed ({len(batch_images)} images), retrying individually: {e}"
|
| 339 |
+
)
|
| 340 |
+
for img in batch_images:
|
| 341 |
+
try:
|
| 342 |
+
msg = make_ocr_message(img, prompt)
|
| 343 |
+
out = llm.chat([msg], sampling_params)
|
| 344 |
+
all_outputs.append(out[0].outputs[0].text.strip())
|
| 345 |
+
except Exception as img_e:
|
| 346 |
+
logger.error(f"Image failed: {img_e}")
|
| 347 |
+
all_outputs.append("[OCR ERROR]")
|
| 348 |
|
| 349 |
# Calculate processing time
|
| 350 |
processing_duration = datetime.now() - start_time
|