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

Hello,

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:

Traceback (most recent call last):
File “/proj/users/xmal/RoseTTAFold2NA/network/predict.py”, line 8, in
from RoseTTAFoldModel import RoseTTAFoldModule
File “/proj/users/xmal/RoseTTAFold2NA/network/RoseTTAFoldModel.py”, line 3, in
from Embeddings import MSA_emb, Extra_emb, Templ_emb, Recycling
File “/proj/users/xmal/RoseTTAFold2NA/network/Embeddings.py”, line 7, in
from util_module import Dropout, get_clones, create_custom_forward, rbf, init_lecun_normal
File “/proj/users/xmal/RoseTTAFold2NA/networkutil_module.py”, line 7, in
import dgl
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/init.py”, line 16, in
from . import (
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/dataloading/init.py”, line 13, in
from .dataloader import *
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/dataloading/dataloader.py”, line 27, in
from …distributed import DistGraph
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/distributed/init.py”, line 5, in
from .dist_graph import DistGraph, DistGraphServer, edge_split, node_split
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/distributed/dist_graph.py”, line 11, in
from … import backend as F, graphbolt as gb, heterograph_index
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/graphbolt/init.py”, line 8, in
from .base import *
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/dgl/graphbolt/base.py”, line 8, in
from torchdata.datapipes.iter import IterDataPipe
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/torchdata/datapipes/init.py”, line 11, in
from . import iter, map, utils
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/torchdata/datapipes/iter/init.py”, line 79, in
from torchdata.datapipes.iter.util.cacheholder import (
File “/home/xmal/.conda/envs/RF2NA/lib/python3.10/site-packages/torchdata/datapipes/iter/util/cacheholder.py”, line 24, in
from torch.utils._import_utils import dill_available
ModuleNotFoundError: No module named ‘torch.utils._import_utils’

Version I have in my env
pytorch-cuda 11.7
pytorch-mutex 1.0
torch 2.1.2
torch-utils 0.1.2
torchaudio 2.2.2
torchdata 0.8.0
torchvision 0.17.2

Any help would be appreciated thanks!

The failing function was merged in Jan 2024 in this PR and your PyTorch release is thus too old. Update PyTorch and rerun your script again.

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

If i changed to another version then this error is solved, but ‘torch.utils’ raises again.

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

solved it by locating the missing libgraphbolt_pytorch_2.3.1.so file with find

then export it
export LD_LIBRARY_PATH={path to libgraphbolt .so file}:$LD_LIBRARY_PATH

hope this helps!

torch==2.1.0 & torchdata==0.7.0 works for me about both these two errors, hope it helps.

2 Likes

when i finished this step,and then another problem occured.ModuleNotFoundError: No module named ‘dgl.graphbolt’.

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.

Version I have in my env
pytorch-cuda 11.8
torch 2.2.2+cu118
torchaudio 2.2.2+cu118
torchdata 0.8.0
torchvision 0.17.2+cu118
dgl 1.1.2+cu118

when i finished this step,and then another problem occured.ModuleNotFoundError: No module named ‘dgl.graphbolt’.

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.

Version I have in my env
pytorch-cuda 11.8
torch 2.2.2+cu118
torchaudio 2.2.2+cu118
torchdata 0.8.0
torchvision 0.17.2+cu118
dgl 1.1.2+cu118

I’m not familiar with DGL and the error is unrelated to PyTorch but you could take a look at this post which solved the same issue.

ok,thank you so much

https://www.dgl.ai/pages/start.html

install dgl according to your torch version. that solved my issue

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: Deep Graph Library (dgl.ai),it talks windows uses 2.0 2.1 torch version.so the following is my env:openhgnn2
torch 2.0.0+cu118
torchaudio 2.0.0+cu118
torchdata 0.6.0
torchvision 0.15.0+cu118
dgl 1.1.2+cu118
i hope this can help you

Thanks,this works for me

Thanks! It helps me, too.