![]() |
私奔的绿豆 · torch.onnx.export()转换o ...· 2 天前 · |
![]() |
礼貌的啄木鸟 · 解决公司Kafka集群问题 - 耗子哥信徒 ...· 2 月前 · |
![]() |
考研的松树 · openFeign 异步 ...· 1 年前 · |
![]() |
焦虑的手套 · Spring Boot 使用 URL 连接 ...· 1 年前 · |
![]() |
发怒的洋葱 · Spring系列:聊聊 @Scope ...· 1 年前 · |
![]() |
聪明伶俐的甘蔗 · python - Read PST ...· 1 年前 · |
假设我创建了一个张量,并将它放在GPU上,以后不需要它,并且希望释放分配给它的GPU内存;我该如何做呢?
import torch
a=torch.randn(3,4).cuda() # nvidia-smi shows that some mem has been allocated.
# do something
# a does not exist and nvidia-smi shows that mem has been freed.
我试过:
del a
del a; torch.cuda.empty_cache()
但它们都不管用。
发布于 2019-04-22 12:43:09
运行
del tensor
会将内存从GPU中释放出来,但不会将其返回给设备,这就是为什么内存仍然显示在
nvidia-smi
上。您可以创建一个新的张量,这将重用该内存。
资料来源
https://discuss.pytorch.org/t/how-to-delete-pytorch-objects-correctly-from-memory/947 https://discuss.pytorch.org/t/about-torch-cuda-empty-cache/34232
https://stackoverflow.com/questions/55788093
复制相似问题
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2023 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号: 粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287