ModuleNotFoundError: No module named 'torch.utils._import_utils'

mael: <p>Hello,</p>
<p>I am currently executing a job on a cluster, but it halts due to an inability to locate a specific module. The log indicates the following error:</p>
<p>Traceback (most recent call last):<br>
File “/proj/users/xmal/RoseTTAFold2NA/network/predict.py”, line 8, in <br>
from RoseTTAFoldModel  import RoseTTAFoldModule<br>
File “/proj/users/xmal/RoseTTAFold2NA/network/RoseTTAFoldModel.py”, line 3, in <br>
from Embeddings import MSA_emb, Extra_emb, Templ_emb, Recycling<br>
File “/proj/users/xmal/RoseTTAFold2NA/network/Embeddings.py”, line 7, in <br>
from util_module import Dropout, get_clones, create_custom_forward, rbf, init_lecun_normal<br>
File “/proj/users/xmal/RoseTTAFold2NA/networkutil_module.py”, line 7, in <br>
import dgl<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/<strong>init</strong>.py”, line 16, in <br>
from . import (<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/dataloading/<strong>init</strong>.py”, line 13, in <br>
from .dataloader import *<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/dataloading/dataloader.py”, line 27, in <br>
from …distributed import DistGraph<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/distributed/<strong>init</strong>.py”, line 5, in <br>
from .dist_graph import DistGraph, DistGraphServer, edge_split, node_split<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/distributed/dist_graph.py”, line 11, in <br>
from … import backend as F, graphbolt as gb, heterograph_index<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/graphbolt/<strong>init</strong>.py”, line 8, in <br>
from .base import *<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/graphbolt/base.py”, line 8, in <br>
from torchdata.datapipes.iter import IterDataPipe<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/torchdata/datapipes/<strong>init</strong>.py”, line 11, in <br>
from . import iter, map, utils<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/torchdata/datapipes/iter/<strong>init</strong>.py”, line 79, in <br>
from torchdata.datapipes.iter.util.cacheholder import (<br>
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/torchdata/datapipes/iter/util/cacheholder.py”, line 24, in <br>
from torch.utils._import_utils import dill_available<br>
ModuleNotFoundError: No module named ‘torch.utils._import_utils’</p>
<p>Version I have in my env<br>
pytorch-cuda              11.7<br>
pytorch-mutex             1.0<br>
torch                     2.1.2<br>
torch-utils               0.1.2<br>
torchaudio                2.2.2<br>
torchdata                 0.8.0<br>
torchvision               0.17.2</p>
<p>Any help would be appreciated thanks!</p>

ptrblck: <p>The failing function was merged in Jan 2024 in <a href="https://github.com/pytorch/pytorch/pull/116214">this PR</a> and your PyTorch release is thus too old. Update PyTorch and rerun your script again.</p>

mael: <p>This helps, but raises another error for FileNotFoundError: Cannot find DGL C++ graphbolt library at /home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/graphbolt/libgraphbolt_pytorch_2.3.1.so</p>
<p>If i changed to another version then this error is solved, but ‘torch.utils’ raises again.</p>

Lexz: <p>I have exactly that problem, and you are right, upgrading PyTorch raises the C++ graphbolt error. This issue is not solved.</p>

mael: <p>solved it by locating the missing libgraphbolt_pytorch_2.3.1.so file with find</p>
<p>then export it<br>
export LD_LIBRARY_PATH={path to libgraphbolt .so file}:$LD_LIBRARY_PATH</p>
<p>hope this helps!</p>

Forest-Lee: <p>torch==2.1.0 &amp; torchdata==0.7.0 works for me about both these two errors, hope it helps.</p>

523718: <p>when i finished this step,and then another problem occured.ModuleNotFoundError: No module named ‘dgl.graphbolt’.</p>
<p>firstly,this problem occured: [ModuleNotFoundError: No module named ‘torch.utils._import_utils’],and then i upgraded it.  Then this problem occured: Cannot find DGL C++ graphbolt library, i find this file and put it to the right place.but it has this problem.</p>
<p>Version I have in my env<br>
pytorch-cuda 11.8<br>
torch                   2.2.2+cu118<br>
torchaudio              2.2.2+cu118<br>
torchdata               0.8.0<br>
torchvision             0.17.2+cu118<br>
dgl                     1.1.2+cu118</p>

523718: <p>when i finished this step,and then another problem occured.ModuleNotFoundError: No module named ‘dgl.graphbolt’.</p>
<p>firstly,this problem occured: [ModuleNotFoundError: No module named ‘torch.utils._import_utils’],and then i upgraded it.  Then this problem occured: Cannot find DGL C++ graphbolt library, i find this file and put it to the right place.but it has this problem.</p>
<p>Version I have in my env<br>
pytorch-cuda 11.8<br>
torch                   2.2.2+cu118<br>
torchaudio              2.2.2+cu118<br>
torchdata               0.8.0<br>
torchvision             0.17.2+cu118<br>
dgl                     1.1.2+cu118</p>

ptrblck: <p>I’m not familiar with DGL and the error is unrelated to PyTorch but you could take a look at <a href="https://discuss.pytorch.org/t/modulenotfounderror-no-module-named-torch-utils-import-utils/208935/5">this post</a> which solved the same issue.</p>

523718: <p>ok，thank you so much</p>

organicyes: <p><a href="https://www.dgl.ai/pages/start.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://www.dgl.ai/pages/start.html</a></p>
<p>install dgl according to your torch version. that solved my issue</p>

523718: <p>i changed torch version,and it did not occur this problem again,it just lacks some packings. i don’t know if this works .in this web site: <a href="https://www.dgl.ai/pages/start.html" rel="noopener nofollow ugc">Deep Graph Library (dgl.ai)</a>,it talks windows uses 2.0 2.1 torch version.so the following is my env:openhgnn2<br>
torch 2.0.0+cu118<br>
torchaudio 2.0.0+cu118<br>
torchdata 0.6.0<br>
torchvision 0.15.0+cu118<br>
dgl 1.1.2+cu118<br>
i hope this can help you</p>

MikuSugar: <p>Thanks,this works for me</p>

zhaoyuan_Zeng: <p>Thanks! It helps me, too.</p>

xuanzera: <p>Of Course.I use torch2.0.0 but installed dgl newest version with pip. So I reinstall it and it works.</p>