Cannot import torch after a succesful custom pytorch build

Hello, I’m experiencing the following trouble:

Python 3.11.1 (main, Jan  6 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/path/pytorch/torch/", line 932, in <module>
    from ._tensor import Tensor
  File "/home/user/path/pytorch/torch/", line 12, in <module>
    import torch.utils.hooks as hooks
  File "/home/user/path/pytorch/torch/utils/", line 7, in <module>
    from .backend_registration import rename_privateuse1_backend
  File "/home/user/path/pytorch/torch/utils/", line 1, in <module>
    from torch._C import _rename_privateuse1_backend
ImportError: cannot import name '_rename_privateuse1_backend' from 'torch._C' (/home/user/path/pytorch/torch/

I used this building setup when compiling pytorch:
BUILD_TEST=0 CXX="/home/user/path/gcc_custom/bin/g++" CC="/home/user/path/gcc_custom/bin/gcc" CMAKE_CXX_FLAGS="-march=znver3 -fPIE" python develop --install-dir ~/.local/lib/python3.11/site-packages/

I had the pytorch switched to nightly branch (git 0a73b08b9f2)

I used gcc 11.1.0 and cuda 12.0 toolkit to link up to. The built was successful without any issues (at least as I could see).

I tried to inspect the**** and I was surprised that basically all of the static functions from torch/csrc/Module.cpp are missing (or perhaps I’m looking at wrong place, I’m not sure).

Has anyone solved this kind of problem. Or does anybody already know what I’m doing wrong from the description of the issue?

Thanks a lot

Are you running your REPL in the source directory?

 File "/home/user/path/pytorch/torch/utils/", line 1, in <module>
    from torch._C import _rename_privateuse1_backend
ImportError: cannot import name '_rename_privateuse1_backend' from 'torch._C' (/home/user/path/pytorch/torch/

The error points to source files located in your /home while you were trying to install it into a site-packages folder located in your /home
If so, switch the wdir and check if this would fix the error.

1 Like

Thank you a lot! I was staring at it for too long. You were right about wdir; and probably I had also have LD_LIBRARY_PATH crippled too. Thanks once again

1 Like