Open veya2ztn opened 2 months ago
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.
I have read the CLA Document and I hereby sign the CLA
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.
Inference Accelerated PDF parsing
This fold include a series infra-accelerate modules for origin PDF parsing, including:
Those engine is tested on a 80,000,000 pdf dataset and get a 5-10x speedup compared with the origin pdf parsing engine. Basicly, it can reach 6-10 pages per second on a single A100 GPU.
This is not a pipline framework but seperated into three task-wise batch processing engine. But it can be easily integrated into your own pipline framework.
Detection (Bounding Boxing)
Check the unit case:1000pdf takes around 20-30min
LayoutLM
The layoutLM is based on the
detectron2
. The main Vision Engine(ViT) is implemented via huggingface, the postprocess is based on detectron. There is a tensorRT version of the detectron model https://github.com/NVIDIA/TensorRT/tree/main/samples/python/detectron2 , but it is only for Mask R-CNN backbone. The tensorRT author manuelly develop the CUDA NMS and ROIAlign such asDET2GraphSurgeon
(see https://github.com/NVIDIA/TensorRT/blob/main/samples/python/detectron2/create_onnx.py) to convert the detectron2 model to tensorRT model. For layoutLM, there is no such tool to convert whole model into a tensorRT engine. There are serveral ways to accelerate the layoutLM model:In this repo, I use the torch.compile(1.5x) and bf16(2x) to accelerate the layoutLM model. The tensorRT version is not implemented yet.
Another way to accelerate the layoutLM is
avoid .numpy() large GPU tensor
. Origin code will useThis will copy the large tensor from GPU to CPU. (Since we later only gather part of data via
mask
, full tensor copy is unnecessary). The better way is to do slicing on GPU tensor and then copy the sliced tensor to CPU. (2x) (see batch_running_task/task_layout/get_batch_layout_model.py)
MFD
MFD(Math Formula Detection) is a simple YOLO model build through
ultralytics
. It has a good tensorRT convert tool chain. See https://docs.ultralytics.com/modes/export/ and convension/MDF/convert.py Download the engine viahuggingface-cli download --resume-download --local-dir-use-symlinks False LLM4SCIENCE/ultralytics-YOLO-MFD --local-dir models/MFD
. Thebatchsize
andtensorRT version==10.3.0
must match! if you want to use thetrt_engine
directly.PaddleOCR-Det
PaddleOCR-Det is the best text detecter around the world. But original paddle det only support one image per batch. In our detection task, every image is normlized into same size, so the original paddle det does not fit our task. Refer to
https://github.com/WenmuZhou/PytorchOCR
, Zhou has convert the paddleOCR into pytorch. It allow us use batch detection in pytorch now.There is a big speed up possiblity for the postprocessing for the paddleOCR-Det module. Currently, we use the DB postprocessing. See
https://github.com/PaddlePaddle/PaddleOCR/blob/main/ppocr/postprocess/db_postprocess.py
. The DB postprocessing is the slow part compare to whole detection process. Currently, there is no any speedup solution for the DB postprocessing.Detection Async(experimental)
See
batch_running_task/task_layout/rough_layout_with_aync.py
The async detection is a way to async postprocess and GPU inference. It works perfectly. But in slurm system, there isexit
error when run the script, this will make your machineCPU soft lock
. So, I do not recommend to use this script in slurm system.Recognition (OCR)
Check the unit case:1000 pdf takes around 2-5 min
PaddleOCR-Rec is the best text recognizer around the world. The original paddle rec support batch image processing. And the origin paddleOCR "is already very fast". However, you can see I still use
PytorchOCR
in this part. Just want to provide a non-paddle solution. Download the engine viahuggingface-cli download --resume-download --local-dir-use-symlinks False LLM4SCIENCE/pytorch_paddle_weight --local-dir models/pytorch_paddle_weight
. Thebatchsize
andtensorRT version==10.3.0
must match! if you want to use thetrt_engine
directly.Math formula recognition (MFR)
Check the unit case: 1000 pdf takes around 2-5min
Download the engine via
huggingface-cli download --resume-download --local-dir-use-symlinks False LLM4SCIENCE/unimernet --local-dir models/MFR/unimernet
. Thebatchsize
andtensorRT version==10.3.0
must match! if you want to use thetrt_engine
directly.The different between
LLM4SCIENCE/unimernet
andwanderkid/unimernet
is we delete thecounting
module in weight file. (it only works in training). And it is a pure nougat model.Batch run the task
Each task has a "batch_deal_with_xxx" module which will automatively schedule task. For example, your can prepare a
.jsonl
file namedtest.filelist
with each line isand then run