mmcv: ModuleNotFoundError: No module named 'mmcv.parallel'

您好, 我的程序中涉及:

from mmcv.parallel import MMDataParallel, MMDistributedDataParallel

但出现以下错误:

ModuleNotFoundError: No module named 'mmcv.parallel'

我的版本为:

mmcv                2.0.0rc4
mmengine            0.7.2
mmsegmentation      1.0.0
torch               1.12.1+cu113
torchaudio          0.12.1+cu113
torchvision         0.13.1+cu113

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

同问, 那在v2.0.0中怎么使用parallel包中的相关内容呢?例如, MMDataParallel, MMDistributedDataParallel

from mmcv.parallel import MMDataParallel, MMDistributedDataParallel in older versions from mmengine.model import MMDataParallel, MMDistributedDataParallel in new versions

Hi, the MMDistributedDataParallel in MMCV has been migrated to MMEngine (https://github.com/open-mmlab/mmengine/blob/426a565908e47f791938baa3a876a87de306b436/mmengine/model/wrappers/distributed.py#L16).

If the distributed environment is initialized (see https://mmengine.readthedocs.io/en/latest/common_usage/speed_up_training.html#distributed-training for details about how to launch distributed training), the MMDistributedDataParallel will be automatically wrapped for the model.

The logic to wrapper the model is in https://github.com/open-mmlab/mmengine/blob/426a565908e47f791938baa3a876a87de306b436/mmengine/runner/runner.py#L408.

Of course, we can pass the model_wrapper_cfg to the cfg of Runner in MMEngine to use the MMDistributedDataParallel.

runner = Runner(
    model=ResNet18(),
    work_dir='./work_dir',
    train_dataloader=train_dataloader_cfg,
    optim_wrapper=dict(
        type='AmpOptimWrapper',
        # If you want to use bfloat16, uncomment the following line
        # dtype='bfloat16',  # valid values: ('float16', 'bfloat16', None)
        optimizer=dict(type='SGD', lr=0.001, momentum=0.9)),
    train_cfg=dict(by_epoch=True, max_epochs=3),
    cfg=dict(model_wrapper_cfg=dict(type=MMDistributedDataParallel),
)
runner.train()

In addition, we also provide several documentation to help migration. https://mmengine.readthedocs.io/en/latest/migration/runner.html

Hi, the parallel has been removed from MMCV since v2.0.0. More details can be found at https://github.com/open-mmlab/mmcv/blob/main/docs/en/compatibility.md#v200.

同样的问题,请问您解决了吗

你好,我暂时“解决”了(因为我还是没找到最新版的mmcv的parallel变为什么了,我降低了版本);我现在的版本为:

torch               1.8.1+cu101
torchaudio          0.8.1
torchvision         0.9.1+cu101

mmcv-full           1.4.0
mmengine            0.7.2
mmsegmentation      0.14.0

我的安装命令为:

pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu112/torch1.6.0/index.html
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

引起上述问题的原因见:https://mmcv.readthedocs.io/en/latest/compatibility.html

image image

同样的问题,请问您解决了吗