How to edit and compile pytorch source code?

Hi, sorry if this question was asked before…

I want to make few changes to the file utils.data.dataloader.py and utils.data._utils.worker.py. Precisely, I want to add some log statements to both the files.

I have downloaded and installed pytorch in Windows 10 using pip3 install torch.... Now, I wanted to know :

  1. how can I edit files and re-compile pytorch from source ?
  2. Do I need to install any C++ compiler on windows since pytorch uses C++ under the hood ?

Please help me, Thanks !!

Hi @Vinayaka_Hegde,

If you want to edit source, you’ll need to install pytorch from source rather than pip or conda. The instructions can be found on their GitHub repo here.

1 Like

Hi @AlphaBetaGamma96 thanks for replying. I have one doubt : I want to install pytorch from source but I dont want the cuda option enabled for now. I want to try out some minor things by chaning the pytorch source code, and I dont want to install nvidia CUDA sdk or cuDNN packages for now.

Is it possible to still install and compile/build source by just installing conda and other packages as mentioned in github (without installing cuDNN or Nvidia CUDA SDK ) ?

There are cpu-only install instructions in the github link I shared, but note you won’t be able to use CUDA with that environment.

hi,

If you only want to change some python code, then there is a hacky way to do this by modifying directly the intall you got from pip.
You can locate the file from the install by running python -c "import torch; print(torch.utils.data.dataloader.__file__)"
Then if you modify this python file, it will be automatically picked up after you restart your python proces.
There is no need to recompille if you change only python code.

1 Like

@albanD thanks as this worked, However, I’m facing some more issues, would you please take a look at this: DataLoader Multiprocessing RunTIme Error
Thanks