Search code examples
pythonmachine-learningdeep-learningpytorchgpu

How to tell PyTorch to not use the GPU?


I want to do some timing comparisons between CPU & GPU as well as some profiling and would like to know if there's a way to tell to not use the GPU and instead use the CPU only? I realize I could install another CPU-only , but hoping there's an easier way.


Solution

  • Before running your code, run this shell command to tell torch that there are no GPUs:

    export CUDA_VISIBLE_DEVICES=""
    

    This will tell it to use only one GPU (the one with id 0) and so on:

    export CUDA_VISIBLE_DEVICES="0"