Suppose I have a Python virtual environment named pytorch-benchmarks
(created using python3 -m venv pytorch-benchmarks
). This environment is set up with the PyTorch nightly build and various other packages for running PyTorch benchmarks. The benchmarks run fine without any runtime errors.
I also have another virtual environment named pytorch-test
(created using python3 -m venv pytorch-test
), which I use for building PyTorch from source. There is no compatibility issue between the two versions because I check out the git commit corresponding to the nightly build in the pytorch-benchmarks
environment. In this pytorch-test
environment, I have multiple PyTorch builds. After building PyTorch for commit ID x
, I copy the torch
directory from ~/pytorch-test/lib/python3.10/site-packages
to torch-x
.
To switch between different PyTorch versions, I do the following:
- Back up the original PyTorch nightly in
pytorch-benchmarks
under~/pytorch-benchmarks/lib/python3.10/site-packages/torch
to~/pytorch-benchmarks/lib/python3.10/site-packages/torch-nightly
. - Remove the
torch
directory in~/pytorch-benchmarks/lib/python3.10/site-packages
. - Create a symlink from the specific version in
pytorch-test
topytorch-benchmarks
:ln -s /home/abhishek/pytorch-test/lib/python3.10/site-packages/torch-x /home/abhishek/pytorch-benchmarks/lib/python3.10/site-packages/torch
My concern is that this approach of switching between various versions of PyTorch (torch-x
) could lead to silent erroneous execution due to the execution of stale bytecode from .pyc
files. For instance, if I switch from torch-y
to torch-x
, could .pyc
files from the old version torch-y
cause problems?
Can anyone explain in detail what might go wrong and how to prevent the execution of stale code while using the symlink approach, without creating separate virtual environments for each version?