Installing PyTorch from Source

Hi,
I want to build PyTorch from Source with CUDA. I followed the official documentation. But I’m getting the following error:

================================================ 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 <module>
    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

Command to run the test:

pytest test/test_nn.py -k test_total_length

Dependencies

  • Python: 3.10.1
  • Pytest: 6.2.5
  • Pluggy: 1.0.0
  • CUDA: 11.5
  • cuDNN: 8.3.1
  • Distro: Manjaro Linux

Will be very much thankful if any one of you can help me out to resolve this error?
Thanks in advance :slight_smile:

Hey, Team!
I resolved this issue. Just run the test using the following command:

python -m pytest test/test_nn.py

It worked. Thanks :slight_smile:

Hi, I wrote a blog about the same: Installing PyTorch from Source

I thought to share :slight_smile: it might help people! Thanks!