pytorch - PyTorch GPU 内存管理
问题描述
在我的代码中,我想替换张量中的值,因为某些索引的值为零,例如
target_mac_out[avail_actions[:, 1:] == 0] = -9999999
但是,它返回 OOM
RuntimeError: CUDA out of memory. Tried to allocate 166.00 MiB (GPU 0; 10.76 GiB total capacity; 9.45 GiB already allocated; 4.75 MiB free; 9.71 GiB reserved in total by PyTorch)
我认为没有内存分配,因为它只是访问张量target_mac_out
并检查值并替换某些索引的新值。
我理解对了吗?
解决方案
创建一个新的avail_actions[:, 1:] == 0
张量,并且可能整行本身在完成操作后删除旧张量之前创建另一个张量。
如果速度不是问题,那么您可以使用for
循环。喜欢
for i in range(target_mac_out.size(0)):
for j in range(target_mac_out.size(1)-1):
if target_mac_out[i, j+1] == 0:
target_mac_out[i, j+1] = -9999999
推荐阅读
- amazon-web-services - AWS Api-Gateway Lambda 代理终端节点的 Swagger 定义
- email - Haskell Yesod 在特定的星期几和特定的时间运行处理程序
- arrays - Numpy Swap/Substitute NoneType Entry with Numpy Array(即向量)
- azure-cosmosdb - Azure CosmosDb 模拟器未启动
- react-native - react-native textinput securetextentry 星而不是点
- outlook - 用阿拉伯语创建邮箱别名
- javascript - 如何使用 ngx 数据绑定将复选框绑定到选择禁用的属性?
- c# - 清除 Winform 文本框代码片段说明
- java - 如何使用 getAllSelectedOptions 从多个下拉列表中获取选定的选项
- svn - VisualSVN 服务器从 Windows 2008 迁移到 2012(Svn 版本 2.7.14)