Pytorch释放显存占用方式

yipeiwu_com6年前Python基础

如果在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释放显存占用方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python遍历指定文件及文件夹的方法

本文实例讲述了Python遍历指定文件及文件夹的方法。分享给大家供大家参考。具体如下: 初次编写: import os def searchdir(arg,dirname,names...

解决python文件字符串转列表时遇到空行的问题

文件内容如下: Alex 100000 Rain 80000 Egon 50000 Yuan 30000 #此处有一个空行! 现在看如何处理并转成列表! sal...

pandas 对日期类型数据的处理方法详解

pandas 对日期类型数据的处理方法详解

pandas 的日期/时间类型有如下几种: Concept Scalar Class Array Class panda...

Python使用itchat模块实现群聊转发,自动回复功能示例

本文实例讲述了Python使用itchat模块实现群聊转发,自动回复功能。分享给大家供大家参考,具体如下: 1.itchat自动把好友发来的消息,回复给他 仅能实现自动回复 原文给 好友...

python 队列详解及实例代码

python 队列详解及实例代码

队列特性:先进先出(FIFO)——先进队列的元素先出队列。来源于我们生活中的队列(先排队的先办完事)。 Queue模块最常与threading模块一起构成生产-消费者模型,提供了一个适...