首页 > 解决方案 > 如何确定您是否在 colab 中安装了 colab pro?

问题描述

这更像是一个杂项问题,但有这样做的功能吗?我只是找不到有关此主题的任何文档。例如,我的用法是这样的:

from google.colab import utils # I made this up
colab_pro = utils.colab_is_pro()
if colab_pro:
  # train model with higher settings
else:
  # train model with lower settings

目前我确实有办法做到这一点,但它相当hacky:

gpu_name = !nvidia-smi --query-gpu=gpu_name --format=csv
# You get Tesla T4 with free colab and faster GPUs with colab pro
colab_pro = False if 'T4' in gpu_name else True

仅供参考,这是我正在研究的 colab: https ://colab.research.google.com/github/Namburger/edgetpu-ssdlite-mobiledet-retrain/blob/master/ssdlite_mobileet_transfer_learning_cat_vs_dog.ipynb#scrollTo=Mg1C8UwStK7i

标签: pythongoogle-colaboratory

解决方案


#A Colab pro environment should have >20Gb of total memory.
from psutil import virtual_memory
colab_pro = virtual_memory().total / 1e9
print('Your runtime has {:.1f} gigabytes of available RAM\n'.format(colab_pro))

if colab_pro < 20:
  print('Not using a high-RAM runtime')
  # train model with lower settings
else:
  print('You are using a high-RAM runtime!')
  # train model with higher settings

此外,您可以按如下方式检查 colab 中的可用内存:

!cat /proc/meminfo

Colab pro 环境的总内存应大于 20Gb。

https://colab.research.google.com/notebooks/pro.ipynb#scrollTo=V1G82GuO-tez


推荐阅读