[Dy2St] Clear InplaceMap after program is completed
#71503
Merged
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.
PR Category
Execute Infrastructure
PR Types
Bug fixes
Description
TL;NR
在动态图转静态图(动转静)模型导出流程中,
paddle.jit.save会在组网过程中将部分中间内容缓存于_global_inplace_map,并以id(program)作为 key。由于该缓存未在组网结束后及时清理,若 program 被复用,则可能出现缓存指向已被释放内存的情况,导致访问非法内存并最终触发段错误(Segmentation fault)。本 PR 针对这一问题,在组网流程结束后增加了对_global_inplace_map的相应清理,确保缓存与内存状态一致,消除悬垂指针隐患,提升导出流程的稳定性。在 PaddleSeg 中,即使是以动态图形式运行,但依旧会执行导出过程(会进行动转静)
在
jit.save过程中,多次执行(>50次)之后会出现段错误在
paddle.jit.save中会进行组网,组网过程中会缓存一部分内容,存在_global_inplace_map与_global_parameter_recorder中_global_parameter_recorder在组网结束后会自动释放其中内容,而_global_inplace_map不会释放由于是以
id(program)为 key,所以如果某个program被复用,则存在访问已被释放变量的风险,导致段错误本PR添加释放过程
PCard-66972