mem: reduce PaddleOCR rec_batch_num from 6 to 1#4295
Open
KRRT7 wants to merge 6 commits intoUnstructured-IO:mainfrom
Open
mem: reduce PaddleOCR rec_batch_num from 6 to 1#4295KRRT7 wants to merge 6 commits intoUnstructured-IO:mainfrom
KRRT7 wants to merge 6 commits intoUnstructured-IO:mainfrom
Conversation
Paddle's native inference engine allocates 500 MiB memory arena chunks during text recognition, proportional to batch size. With the default rec_batch_num=6, four 500 MiB chunks are allocated simultaneously. Setting rec_batch_num=1 reduces this to a single chunk, cutting peak memory on the PaddleOCR code path by ~1,265 MiB (-42.6%). Latency benchmark (55 text regions, CPU, 5 runs): - rec_batch_num=6: 39.1s +/- 3.5s - rec_batch_num=1: 37.0s +/- 2.0s No throughput regression — on CPU, batch processing is sequential.
…h-num # Conflicts: # CHANGELOG.md
badGarnet
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduce PaddleOCR
rec_batch_numfrom 6 (default) to 1. Paddle's native inference engine allocates 500 MiB memory arena chunks proportional to recognition batch size. With batch_num=6, four chunks are allocated during text recognition. Setting it to 1 reduces this to one chunk.rec_batch_num=6rec_batch_num=1Measured with
memray runonlayout-parser-paper-with-table.pdfthroughpartition()with hi_res + PaddleOCR table OCR. On CPU, batch processing doesn't parallelize — it's sequential withinpredictor.run(). Smaller batches just allocate less workspace memory.Reproduce
Requires
unstructured[pdf],paddlepaddle,unstructured-paddleocr, andmemray.