def broadcast(tensor, devices):
 if (nccl.is_available([tensor]) and (len(set(devices)) == len(devices))):
  tensors = [tensor]
  for device in devices[1:]:
   with torch.cuda.device(device):
    tensors.append(type(tensor)(tensor.size()))
  nccl.broadcast(tensors)
  return tuple(tensors)
 return tuple((tensor.cuda(gpu, async=True) for gpu in devices))

def broadcast ( tensor , devices ) : if ( nccl . is_available ( [ tensor ] ) and ( len ( set ( devices ) ) == len ( devices ) ) ) : tensors = [ tensor ] for device in devices [ 1 : ] : with torch . cuda . device ( device ) : tensors . append ( type ( tensor ) ( tensor . size ( ) ) ) nccl . broadcast ( tensors ) return tuple ( tensors ) return tuple ( ( tensor . cuda ( gpu , async = True ) for gpu in devices ) )
find the first socket and use it to broadcast to all sockets including the socket itself .