将PaddleDevice.Mkldnn()的ctor参数cacheCapacity默认值从10降低到1#46
Merged
sdcb merged 2 commits intosdcb:masterfrom Apr 24, 2023
n0099:master
Merged
将PaddleDevice.Mkldnn()的ctor参数cacheCapacity默认值从10降低到1#46sdcb merged 2 commits intosdcb:masterfrom n0099:master
PaddleDevice.Mkldnn()的ctor参数cacheCapacity默认值从10降低到1#46sdcb merged 2 commits intosdcb:masterfrom
n0099:master
Conversation
Contributor
Author
|
另外即便是在执行 |
Owner
|
非常感谢! |
n0099
added a commit
to n0099/open-tbm
that referenced
this pull request
Apr 25, 2023
* fix comittied too many memory after long running, sdcb/PaddleSharp#46 @ `PaddleOcrRecognizerAndDetector.GetModelFactory()` * merge field `_percentageThresholdOfIntersectionAreaToConsiderAs(Same|New)TextBox` and their config into a single tuple/config section `_intersectionAreaThresholds` @ ImageOcrConsumer.cs * clarify reloadability for each config in section `ImageOcrPipeline` @ appsettings.json * rename all param with type `KeyValurPair<,>` to `pair` @ PaddleOcrRecognizerAndDetector.cs & ClientRequester.cs @ crawler
n0099
added a commit
to n0099/open-tbm
that referenced
this pull request
May 4, 2023
- method `ForEach()` since it's conflicting with LinqKit: scottksmith95/LINQKit#168 - remove unused method `GetValuesByKeys()` * move method `NanToZero()` and `RoundToUshort()` to project `tbm.Shared` since they are also used by project `tbm.ImagePipeline` @ crawler/ExtensionMethods.cs * remove the value to argument `cacheCapacity` of method `PaddleDevice.Mkldnn()` since it's now the default value: sdcb/PaddleSharp#46 @ `PaddleOcrRecognizerAndDetector.GetPaddleOcrFactory()` * update NuGet packages @ imagePipeline @ c#
Closed
Contributor
Author
Open
|
楼主: |
Contributor
Author
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.
如下图表所示,针对完全不同的图片(但每次执行时的顺序相同)依次


PaddleOCRAll.Run()时如果在ctorPaddleOCRAll时使用了PaddleDevice.Mkldnn()的ctor并对其提供不同的cacheCapacity(即对PaddleConfig.MkldnnCacheCapacity的赋值,其又是在调用paddleinfer的PD_ConfigSetMkldnnCacheCapacity())ctor参数值(默认值10),那么持续运行下来的内存占用完全不同:并且值得注意的是在设为0时几乎必定会触发#44 中所述的
'dnnl:error' could not execute a primitive导致无法长时间运行下去,而使用默认值10时或许可以继续让内存增长并在达峰后稳定下来,但我没有足够的内存和耐心去等待结果回顾paddle文档:
https://github.com/PaddlePaddle/docs/blob/63362b7443c77a324f58a045bcc8d03bb59637fa/docs/design/mkldnn/caching/caching.md?plain=1#L70
机翻:
机翻:
可得paddle的这一套仅用于mkldnn环境的缓存机制是为了缓解(在paddleocr的语境下)针对不同输入图片时需要对每图片创建mkldnn对象的耗时,这也解释了为什么如果一直输入完全相同的图片集,那不论
MkldnnCacheCapacity是多少内存占用都是十分稳定的尽管缓存的本意是为了提升性能然而从上图表中可见
cap=10时的耗时反而比cap=1更久,这可能是由于运行环境系统内存不足导致页都被swap所以反而拖累了整体性能而
机翻:
进一步证明了paddleinfer中
PD_ConfigSetMkldnnCacheCapacity()函数的文档错误描述了0值时的行为https://github.com/PaddlePaddle/Paddle/blob/040f8aa50191b81313237e39d510dfb7b531cda9/paddle/fluid/inference/capi_exp/pd_config.h#L553
(以及复制粘贴进本库中的)
PaddleSharp/src/Sdcb.PaddleInference/Native/PaddleNative.g.cs
Line 325 in 5687fb0
PaddleSharp/src/Sdcb.PaddleInference/PaddleConfig.cs
Line 194 in 5687fb0
实际上由于paddle没有提供有关api目前根本没有办法能完全关闭这个缓存机制,而将其设为0反而是完全阻止了对缓存的定期清理导致只要继续输入不同的图片内存就必然会无限增长下去
因此本pr将这其在
PaddleDevice.Mkldnn()的ctor的默认值从10降低到1以尽可能缓解这种容易被用户视作内存溢出(#17 #27 #37 )的缓存行为(也就是使内存更快达峰然后稳定下来)并在
ocr.md文档中指出这个保守的默认值并建议运行环境有足够内存的用户考虑增加此值