PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.19k stars 5.57k forks source link

PaddlePaddle1.6.x下动态图使用deformable_conv造成显存泄露 #24579

Closed ViktorAxelsen closed 3 years ago

ViktorAxelsen commented 4 years ago

PaddlePaddle版本:1.6.2 GPU:V100,AI Studio上的 系统环境:Python2.7 单卡 16GB / 32GB deformable_conv

动态图下使用deformable_conv会造成显存泄露。PaddlePaddle的显存分配策略好像是固定分配最大显存的92%,所以在训练前10个epoch左右的时候显存没变,之后显存随step上升。经过消融实验验证后确定deformable_conv导致此问题。

iclementine commented 4 years ago

请问你是如何调用 deformable_conv 呢?

https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/deformable_conv_cn.html#deformable-conv

这个 API 目前只能在静态图下使用,因为这个 API 调用的时候会创建 weight bias 等参数。动态图下如果在模型定义里使用了这个就会每次运行的时候创建新的 weight bias. 所以会造成显存泄漏。

我们目前在动态图下如果使用包含参数的层,它们都在 fluid/dygraoh 目录下,以大写开头的比如 Linear, Conv2D. 这些 Layer 是 class object,只在 __init__ 的时候创建参数,在 forward 中只是计算。动态图下 forward 函数会被多次调用。

而 fluid.layers.fc, fluid.layers.conv2d 之类的小写的 function, 它们是 functuon, 调用的时候会创建参数。而静态图下我们多次调用的是 executor.run(program), 而 fluid.layers.conv2d 之类的函数只会调用一次,用于往 program 上写入。所以不会有这个问题。

我反馈一下这个问题,添加 deformable conv 功能的仅计算的 API 以及在动态图下的 Layer.

ViktorAxelsen commented 4 years ago

好的,非常感谢。能在文档的其他版本下也加上“仅支持静态图”字样吗?当时我使用的是paddle1.6,在1.6文档下,没有写明我还以为动态图能用deformable_conv

iclementine commented 4 years ago

好的,非常感谢。能在文档的其他版本下也加上“仅支持静态图”字样吗?当时我使用的是paddle1.6,在1.6文档下,没有写明我还以为动态图能用deformable_conv

理论上是应该的,但是目前对文档的修改主要是对新版本的修改了。所以也推荐使用最新版本的 paddle.

paddle-bot-old[bot] commented 3 years ago

Since you haven\'t replied for more than a year, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. 由于您超过一年未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。