Building from source a pytorch wheel file with all the dependencies and Cuda+Cudnn included; Linux+Python 3.7, Cuda=11.2+Cudnn=8.1

AlexW: <blockquote>
<p>I want to build torch v1.12.1  from source and create wheel with all the dependencies included into the  wheel file .  Additionally,  to force the inclusion of all the Cuda and Cudnn -related stuff from my system into the wheel file. Similar task goes for torchvision v0.13.1.<br>
I have Ubuntu 22.04 with Nvidia-driver-535 and Cuda Toolkit 11.2+Cudnn 8.1 installed system-wide.</p>
</blockquote>
<p><code>conda create --name pytorch-build python=3.7</code><br>
conda activate pytorch-build</p>
<pre><code class="lang-auto">
conda install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
</code></pre>
<p><code>conda install -c pytorch magma-cuda112</code></p>
<pre><code class="lang-auto">cd ~
git clone --recursive https://github.com/pytorch/pytorch
cd ~/pytorch
git checkout v1.12.1
git submodule sync
git submodule update --init --recursive --jobs 0
</code></pre>
<pre><code class="lang-auto">
export USE_CUDA=1 USE_CUDNN=1 USE_MKLDNN=1
cd ~/pytorch
python setup.py sdist bdist_wheel
</code></pre>
<blockquote>
<p>as a result, the file ‘torch-1.12.0a0+git664058f-cp37-cp37m-linux_x86_64.whl’ has been created. The size of the file is 250.4mb.</p>
</blockquote>
<pre><code class="lang-auto">conda  deactivate pytorch-build
conda create --name new-environment   python=3.7
conda  activate new-environment 
pip install  ~/pytorch/dist/torch-1.12.0a0+git664058f-cp37-cp37m-linux_x86_64.whl
Processing ./pytorch/dist/torch-1.12.0a0+git664058f-cp37-cp37m-linux_x86_64.whl
Collecting typing-extensions (from torch==1.12.0a0+git664058f)
  Downloading typing_extensions-4.7.1-py3-none-any.whl.metadata (3.1 kB)
Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
</code></pre>
<pre><code class="lang-auto">Installing collected packages: typing-extensions, torch
Successfully installed torch-1.12.0a0+git664058f typing-extensions-4.7.1
</code></pre>
<blockquote>
<p>‘pip install  …/torch-1.12.0a0+git664058f-cp37-cp37m-linux_x86_64.whl’ is collecting typing-extensions (from torch==1.12.0a0+git664058f) as well as  is downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB).<br>
Will it be safe to install, prior to compiling and building,  all three typing packages as follows?<br>
<code>conda install typing-extensions typing_extensions typing</code></p>
</blockquote>
<blockquote>
<p>How to force ‘python setup.py sdist bdist_wheel’ to include all the dependencies into the wheel file ‘torch-1.12.0a0+git664058f-cp37-cp37m-linux_x86_64.whl’?</p>
</blockquote>
<blockquote>
<p>How to force  ‘pip install *.whl’ not to look for (and not  to download) the dependencies if they already included with the wheel file?</p>
</blockquote>
<blockquote>
<p><strong>Moreover, how can I force the inclusion of all the Cuda and Cudnn -related stuff  from my system  into the wheel file ‘torch-*.whl’</strong>?</p>
</blockquote>
<blockquote>
<p>Next, in the original ‘pytorch-build’ conda enviroment, I want to build torchvision:</p>
</blockquote>
<pre><code class="lang-auto">conda  activate pytorch-build
conda install libpng libjpeg-turbo -c pytorchhttps://discuss.pytorch.org/t/torch-tf-spacy-more-gpu-python-3-7-ubuntu-22-04
conda install pillow
</code></pre>
<pre><code class="lang-auto">
cd ~
git clone https://github.com/pytorch/vision.git
cd vision
git checkout v0.13.1
</code></pre>
<pre><code class="lang-auto">
python setup.py sdist bdist_wheel
</code></pre>
<blockquote>
<p>as a result, the file ‘torchvision-0.13.1a0+bddbd7e-cp37-cp37m-linux_x86_64.whl’ has been created. The size of the file is 19mb.</p>
</blockquote>
<pre><code class="lang-auto">conda  deactivate pytorch-build
conda  activate new-environment  ### with Python 3.7
pip install  ~/vision/dist/torchvision-0.13.1a0+bddbd7e-cp37-cp37m-linux_x86_64.whl
Processing ./vision/dist/torchvision-0.13.1a0+bddbd7e-cp37-cp37m-linux_x86_64.whl
Requirement already satisfied: typing-extensions in ./miniconda3/envs/py37/lib/python3.7/site-packages (from torchvision==0.13.1a0+bddbd7e) (4.7.1)

Collecting numpy (from torchvision==0.13.1a0+bddbd7e)
  Downloading numpy-1.21.6-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.7/15.7 MB 11.5 MB/s eta 0:00:00
