Installing PyTorch from Source

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

================================================ ERRORS ================================================
_______________pytest test/ -k test_total_length____________________ ERROR collecting test/ ___________________________________
ImportError while importing test module '/home/khushi/Documents/opensource/pytorch/test/'.
Hint: make sure your test modules/packages have valid Python names.
/usr/lib/python3.10/importlib/ in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test/ 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/
------------------------------------------- Captured stdout --------------------------------------------
Fail to import hypothesis in common_utils, tests are not derandomized
=========================================== warnings summary ===========================================
  /usr/lib/python3.10/site-packages/packaging/ DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release

-- Docs:
======================================= short test summary info ========================================
ERROR test/

Command to run the test:

pytest test/ -k test_total_length


  • 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/

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!