Hello! I need to and have managed to build from source for torch v2.4.1 using tag v2.4.1 in the pytorch source code. However, I also need torchvision, for which I use the command pip install torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 provided at Start Locally | PyTorch. The command will not use my self built torch and auto uninstall it:
While the commit matches the v2.4.1 release, the actual version tag is wrong as I believe it’s defined via an env variable.
I don’t know if trying to change the PyTorch version tag after a build would work, but you could try to install torchvision with --no-deps instead.
Thanks for the reply! So it means although I use git checkout v2.4.1 and build from it, the actual version is not v2.4.1, right?
Also, after installing torchvision with --no-deps, I find that the installed torchvision is not compatible with the torch I built. Is it also because the built torch from v2.4.1 is not version 2.4.1
No, your source build matches the v2.4.1 release as the same commit is used. However, the version tag stored in torch.__version__ is showing the commit (as is expected for default source builds) and you could override it via using the PYTORCH_VERSION env variable if I’m not mistaken. Technically nothing will change in your build as you are already building v.2.4.1 which just corresponds to commit ee1b680. (@malfet please correct me if the env variable is wrong)
Which torchvision version was installed and what kind of issues do you see?
I encountered a similar issue today and hope my comment can help.
I was building PyTorch from source and found that the version was 2.4.0 even though I downloaded pytorch-v2.4.1.tar.gz via the release page. I found this question and after setting environment variables PYTORCH_BUILD_VERSION=2.4.1 and PYTORCH_BUILD_NUMBER=1 and rebuilding the project, the version changed as expected.
However, torchvision throwed an exception:
RuntimeError: operator torchvision::nms does not exist
I suspected that torchvision downloaded by pip was incompatible with my CUDA toolkit’s version and also built torchvision from source. It works now!
Hi @ligweshh, could you explain in some more detail what exactly you did? I am also facing the same problem as you. How exactly did you install from source? Did you pick a tag? Have you set some flags?
Build torch and ensure you remain in the same environment before proceeding with the following steps.
Check your torch version and find a corresponding torchvision release. The torch package I built is v2.4.1, so the torchvision should be v0.19.1. The version comparison table can be found here.
I set the environment variable BUILD_VERSION to 0.19.1. If you download the source from the Github releases page, there’s a file named version.txt which also controls the version of the package you build, but I believe it can be overridden by BUILD_VERSION.
I set the environment variable TORCH_CUDA_ARCH_LIST to 6.0 6.1 6.2 7.0 7.2 7.5 8.0 8.6 8.7. I’m not entirely sure if TORCH_CUDA_ARCH_LIST has the same effect here as it does when building torch, so I kept it consistent with the value I used for that.
I ran python setup.py bdist_wheel instead of python setup.py develop to generate a .whl file. This allows me to install torchvision using pip install dist/torchvision-0.19.1-cp312-cp312-linux_x86_64.whl, ensuring all files are fully placed in site-packages. Note that the official documentation mentions that torchvision does not officially support building from source and suggests adding --no-build-isolation flag. I forgot to add that and it still works, but you may want to add it.
Example:
export TORCH_CUDA_ARCH_LIST="6.0 6.1 6.2 7.0 7.2 7.5 8.0 8.6 8.7"
export BUILD_VERSION=0.19.1
python setup.py bdist_wheel
# Optional: install it in current environment.
pip install dist/torchvision-0.19.1-cp312-cp312-linux_x86_64.whl