How do I install PyTorch v1.0.0+ on Google Colab?

一笑奈何 提交于 2020-01-01 09:21:46

问题


PyTorch v1.0.0 stable was released on 8 December 2018 after being announced 7 months earlier.

I want get a version optimised for the hardware that my IPython kernel is running on.

How do I get this version on Google Colab?


回答1:


try the following code snippet (it works equally for the runtime with or without gpu)

!pip install -q torch==1.0.0 torchvision

to check the version

import torch
print(torch.__version__)

here you have the version 1.0.0

UPDATE

!pip install torch

Works fine now, as the most stable version is 1.0.0




回答2:


With version 1.0.0, PyTorch changed the download URL format from:

https://download.pytorch.org/whl/cu92/torch-1.0.0-cp36-cp36m-linux_x86_64.whl

to

https://download.pytorch.org/whl/cu90/torch-1.0.0-cp36-cp36m-linux_x86_64.whl

(The change is in the CUDA version part, where cu92 changes to cu90.)

To programmatically generate that URL, I used the following code:

from os.path import exists
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag

platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-9]*\)\.\([0-9]*\)$/cu\10/'    
accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

torch_url=f"http://download.pytorch.org/whl/{accelerator}/torch-{version}-{platform}-linux_x86_64.whl"
version='1.0.0'

!pip install -U {torch_url} torchvision

You can then change the version variable as desired as newer versions are released.




回答3:


For version 1.1.0, this works

!pip install -q torch==1.1.0 torchvision



回答4:


You can now just

import torch

No need for additional installation.



来源:https://stackoverflow.com/questions/53775508/how-do-i-install-pytorch-v1-0-0-on-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!