MCPcopy Index your code
hub / github.com/pytorch/pytorch / _SyncAllParamsDistributed

Function _SyncAllParamsDistributed

caffe2/python/data_parallel_model.py:1171–1229  ·  view source on GitHub ↗
(
    devices,
    model,
    init_net,
    net,
    rendezvous,
    unique_param_names,
    max_concurrent_distributed_ops
)

Source from the content-addressed store, hash-verified

1169
1170
1171def _SyncAllParamsDistributed(
1172 devices,
1173 model,
1174 init_net,
1175 net,
1176 rendezvous,
1177 unique_param_names,
1178 max_concurrent_distributed_ops
1179):
1180 assert rendezvous['num_shards'] > 1
1181
1182 gpu_device_opt = core.DeviceOption(model._device_type, devices[0])
1183 cpu_device_opt = core.DeviceOption(caffe2_pb2.CPU)
1184 ideep_device_opt = core.DeviceOption(caffe2_pb2.IDEEP)
1185
1186 if model._broadcast_context is None:
1187 model._broadcast_context = CollectivesConcurrencyControl(
1188 "broadcast",
1189 max_concurrent_distributed_ops,
1190 init_net,
1191 rendezvous
1192 )
1193 context = model._broadcast_context
1194
1195 for param_name in sorted(unique_param_names):
1196 master_param = model._device_grouped_blobs[param_name][devices[0]]
1197 params_group = list(model._device_grouped_blobs[param_name].values())
1198
1199 def broadcast(params):
1200 comm_world, control_input = context.get_control_and_context(params)
1201 net.Broadcast(
1202 inputs=[comm_world] + params,
1203 outputs=params,
1204 name=param_name,
1205 engine=rendezvous['engine'],
1206 control_input=control_input
1207 )
1208
1209 device_opt = gpu_device_opt if _IsGPUBlob(
1210 model, param_name
1211 ) else ideep_device_opt if _IsIDEEPBlob(model, param_name) else cpu_device_opt
1212
1213 if rendezvous['engine'] == 'GLOO':
1214 with core.DeviceScope(device_opt):
1215 broadcast(params_group)
1216 else:
1217 # Copy between GPU and CPU
1218 with core.DeviceScope(device_opt):
1219 param_cpu = net.CopyGPUToCPU(
1220 master_param,
1221 str(master_param) + "cpu"
1222 )
1223 with core.DeviceScope(cpu_device_opt):
1224 broadcast([param_cpu])
1225 with core.DeviceScope(device_opt):
1226 net.CopyCPUToGPU(param_cpu, master_param)
1227
1228 # Broadcast locally

Callers 1

_SyncAllParamsFunction · 0.85

Calls 7

listFunction · 0.85
_IsGPUBlobFunction · 0.85
_IsIDEEPBlobFunction · 0.85
broadcastFunction · 0.70
_BroadcastFunction · 0.70
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…