MCPcopy Create free account
hub / github.com/pytorch/pytorch / sumN

Function sumN

caffe2/python/data_parallel_model.py:1054–1077  ·  view source on GitHub ↗

Create a Sum op for 2 or more blobs on different devices. Saves the result on the first device. Args: dev_indices -- a list of device indices, which can be translated into CUDA identifiers with model._devices

(*dev_indices)

Source from the content-addressed store, hash-verified

1052 p2p_access_pattern = None
1053
1054 def sumN(*dev_indices):
1055 """Create a Sum op for 2 or more blobs on different devices.
1056 Saves the result on the first device.
1057
1058 Args:
1059 dev_indices -- a list of device indices, which can be translated into
1060 CUDA identifiers with model._devices
1061 """
1062 devices = [model._devices[idx] for idx in dev_indices]
1063 blobs = [blobs_group[idx] for idx in dev_indices]
1064 device_opt = core.DeviceOption(model._device_type, devices[0])
1065 with core.DeviceScope(device_opt):
1066 for i, peer in enumerate(devices):
1067 if i == 0:
1068 continue # Skip the first device
1069 if p2p_access_pattern is not None and p2p_access_pattern.size and not p2p_access_pattern[
1070 devices[0], peer
1071 ]:
1072 # Copy from peer to d0
1073 blobs[i] = model.Copy(
1074 blobs[i],
1075 'gpu_{}/{}_gpu{}_copy'.format(devices[0], param, peer)
1076 )
1077 net.Sum(blobs, [blobs[0]], name='dpm')
1078
1079 if len(devices) == 16:
1080 # Special tree reduction for 16 gpus, TODO generalize like in muji.py

Callers 1

_AllReduceFunction · 0.85

Calls 2

SumMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…