Collecting requests (from torchvision==0.13.1a0+bddbd7e)
  Downloading requests-2.31.0-py3-none-any.whl.metadata (4.6 kB)
Requirement already satisfied: torch in ./miniconda3/envs/py37/lib/python3.7/site-packages (from torchvision==0.13.1a0+bddbd7e) (1.12.0a0+git664058f)

Collecting pillow!=8.3.*,&gt;=5.3.0 (from torchvision==0.13.1a0+bddbd7e)
  Downloading Pillow-9.5.0-cp37-cp37m-manylinux_2_28_x86_64.whl (3.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 10.1 MB/s eta 0:00:00

Collecting charset-normalizer&lt;4,&gt;=2 (from requests-&gt;torchvision==0.13.1a0+bddbd7e)
  Downloading charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (33 kB)

Collecting idna&lt;4,&gt;=2.5 (from requests-&gt;torchvision==0.13.1a0+bddbd7e)
  Downloading idna-3.4-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.5/61.5 kB 15.9 MB/s eta 0:00:00

Collecting urllib3&lt;3,&gt;=1.21.1 (from requests-&gt;torchvision==0.13.1a0+bddbd7e)
  Downloading urllib3-2.0.7-py3-none-any.whl.metadata (6.6 kB)

Requirement already satisfied: certifi&gt;=2017.4.17 in ./miniconda3/envs/py37/lib/python3.7/site-packages (from requests-&gt;torchvision==0.13.1a0+bddbd7e) (2022.12.7)

Downloading requests-2.31.0-py3-none-any.whl (62 kB)

Downloading charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (136 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 136.8/136.8 kB 14.9 MB/s eta 0:00:00

Downloading urllib3-2.0.7-py3-none-any.whl (124 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 124.2/124.2 kB 19.9 MB/s eta 0:00:00
</code></pre>
<pre><code class="lang-auto">Installing collected packages: urllib3, pillow, numpy, idna, charset-normalizer, requests, torchvision
Successfully installed charset-normalizer-3.3.2 idna-3.4 numpy-1.21.6 pillow-9.5.0 requests-2.31.0 torchvision-0.13.1a0+bddbd7e urllib3-2.0.7
</code></pre>
<blockquote>
<p>Why ‘pip install’  wants to download the above dependencies?<br>
How to force ‘python setup.py sdist bdist_wheel’ to include all the dependencies as well as Cuda+Cudnn into the wheel file?<br>
How to force  ‘pip install *.whl’ not to look for (and not  to download) the dependencies if they already included with the wheel file?</p>
</blockquote>
<p>This topic is the continuation of <a href="https://discuss.pytorch.org/t/torch-tf-spacy-more-gpu-python-3-7-ubuntu-22-04">https://discuss.pytorch.org/t/torch-tf-spacy-more-gpu-python-3-7-ubuntu-22-04</a></p>

ptrblck: <p>Check <a href="https://github.com/pytorch/builder"><code>pytorch/builder</code></a> to see how these “large” nightly binaries are created which also include all dependencies inside the wheel.</p>

AlexW: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="191916">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>Check <a href="https://github.com/pytorch/builder" rel="noopener nofollow ugc"><code>pytorch/builder</code></a></p>
</blockquote>
</aside>
<p>On  <a href="https://github.com/pytorch/builder/tree/main/manywheel" rel="noopener nofollow ugc">https://github.com/pytorch/builder/tree/main/manywheel</a> : I see scripts to build linux wheels.</p>
<p>I  have cloned the source  <code>git clone --recursive https://github.com/pytorch/pytorch</code>.<br>
I know the command to built and create a wheel file from the source:<br>
<code>python setup.py sdist bdist_wheel</code></p>
<p>I do not understand where and how  in the process I can use the builder  scripts  - before running  ‘setup.py’? Or instead of ‘setup.py’ ?</p>
<p>It mentions building docker images,but I do not need  docker, just a wheel file</p>

Lucas_Gomez: <p>Any updates on this? I am trying to do the same thing, but no luck.</p>

sunny_yang: <p>Take a look at my work</p>
<aside class="quote quote-modified" data-post="1" data-topic="222638">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sunny_yang/48/78042_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://discuss.pytorch.org/t/a-tool-for-fast-stable-pytorch-builds-30-mins-pytorch-turbo-builder/222638">A Tool for Fast, Stable PyTorch Builds (&lt;30 Mins) - PyTorch Turbo-Builder</a> 
    </div>
  </div>
  <blockquote>
    Hi everyone, 
Like many of you who build PyTorch from source, I was often frustrated with 90-minute builds that would frequently crash with out-of-memory (OOM) errors. 
To solve this, I created a project called the PyTorch Turbo-Builder. It’s a collection of scripts and a documented workflow that automates the entire process inside the official manylinux container, bringing my compile times down to under 30 minutes on a 16-core CPU. 
The goal was to create a fast, reproducible, and—most importan…
  </blockquote>
</aside>