Checked the scatter implementation, and looks like it can scatter tensors in dictionaries properly. What is the structure of the blobs var that scatter fails to handle?

  
      github.com
  
  
    pytorch/pytorch/blob/13dd53b3d2ba16d353ff1fe3c535c9dd79c19e8d/torch/nn/parallel/scatter_gather.py#L5-L31 3

def scatter(inputs, target_gpus, dim=0):
    r"""
    Slices tensors into approximately equal chunks and
    distributes them across given GPUs. Duplicates
    references to objects that are not tensors.
    """
    def scatter_map(obj):
        if isinstance(obj, torch.Tensor):
            return Scatter.apply(target_gpus, None, dim, obj)
        if isinstance(obj, tuple) and len(obj) > 0:
            return list(zip(*map(scatter_map, obj)))
        if isinstance(obj, list) and len(obj) > 0:
            return list(map(list, zip(*map(scatter_map, obj))))
        if isinstance(obj, dict) and len(obj) > 0:
            return list(map(type(obj), zip(*map(scatter_map, obj.items()))))
        return [obj for targets in target_gpus]

    # After scatter_map is called, a scatter_map cell will exist. This cell
    # has a reference to the actual function scatter_map, which has references
    # to a closure that has a reference to the scatter_map cell (because the


  This file has been truncated. show original

  
  
    
    
  
  


>>> x = {1:1, 2:2}
>>> x.items()
dict_items([(1, 1), (2, 2)])
>>> import torch
>>> from torch.nn.parallel.scatter_gather import scatter
>>> scatter(x, target_gpus=[0, 1])
[{1: 1, 2: 2}, {1: 1, 2: 2}]
>>> y = {1: torch.zeros(4, 4).to(0), 2: torch.zeros(4, 4).to(0)}
>>> scatter(y, target_gpus=[0, 1])
[{1: tensor([[0., 0., 0., 0.],
        [0., 0., 0., 0.]], device='cuda:0'), 2: tensor([[0., 0., 0., 0.],
        [0., 0., 0., 0.]], device='cuda:0')}, {1: tensor([[0., 0., 0., 0.],
        [0., 0., 0., 0.]], device='cuda:1'), 2: tensor([[0., 0., 0., 0.],
        [0., 0., 0., 0.]], device='cuda:1')}]