I am getting started with torch, and trying to understand the object detection support in it using https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html 13
I am having trouble paralleilizing the faster-rcnn model. I get the following error when running train_one_epoch in engine.py,
RuntimeError: chunk expects at least a 1-dimensional tensor (chunk at /pytorch/aten/src/ATen/native/TensorShape.cpp:188)
What am I doing wrong?
I parallelized using the following,
backbone = torchvision.models.resnet50(pretrained=True)   # commented out torch.flatten
backbone.avgpool = torch.nn.Identity()
backbone.fc = torch.nn.Identity()
backbone.out_channels = 2048
model = FasterRCNN(backbone=backbone,
rpn_anchor_generator=anchor_generator,
box_roi_pool=roi_align,
num_classes=81)
device = torch.device(“cuda”) if torch.cuda.is_available() else torch.device(“cpu”)
model.to(device)
parallel_model = torch.nn.DataParallel(model)  # need to first freeze batch norm
Debugging with pdb seems to suggest that it is trying to scatter “image_id” in the target dictionary. I thought I was applying torch.nn.DataParallel in the wrong place, so looked at https://github.com/pytorch/vision/blob/master/references/detection/train.py 10, but it seems fine.
I also unsuccessfully tried using torch.nn.parallel.DistributedDataParallel in the following way,
torch.distributed.init_process_group(backend=‘nccl’, world_size=1, rank=0)
parallel_model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[0])
python3 -m torch.distributed.launch --nproc_per_node=1 --use_env train_faster_rcnn.py