Installing PyTorch from Source

username: khushi-411
cooked: <p>Hi,<br>
I want to build PyTorch from Source with CUDA. I followed the official documentation. But I’m getting the following error:</p>
<pre><code class="lang-auto">================================================ ERRORS ================================================
_______________pytest test/test_nn.py -k test_total_length____________________ ERROR collecting test/test_nn.py ___________________________________
ImportError while importing test module '/home/khushi/Documents/opensource/pytorch/test/test_nn.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test/test_nn.py:47: in &lt;module&gt;
    from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes, \
E   ImportError: cannot import name 'onlyNativeDeviceTypes' from 'torch.testing._internal.common_device_type' (/usr/lib/python3.10/site-packages/torch/testing/_internal/common_device_type.py)
------------------------------------------- Captured stdout --------------------------------------------
Fail to import hypothesis in common_utils, tests are not derandomized
=========================================== warnings summary ===========================================
../../../../../usr/lib/python3.10/site-packages/packaging/version.py:127
../../../../../usr/lib/python3.10/site-packages/packaging/version.py:127
  /usr/lib/python3.10/site-packages/packaging/version.py:127: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================= short test summary info ========================================
ERROR test/test_nn.py
</code></pre>
<p>Command to run the test:</p>
<pre><code class="lang-auto">pytest test/test_nn.py -k test_total_length
</code></pre>
<h4>
<a name="dependencies-1" class="anchor" href="#dependencies-1"></a>Dependencies</h4>
<ul>
<li>Python: <code>3.10.1</code>
</li>
<li>Pytest: <code>6.2.5</code>
</li>
<li>Pluggy: <code>1.0.0</code>
</li>
<li>CUDA: <code>11.5</code>
</li>
<li>cuDNN: <code>8.3.1</code>
</li>
<li>Distro: <code>Manjaro Linux</code>
</li>
</ul>
<p>Will be very much thankful if any one of you can help me out to resolve this error?<br>
Thanks in advance <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=10" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: khushi-411
cooked: <p>Hey, Team!<br>
I resolved this issue. Just run the test using the following command:</p>
<pre><code class="lang-auto">python -m pytest test/test_nn.py
</code></pre>
<p>It worked. Thanks <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=10" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: khushi-411
cooked: <p>Hi, I wrote a blog about the same: <a href="https://khushi-411.github.io/installing-pytorch-from-source/" class="inline-onebox" rel="noopener nofollow ugc">Installing PyTorch from Source</a></p>
<p>I thought to share <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> it might help people! Thanks!</p>