Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I get a CPU-only version of PyTorch?

Tags:

I'm trying to get a basic app running with Flask + PyTorch, and host it on Heroku. However, I run into the issue that the maximum slug size is 500mb on the free version, and PyTorch itself is ~500mb.

After some google searching, someone wrote about finding a cpu-only version of PyTorch, and using that, which is much smaller here.

However, I'm pretty lost as to how this is done, and the person didn't document this at all. Any advice is appreciated, thanks.

EDIT:

To be more specific about my problem, I tried installing torch by (as far as I understand), including a requirements.txt which listed torch as a dependency. Current I have: torch==0.4.1. However this doesn't work bc of size.

My question is, do you know what I could write in the requirements file to get the cpu-only version of torch that is smaller, or alternatively, if the requirements.txt doesn't work for this, what I would do instead, to get the cpu version.

like image 860
Matt Avatar asked Aug 07 '18 15:08

Matt


People also ask

Can I run PyTorch on CPU?

Pytorch works perfectly running in CPU mode with no GPU, regardless of whether your system supports it or not.

Can I install PyTorch without GPU?

Depending on your system and compute requirements, your experience with PyTorch on Windows may vary in terms of processing time. It is recommended, but not required, that your Windows system has an NVIDIA GPU in order to harness the full power of PyTorch's CUDA support.

Which version of PyTorch should I use?

Stable represents the most currently tested and supported version of PyTorch. This should be suitable for many users. Preview is available if you want the latest, not fully tested and supported, 1.12 builds that are generated nightly.

How do I know what version of PyTorch I have?

Using Python Code The output prints the installed PyTorch version along with the CUDA version. For example, 1.9. 0+cu102 means the PyTorch version is 1.9. 0, and the CUDA version is 10.2.


2 Answers

Per the Pytorch website, you can install pytorch-cpu with

conda install pytorch-cpu torchvision-cpu -c pytorch 

You can see from the files on Anaconda cloud, that the size varies between 26 and 56MB depending on the OS where you want to install it.

You can get the wheel from http://download.pytorch.org/whl/cpu/. The wheel is 87MB.

You can setup the installation by putting the link to the wheel in the requirements.txt file. If you use Python 3.6 on Heroku:

http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-linux_x86_64.whl 

otherwise, for Python 2.7:

http://download.pytorch.org/whl/cpu/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl 

For example if your requirements are pytorch-cpu, numpy and scipy and you're using Python 3.6, the requirements.txt would look like:

http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-linux_x86_64.whl numpy scipy 
like image 127
iacolippo Avatar answered Sep 21 '22 16:09

iacolippo


As of PyTorch 1.3, PyTorch has changed its API. In order to install CPU version only, use

conda install pytorch torchvision cpuonly -c pytorch 

And, the corresponding wheel files can be downloaded from https://download.pytorch.org/whl/torch_stable.html and can be installed using pip or use the command similar to the following corresponding to your intended pytorch and torchvision versions

On Linux:

pip3 install torch==1.9.0+cpu torchvision==0.10.0+cpu -f https://download.pytorch.org/whl/torch_stable.html 

On Windows / Mac:

pip3 install torch torchvision 

Check the PyTorch's getting started guide.

like image 27
kHarshit Avatar answered Sep 22 '22 16:09

kHarshit