-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in PaddleOCR. #11639
Comments
Same problem... |
@tink2123 Can you look into this issue? |
你好,这个原因经过分析,本质上不属于内存泄漏,是Paddle框架将Tensor做了缓存复用,这部分内存 在下次遇到同样shape tensor的时候会复用,从而避免调用系统的allocator。如果对内存比较敏感,可以export FLAGS_allocator_strategy=naive_best_fit,这个会一定程度上缓解CPU的内存占用。后续我们将进一步优化Allocator的逻辑,以提供更合理的内存复用策略。 |
@vivienfanghuagood Thank you for your reply, but as i am using PaddleOCR, I can't find any parameter as following are the parameters in paddleOCR |
You are right. In fact, this is an environment variable in Paddle. When you use PaddleOCR for inference, the backend may be Paddle( if you choose it), so this environment variable will take effect. |
@vivienfanghuagood Yes you are correct, but I can't manually change that env variable. Can you suggest me any solution, I really want to fix this memory auto growth problem. Thanks. |
just set in you shell export FLAGS_allocator_strategy=naive_best_fit |
@GreatV The following is not working. |
It is supposed to work according to the python code. Line 29 in 89e0a15
|
@GreatV @vivienfanghuagood Still the same, here i am using python memory profiler. You can see on every request we see a memory increment on predict model line. This is not the case if we so same for same image. but I also tried to preprocess the image and resize to make tensors same. but the problem still remains the same. |
This is a long standing issue in the community. I generally use onnx as an inference backend in my deployments. |
@GreatV can you show you inference script of using onnx for OCR, will check the memory issue over onnx too. |
Hi @ShubhamZoop, you may refer https://github.com/GreatV/ppocr_trt_infer |
Does this solve the problem of memory growth? and can you show me how do I get started with the above infer files. Thank you for your help. Appreciate that. |
Hi @ShubhamZoop, You may try other implementations that don't use the paddle inference backend, such as https://github.com/PaddlePaddle/FastDeploy. The code above link is just a demo that removes the paddle inference dependency from the official deploy code and uses tensorrt as the backend. |
already using Openvino as a backend using fastdeploy, which also seems the same. #memory_leak :p |
@GreatV Will there is any update on paddle for memory leak? why this issue is taking so long to solve? @TingquanGao @vivienfanghuagood |
most of key developers (i.e., |
@ShubhamZoop Hello ,how did u manage to integrate ORT I've been facing the same problem. |
@pxike |
各位大佬,内存泄漏问题,后来怎么解决的啊? |
@cmathx The issue is not yet fully resolved. But you can try using Onnx models which are better than the default. |
to use onnx, it's too slow. |
Hi, this issue should be fixed on develop branch of Paddle after oneDNN v3.4 is merged. The root cause is, some specific kernels (brgemm kernels) in oneDNN were not reused even if they were functionally identical, resulting in repetitive creation and memory leak afterwards. This issue is fixed after v3.4, you may try building Paddle locally and see if it works, thanks. |
@LLee233 Thanks for mentioning it, can you mention the commit for oneDNN v3.4. I can't see any changes regarding oneDNN v3.4 on any branch. |
@Shubham654 This commit is where we update oneDNN on Paddle. |
It's cool. With my several ocr test on paddle/openvino/onnx model, using
paddle model it's most quick. As memory leak is well fixed(I will test your
mentioned suggestion), paddle model will be a strong engineering toolkit.
Xinyi_LI ***@***.***> 于2024年6月19日周三 15:16写道:
… Hi, this issue should be fixed on *develop branch* of Paddle after oneDNN
*v3.4* is merged. The root cause is, some specific kernels (brgemm
kernels) in oneDNN were not reused even if they were functionally
identical, resulting in repetitive creation and memory leak afterwards.
This issue is fixed after v3.4, you may try building Paddle locally and see
if it works, thanks.
—
Reply to this email directly, view it on GitHub
<#11639 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNFGBM4KQA6HIBYUD4POV3ZIEV3LAVCNFSM6AAAAABD5USORSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZXHEZDMNZTHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
您好,我遇到的是GPU推理时显存一直上涨,推理结束之后不释放,请问目前有方法可以避免这种情况吗 |
Hi, so what should I do to fix this problem, may I update oneDNN? |
Yes, you may try updating version of oneDNN locally in 3rd-party (if your branch is not too old) or just use newest develop branch of Paddle, which already updated oneDNN (both of them need re-build from source). Or you may use build-wheel of 3.0-beta or nightly build on offical site and see if it works. |
I try to use paddlepaddle 3.0.0b1 but it don't work. Would you happen to have any solution? |
Are you using oneDNN (MKLDNN) backend? Cause this only fixes mem issue on oneDNN. |
This still seems to be an issue, I upgraded onednn and its still leaking memory |
我最终通过设置以下环境变量,限制内存使用来解决这个问题,速度变得非常慢,但是运行过程不会再崩溃了。 |
I have noticed some weird memory usage when evaluating the performance of PaddleOCR:
When PaddleOCR processes new images of a sequence, there is a constant increase in memory usage of the process.
The time profile of the memory usage has sudden steps to higher memory levels.
If the system sets an upper bound in the memory consumption, the paddle process is eventually killed. It won't give allocated memory back, ever.
This behaviour can be observed both with the C++ and the Python interface.
Eventually it is impossible to keep running a PaddleOCR process as a service because the system runs out of memory and the process is killed.
Can you provide insights on this memory usage pattern? Do you have any remedy?
The following sections describe the tests in detail.
C++ Tests
Setup for the C++ tests
Test hardware:
OS: Ubuntu 20.04
CPU: Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz, 16 threads, AVX2
RAM: 128GB
PaddleOCR: Source code from v2.7.0.3
Model files:
Detector: en_PP-OCRv3_det_infer.tar
Classifier: ch_ppocr_mobile_v2.0_cls_infer.tar
Recognizer: en_PP-OCRv3_rec_infer.tar
OpenCV has been compiled from the source code tagged at v4.6.0 with the parameters:
Methodology for the Python tests
PaddleOCR repo at v2.7.0.3
Slight modifications to report the memory usage (Resident Set Size), the number of bboxes/image and the total time spent after the OCR of each image.
Run on CPU with or without MKL enabled.
cmd arguments:
./${PADDLE_OCR_BUILD_DIR}/ppocr
--rec_char_dict_path="./dicts/en_dict.txt"
--det_model_dir=${MODELS_INFERENCE_DIR}/det_db
--rec_model_dir=${MODELS_INFERENCE_DIR}/rec_rcnn
--cls_model_dir=${MODELS_INFERENCE_DIR}/cls
--visualize=true
--output=${OUT_DIR}
--image_dir=${IMAGES_DIR}
--use_angle_cls=true
--det=true
--rec=true
--cls=true
--use_gpu=false
--enable_mkldnn=true
--precision=fp32
--cpu-threads=4
Results of the Python tests
Test 1: Base
Test 2: Long run
Test 3: No MKL
Test 4: Det only
Test 5: Det + Rec
Test 6: Det + Cls
Test 7: Loop same image
Python tests
Setup for the Python tests
Test hardware:
OS: Ubuntu 20.04
CPU: Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz, 16 threads, AVX2
RAM: 128GB
paddlepaddle: v2. 6.0
paddleocr: v2.7.0.3
Results of the Python tests
CPU with MKL enabled
1320 images
OCR pipeline = Detector + Classifier + Recognizer
Num of theads: 4
The text was updated successfully, but these errors were encountered: