PR: Fix memory leaks and reduce GPU memory requirements #17
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.
作者你好,我是一名独立游戏开发者,我很喜欢你们的IDOL模型,但是我在使用它的时候发现了一些内存泄漏问题,这导致模型推理时内存和显存需求非常大,即使整个模型只有8G左右,推理仍然需要24G以上的显存和内存,连4090都无法cover。究其根本,是python的垃圾回收机制在torch中可能失效的问题,如果不手动回收一些内存,内存(显存)垃圾会一直累计。这是我作出的一些简单修改:
更多优化建议:
我猜测,ckpt中的encoder是半精度,也就是fp16,模型总参数其实只有4g左右,去掉推理不使用的optimizer,可以再降低显存需求。
总结:本次修复了加载时的内存泄漏,优化了推理时的显存占用,使得小显存的显卡也能完成推理工作,显存峰值降低到9524 MiB。
IDOL模型相当优秀,我们正在探索把它加入到我们新游戏开发的工作流中。感谢你们对AIGC技术的贡献。