I have a question regarding the installation mechanism of PyTorch and the differences it has compared to TensorFlow. I have noticed that TensorFlow can be easily installed from PyPI using the command pip install tensorflow
, regardless of whether it is the CPU or CUDA version. However, PyTorch seems to have a different approach. I would like to understand the reasons behind this difference.
Is the decision to not implement a similar installation mechanism in PyTorch due to technical challenges or a deliberate choice made by the developers? I am curious to know the factors that led to this divergence and the implications it may have for users.
Btw, I am using mono repo to manage my projects, so lock files are necessary for me. However, generating lock files for PyTorch becomes quite cumbersome due to the requirement of calculating hashes each time. This is why I am particularly interested in seeking an answer to this question.
PyTorch uses a similar install command for the “default” wheels via pip install torch
as mentioned in the install matrix and I’m unsure which difference you are trying to point out.
Thank you for your response.
Unlike TensorFlow, which only requires the ‘pip install tensorflow’ command for installation regardless of the device’s CUDA compatibility (after version 1.15), without the need for practices like ‘–index-url https://download.pytorch.org/whl/cu118’, PyTorch’s installation process is different.
I understand that this difference doesn’t pose any challenges when using pip alone. However, in the case of using environment managers such as Poetry or PDM (which I use) with a lockfile, the need to download and calculate hashes for the large packages from the third-party index can become burdensome.
I would like to know the reason behind PyTorch not bundling the CUDA dependency together, similar to TensorFlow.
there is an open issue on Poetry’s GitHub repository that has been discussing how to install PyTorch for the past two years: Instructions for installing PyTorch · Issue #6409 · python-poetry/poetry · GitHub. I believe this demonstrates the difficulties encountered when using PyTorch with package management tools.
PyTorch’s install commands differ for the non-default binaries while the default ones (currently 2.0.1+cu117
) are installed via a simple pip install torch
command.
This command will download all necessary CUDA runtime dependencies and will allow you to directly execute any PyTorch workload on your GPU without the need to install any other CUDA dependencies such as the CUDA toolkit.
Correct me if I’m missing something, but according to these TensorFlow install instructions you are supposed to:
- download and install
conda
first
- install a
cudatoolkit
from conda-forge
- install
cudnn
and tensorflow
from PyPI
- create custom folders
- move env variables to your conda environment
source
the newly installed environment
while the CPU-only version only requires pip install tensorflow
.
The opposite is the case. We are making sure that no other CUDA requirements are needed and that each command installs the desired PyTorch version with all needed CUDA depndencies.
Only if you are building from source or a custom CUDA extension would a locally installed CUDA toolkit be needed.
Thank you for your response.
May I ask another question? Why is the default installation behavior different between Windows and Linux?
A few dependencies could be missing for Windows on PyPI, but that’s my guess. However, due to the low number of Windows users the priority to host the PyTorch wheels with CUDA support on PyPI might be lower.