Notes on Colab

从本科毕设开始使用Colab, 记录一下学习的过程.

Check Environment

  • Pip freeze vs. pip list: freeze outputs installed packages in requirements format; list lists installed packages

    1
    !pip freeze

  • cmdoption-version: Print the Python version number and exit.

    1
    !python --version

  • NVIDIA System Management Interface: The NVIDIA System Management Interface (nvidia-smi) is a command line utility, based on top of the NVIDIA Management Library (NVML), intended to aid in the management and monitoring of NVIDIA GPU devices.

    1
    2
    3
    4
    5
    6
    7
    8
    # [Making the Most of your Colab Subscription - Colaboratory](https://colab.research.google.com/notebooks/pro.ipynb)
    gpu_info = !nvidia-smi
    gpu_info = '\n'.join(gpu_info)
    if gpu_info.find('failed') >= 0:
    print('Select the Runtime > "Change runtime type" menu to enable a GPU accelerator, ')
    print('and then re-execute this cell.')
    else:
    print(gpu_info)

  • psutil.virtual_memory: Return statistics about system memory usage as a named tuple including the following fields, expressed in bytes.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # [Making the Most of your Colab Subscription - Colaboratory](https://colab.research.google.com/notebooks/pro.ipynb)
    from psutil import virtual_memory
    ram_gb = virtual_memory().total / 1e9
    print('Your runtime has {:.1f} gigabytes of available RAM\n'.format(ram_gb))
    if ram_gb < 20:
    print('To enable a high-RAM runtime, select the Runtime > "Change runtime type"')
    print('menu, and then select High-RAM in the Runtime shape dropdown. Then, ')
    print('re-execute this cell.')
    else:
    print('You are using a high-RAM runtime!')