Instructions for installing PyTorch
See original GitHub issue- I have searched the issues of this repo and believe that this is not a duplicate.
Issue
As mentioned in issue https://github.com/python-poetry/poetry/issues/4231 there is some confusion around installing PyTorch with CUDA but it is now somewhat resolved. It still requires a few steps, and all options have pretty serious flaws. Below are two options that worked for me, on Poetry version 1.2.0.
Option 1 - wheel URLs for a specific platform
- You will need to pick the specific wheels you want. These are listed here: https://download.pytorch.org/whl/torch_stable.html. E.g. if you want CUDA 11.6, Python 3.10 and Windows, search that page for
cu116-cp310-cp310-win_amd64.whlto see the matches fortorch,torchaudioandtorchvision - In your
pyproject.tomlfile add the URLs like:
[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1.23.2"
torch = { url = "https://download.pytorch.org/whl/cu116/torch-1.12.1%2Bcu116-cp310-cp310-win_amd64.whl"}
torchaudio = { url = "https://download.pytorch.org/whl/cu116/torchaudio-0.12.1%2Bcu116-cp310-cp310-win_amd64.whl"}
torchvision = { url = "https://download.pytorch.org/whl/cu116/torchvision-0.13.1%2Bcu116-cp310-cp310-win_amd64.whl"}
- Run
poetry update. It will download a lot of data (many GB) and take quite some time. And this doesn’t seem to cache reliably (at least, I’ve waited 30 minutes+ at 56 Mbps three separate times while troubleshooting this, for the exact same wheels)
Note that each subsequent poetry update will do another huge download and you’ll see this message:
• Updating torch (1.12.1+cu116 -> 1.12.1+cu116 https://download.pytorch.org/whl/cu116/torch-1.12.1%2Bcu116-cp310-cp310-win_amd64.whl)
• Updating torchaudio (0.12.1+cu116 -> 0.12.1+cu116 https://download.pytorch.org/whl/cu116/torchaudio-0.12.1%2Bcu116-cp310-cp310-win_amd64.whl)
• Updating torchvision (0.13.1+cu116 -> 0.13.1+cu116 https://download.pytorch.org/whl/cu116/torchvision-0.13.1%2Bcu116-cp310-cp310-win_amd64.whl)
Option 2 - alternate source
[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1.23.2"
torch = { version = "1.12.1", source="torch"}
torchaudio = { version = "0.12.1", source="torch"}
torchvision = { version = "0.13.1", source="torch"}
[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu116"
secondary = true
This seems to have worked (although I already had the packages installed) but it reports errors like Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pillow/, but I think they get installed anyway (maybe a better message would be “Can’t access pillow at ‘https://download.pytorch.org/whl/cu116’, falling back to pypi”)
Also, if you later go on to do, say poetry add pandas (a completely unrelated library) you’ll get a wall of messages like:
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pandas/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pandas/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pytz/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/python-dateutil/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/numpy/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pillow/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/requests/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/typing-extensions/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/certifi/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/urllib3/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/idna/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/charset-normalizer/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/python-dateutil/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/six/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pytz/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/six/
This happens with or without secondary = true in the source config.
Maintainers: please feel free to edit the text of this if I’ve got something wrong.
Issue Analytics
- State:
- Created a year ago
- Reactions:113
- Comments:32 (12 by maintainers)
Top Related StackOverflow Question
Solution 1 seems infeasible when working in a team with machines on different operating systems, due to the need of providing the complete URL of the wheel including operating system and exact version number.
Solution 2 seems to work, but it results in downloading every single PyTorch version that can found, independent on the operating system. I’m running Windows and the download looks like this:
A single installation takes around 15-20 minutes at ~250 Mbps.
Maybe I’m misunderstanding but I think there’s some confusion
Ref: https://pytorch.org/get-started/locally/
First of all (on Linux)
pip install torchdoes not install the CPU version, it installs the default cuda version which is currently 11.7. If you want to install a cpu version you need to use a different command:pip3 install torch --extra-index-url https://download.pytorch.org/whl/cpu. This requires an extra index URL but it also identifies a different package version using the+convention.So you could do something like
if you want CPU support, or if you want a specific cuda version:
The issue that is being discussed on this bug report is that it’s really slow/throws a bunch of warnings depending on which command you run. Also I have no idea if this works on windows, but you probably shouldnt be using windows.
I was actually pretty surprised to find that this doesn’t work with config groups and I think fixing this should be considered. I think something like the following should be possible:
where you can then do
poetry install --with cpufor your cpu environment orpoetry install --with gpufor your cu116 GPU environment. But the dependencies in all groups need to be consistent so you getBecause test depends on both torch (1.12.1+cu116) and torch (1.12.1+cpu), version solving failed.. I dont think that should be enforced for optional groups unless the user tries to actually install two groups with conflicting packages