释放pytorch占用的gpu显存_Pytorch释放显存占用方式

如果在python内调用pytorch有可能显存和GPU占用不会被自动释放,此时需要加入如下代码

torch.cuda.empty_cache()

我们来看一下官方文档的说明

Releases all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU application and visible in nvidia-smi.

Note

empty_cache() doesn't increase the amount of GPU memory available for PyTorch. See Memory management for more details about GPU memory management.

此外还可以使用

memory_allocated()和max_memory_allocated()

观察显存占用,并使用

memory_cached()和 max_memory_cached()

观察由缓存分配器管理的内存。

以上这篇Pytorch释放显存占用方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

本文标题: Pytorch释放显存占用方式

本文地址: http://www.cppcns.com/jiaoben/python/298283.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值