How can I install torchvision with my self built from source torch

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:

Installing collected packages: torch, torchvision, torchaudio
Attempting uninstall: torch
Found existing installation: torch 2.4.0a0+gitee1b680
Uninstalling torch-2.4.0a0+gitee1b680:
Successfully uninstalled torch-2.4.0a0+gitee1b680
Successfully installed torch-2.4.1+cu118 torchaudio-2.4.1+cu118 torchvision-0.19.1+cu118

Do you know how to solve it? Thanks a lot!

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?