如何在Google Colab中获取分配的GPU规格

46

我正在使用Google Colab进行深度学习,而且我知道他们会随机分配GPU给不同的用户。我想要在任何一个会话中看到我被分配了哪个GPU。在Google Colab笔记本中有没有办法做到这一点?

请注意,我正在使用Tensorflow。

3个回答

56

由于您可以在Colab中运行bash命令,只需运行!nvidia-smi

输入图片描述

在Colab中,您可以使用!或%%shell来调用Shell命令。 - Alex78191
如何在Python代码中使用信息?例如,如何相应地设置batch_size? - undefined
1
@jerron 我觉得这值得提出一个单独的问题,因为根据你的代码,有很多种方法可以做到这一点 :) 如果你在使用PyTorch,你可以使用 torch.cuda.get_device_properties(0).total_memory - undefined
@Vladimir Sotnikov 谢谢你的评论。我会创建一个单独的问题。顺便说一下,根据你的回答,我发现以下代码可以工作:`batch_size=int(torch.cuda.get_device_properties(0).total_memory/1e9+.5)*16 print(f'GPU mem:{int(torch.cuda.get_device_properties(0).total_memory/1e9+.5)}G, batch_size:{batch_size}') - undefined
这是一个新的问题:https://stackoverflow.com/questions/77160588/how-to-set-batch-size-in-google-colab-notebook-according-to-allocated-node-spec - undefined

36

这使得阅读更加容易。

!nvidia-smi -L

谢谢!nvidia-smi 的输出很混乱。这个简单易懂多了。 - Harshit Trehan

4

在collab中运行这两个命令

!/usr/local/cuda/bin/nvcc --version

!nvidia-smi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接