How to build pytorch source? - pytorch

When I use pytorch, it showed that my the cuda version pytorch used and cuda version of system are inconsistent, so I need rebuild pytorch from source.
# install dependency
pip install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
# Download pytorch source
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
# if you are updating an existing checkout
git submodule sync
git submodule update --init --recursive --jobs 0
# Build
#if you want to use pytorch with cuda ,please `USE_CUDA=1`
python setup.py install
#torchvision install with source
# Download
git clone --recursive --branch v0.11.1 https://github.com/pytorch/vision.git
cd vision
python setup.py install

Building pytorch from source is not trivial, there is extensive documentation for it hereenter link description here .
However I think you should try to either install directly a an older pytorch version compatible with your system version of cuda or use docker with the version (safer option).
You could also try to update your CUDA system if it supports newer drivers, good luck.

Related

Error in creating an offline PDF documentatin for PyTorch

I wanted to make an offline PDF on my system for PyTorch documentation. After reading from several resources #1, #2, #3
git clone https://github.com/pytorch/pytorch
cd pytorch/docs/
make latexpdf
First two commands are working fine. Third command leads to the following error
Traceback (most recent call last):
File "source/scripts/build_activation_images.py", line 70, in <module>
function = torch.nn.modules.activation.__dict__[function_name]()
KeyError: 'SiLU'
How to overcome this error and make a PDF document of PyTorch?
1.4.0 is the version of PyTorch in my system
print(torch.__version__)
1.4.0
3.8.3 is the version of Python in my system
python -V
Python 3.8.3
The PyTorch version installed in your machine (1.4.0) is older than the one you cloned (most recent). Two ways to fix it:
Checkout to the version you have installed (if you want the doc of 1.4 version):
git clone https://github.com/pytorch/pytorch
# move back to the 1.4 release, which you have installed in your machine
cd pytorch
git checkout release/1.4
cd docs
make latexpdf
Upgrade to the most-recent PyTorch version (if you want the most recent doc):
# upgrade PyTorch to the nightly release (change it accordingly)
python -m pip install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html
git clone https://github.com/pytorch/pytorch
cd pytorch/docs/
make latexpdf

Install wheel file on off-line machine which has different processor

I have a wheel file for ARM64 based platform which should be installed by pip3 install MyWheelfile.whl on an offline computer.
How can I download all the required dependencies to an online computer which is x86-64 platform?
You can use the --platform flag with pip download to get the desired version of the wheel. You probably can't get the ARM wheels from PyPi (I haven't done enough with ARM myself to be sure), but piwheels should have them.
This worked for me to get numpy:
pip download --index-url=https://www.piwheels.org/simple --platform linux_armv7l --no-deps numpy
You can of course combine this with a requirements.txt file to get all of your packages at once if you want
pip download --index-url=https://www.piwheels.org/simple --platform linux_armv7l --no-deps -r requirements.txt
In requirements.txt (example):
pandas==1.0.1
numpy>=1.18.1
I'm not sure exactly what version you need, but you can see available versions at piwheels (e.g. for numpy go to https://www.piwheels.org/simple/numpy/)

I am trying to install intel optimized pytorch in different ways

I am very first time using pyTorch. I am trying to install it. In how many ways I can do this?
Please provide the steps for that.
You can install PyTorch in 3 ways.
Using pip
Using conda
From source
1.Intel Optimized Pytorch Installation
Install the stable version (v 1.0) on Linux via Pip for Python 3.6.
pip install https://download.pytorch.org/whl/cpu/torch-1.0.1.post2-cp36-cp36m-linux_x86_64.whl
pip install torchvision
2.Conda Pytorch Installation
conda install pytorch-cpu torchvision-cpu -c pytorch
3.PyTorch Installation from source
Create a new environment:
conda create -n <env_name> python=3.6
export CMAKE_PREFIX_PATH=/home/user/.conda/envs/<env_name>
source activate <env_name>
Install dependencies:
conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing
conda install -c conda-forge opencv
conda install Pillow
Get the PyTorch source:
git clone --recursive https://github.com/intel/pytorch
cd pytorch
mv caffe2/contrib/cuda-convnet2/ /tmp
# Fix the bug removing the old package out
Install PyTorch:
python setup.py install 2>&1 | tee build.out
Hope this will help you.

How to install torch==0.3.1 in python=3.6

I am trying to install deepmatcher package in python 3.6. To let this package to run in python you need have a torch==0.3.1 version. So I am trying to install torch==0.3.1 by running :
pip install torch==0.3.1
Error during installation:
Collecting torch==0.3.1
ERROR: Could not find a version that satisfies the requirement torch==0.3.1 (from versions: 0.1.2, 0.1.2.post1)
ERROR: No matching distribution found for torch==0.3.1
I even tried installing it using "peterjc123" package but still unable to uninstall it.
torch 0.3.1 is not listed official anymore. To install torch 0.3.1 one can either build it by source or using a whl file for the specific version.
Using a whl file
whl files can be found here provided by pytorch
The downloaded file can then be installed with pip install [path to downloaded file]
Build by source
To build torch by source one can checkout the desired version via git
git checkout v[version number]
For torch==0.3.1 this would be git checkout v0.3.1
After this follow the install instructions provided by README.md
More information can be found at: https://pytorch.org/get-started/previous-versions/
check if you have right python installed for you os architecture or
create a virtual env using conda and then try installing its better this way

setuptools, use package on local system instead of getting it from PyPI

There is an open-source python package that I want to work on (toga-android). To test the code I write, I have to be able to build my own project that has said open-source package as a dependency. My project has to be built with setuptools, so I need setuptools to fulfill the dependency using my version of the package, and not get the package from PyPI.
The problem is that setuptools always gets the package from PyPI.
Whenever I build with setuptools I see:
Collecting toga-android==0.3.0.dev8
Downloading https://files.pythonhosted.org/packages/92/fe/348a39e2e0bbcac2d3ed511dd2b62943b488e7dcb8097c437416caf1c179/toga_android-0.3.0.dev8-py3-none-any.whl
or
Collecting toga-android==0.3.0.dev8
Using cached https://files.pythonhosted.org/packages/92/fe/348a39e2e0bbcac2d3ed511dd2b62943b488e7dcb8097c437416caf1c179/toga_android-0.3.0.dev8-py3-none-any.whl
Clearly it is getting the package from PyPI or using a cached version from it.
I have installed my version using pip install -e . , and that has no effect. I have also tried including the package's source in my project's directory with setup.py. Setuptools apparently includes this code because syntax errors there make the build fail, but it doesn't recognize that it can satisfy the dependency. It still gets the package from PyPI and any modules imported from the package are the PyPI versions.
How can I use of custom version of a package that is also in PyPI as a setuptools dependency?
Steps to reproduce:
pip install briefcase (using or not using virtualenv does not matter)
git clone https://github.com/pybee/toga.git
cd ~/toga/src/core; sudo pip install -e .
cd ~/toga/src/android/; sudo pip install -e .
cd ~/toga/examples/tutorial0
python setup.py android
The output will show that an older version of toga-android is downloaded even though it was already installed with pip.

Resources