我可以在colab中清理GPU显存吗

发布于 2025-01-12 12:42:25 字数 121 浏览 2 评论 0原文

我正在尝试使用 aitextgen 在数据集上微调 774M gpt 2。不幸的是,无论我做什么,训练都会失败,因为只有 80 MB 的 vram 可用。如何在不重新启动运行时的情况下清除 vram,并可能防止 vram 已满?

I'm trying to use aitextgen to finetune 774M gpt 2 on a dataset. unfortunately, no matter what i do, training fails because there are only 80 mb of vram available. how can i clear the vram without restarting the runtime and maybe prevent the vram from being full?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷你仙 2025-01-19 12:42:25

另一种解决方案是使用这些代码片段。

1.

!pip install numba
  1. 然后:
from numba import cuda
# all of your code and execution
cuda.select_device(0)
cuda.close()

你的问题在Tensorflow官方github上有讨论。 https://github.com/tensorflow/tensorflow/issues/36465

更新:@alchemy 报告说,在开启方面这是无法恢复的。
您可以尝试下面的代码。

device = cuda.get_current_device() 
device.reset()

Another solution can be using these code snippets.

1.

!pip install numba
  1. Then:
from numba import cuda
# all of your code and execution
cuda.select_device(0)
cuda.close()

Your problem is discussed in Tensorflow official github. https://github.com/tensorflow/tensorflow/issues/36465

Update: @alchemy reported this to be unrecoverable in terms of turning on.
You can try below code.

device = cuda.get_current_device() 
device.reset()
甜`诱少女 2025-01-19 12:42:25
  1. 在笔记本块内运行命令 !nvidia-smi
  2. 查找您不需要删除以清理 vram 的 GPU 的进程 ID。然后运行命令 !kill process_id

它应该对你有帮助。

  1. Run the command !nvidia-smi inside a notebook block.
  2. Look for the process id for the GPU that is unnecessary for you to remove for cleaning up vram. Then run the command !kill process_id

It should help you.

淡笑忘祈一世凡恋 2025-01-19 12:42:25

PyTorch 自动管理 CUDA 内存,因此您通常不需要手动关闭设备。如果您想释放 GPU 内存,可以尝试以下操作:


import torch

# Deletes all unused tensors
torch.cuda.empty_cache()

PyTorch manages CUDA memory automatically, so you generally don't need to manually close devices. If you want to free up GPU memory, you can try the following:


import torch

# Deletes all unused tensors
torch.cuda.empty_cache()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文