question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting error: ImportError: cannot import name 'ProcessGroup' from 'torch.distributed'

See original GitHub issue

Discussed in https://github.com/facebookresearch/detectron2/discussions/4549

<div type='discussions-op-text'>

Originally posted by hqm September 18, 2022 I am trying to run detectron2 on an NVIDIA Jetson ARM-based system using a docker container.

I am using a prebuilt pytorch container image from NVIDIA nvcr.io/nvidia/l4t-pytorch:r35.1.0-pth1.12-py3 as a base image This has these versions prebuilt and installed:

l4t-pytorch:r35.1.0-pth1.12-py3
PyTorch v1.12.0
torchvision v0.13.0
torchaudio v0.12.0

I’m installing detectron2 with these commands

RUN git clone https://github.com/facebookresearch/detectron2.git
RUN pip3 install -e detectron2

And when I try to run a detectron2 application, I get this error “cannot import name ‘ProcessGroup’ from ‘torch.distributed’”

I’ve read on the net people say that pytorch is probably not compiled with ‘distributed’ option, so perhaps building it with that option would fix this, but I don’t really want to build it from scratch, given that this container has a nice prebuilt version.

stacktrace below:

File "vision/server.py", line 45, in <module>
  from processor import VisionProcessor
File "/home/work/vision/processor.py", line 28, in <module>
  from predictors import *
File "/home/work/vision/predictors.py", line 27, in <module>
  from detectron2.engine.defaults import DefaultPredictor
File "/home/detectron2/detectron2/engine/__init__.py", line 12, in <module>
  from .defaults import *
File "/home/detectron2/detectron2/engine/defaults.py", line 38, in <module>
  from detectron2.modeling import build_model
File "/home/detectron2/detectron2/modeling/__init__.py", line 5, in <module>
  from .backbone import (
File "/home/detectron2/detectron2/modeling/backbone/__init__.py", line 15, in <module>
  from .vit import ViT, SimpleFeaturePyramid, get_vit_lr_decay_rate
File "/home/detectron2/detectron2/modeling/backbone/vit.py", line 10, in <module>
  from fairscale.nn.checkpoint import checkpoint_wrapper
File "/usr/local/lib/python3.8/dist-packages/fairscale/__init__.py", line 12, in <module>
  from . import nn
File "/usr/local/lib/python3.8/dist-packages/fairscale/nn/__init__.py", line 9, in <module>
  from .data_parallel import FullyShardedDataParallel, ShardedDataParallel
File "/usr/local/lib/python3.8/dist-packages/fairscale/nn/data_parallel/__init__.py", line 8, in <module>
  from .fully_sharded_data_parallel import (
File "/usr/local/lib/python3.8/dist-packages/fairscale/nn/data_parallel/fully_sharded_data_parallel.py", line 38, in <module>
  from torch.distributed import ProcessGroup
ImportError: cannot import name 'ProcessGroup' from 'torch.distributed' (/usr/local/lib/python3.8/dist-packages/torch/distributed/__init__.py)

Anyone know what causes this? Should I use PyTorch v1.11.0 instead of v1.12.0? Or is there a pinned version of detectron2 I should install ?

</div>

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
ppwwyyxxcommented, Sep 22, 2022
1reaction
wartek69commented, Sep 23, 2022

What is the workaround ?

The fairscale implemented a hotfix. You can install the new fairscale version from source as described here: https://github.com/facebookresearch/fairscale/blob/main/docs/source/installation_instructions.rst. That solves the issue for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot import name 'ProcessGroup' from 'torch.distributed ...
When trying to import ProcessGroup from torch.distributed I get import error: 'ImportError: cannot import name 'ProcessGroup' from 'torch.
Read more >
Torch distributed, ProcessGroup import error
I'm hitting some error trying to run some code as I can't import 'ProcessGroup' Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] ......
Read more >
Pytorch error on multi-GPU setup: cannot import name ...
I removed the torch and torchvision and re-installed them using the following command: conda install pytorch torchvision cuda100 -c pytorch ...
Read more >
distributed/distributed_c10d.py · neilisaac/torch - Gemfury
_distributed_c10d import ProcessGroupMPI except ImportError: _MPI_AVAILABLE ... raise ValueError("Backend name must be a string, but got: {}".format(name)) ...
Read more >
Cannot import torch in Apple M1 Macbook - PyTorch Forums
__version__)) import torch torch.device("mps") torch.__ver… ... in fbcode build ImportError: cannot import name 'classproperty' from 'torch.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found