【问题标题】:How Solve 'RuntimeError: CUDA error: out of memory'?如何解决“RuntimeError: CUDA error: out of memory”?
【发布时间】:2021-05-22 22:01:28
【问题描述】:

我导入torch并使用cuda运行简单代码,但出现RuntimeError: CUDA error: out of memory错误。

我的代码和错误是:

>>> import torch
>>> print(torch.rand(1, device="cuda"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: CUDA error: out of memory

【问题讨论】:

  • 确保没有其他进程正在使用您的 GPU,如果是,请杀死它们或让它们完成。否则重启。否则你的 GPU 没有足够的内存来支持 PyTorch
  • 通过“watch -n 0.5 nvidia-smi”检查你的gpu内存
  • 是否有其他进程在使用 GPU 内存?

标签: python pytorch


【解决方案1】:

我与torch 合作遇到了同样的问题,问题通过以下代码解决:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '2, 3'

【讨论】:

    猜你喜欢
    • 2019-06-19
    • 2020-09-24
    • 2022-09-28
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 2021-01-27
    相关资源
    最近更新 更多