(
blob_names,
devices,
model,
net,
rendezvous,
max_concurrent_distributed_ops,
)
| 1345 | |
| 1346 | |
| 1347 | def _AllReduceBlobsDistributed( |
| 1348 | blob_names, |
| 1349 | devices, |
| 1350 | model, |
| 1351 | net, |
| 1352 | rendezvous, |
| 1353 | max_concurrent_distributed_ops, |
| 1354 | ): |
| 1355 | num_workers = model.net.Proto().num_workers |
| 1356 | assert num_workers > 1, "Please specify more than 1 worker" |
| 1357 | all_reduce_engine = rendezvous['engine'] |
| 1358 | |
| 1359 | master_device_opt = core.DeviceOption(model._device_type, devices[0]) |
| 1360 | |
| 1361 | reducing_device_opt = master_device_opt |
| 1362 | |
| 1363 | context = CollectivesConcurrencyControl( |
| 1364 | "allreduce", |
| 1365 | max_concurrent_distributed_ops, |
| 1366 | model.param_init_net, |
| 1367 | rendezvous |
| 1368 | ) |
| 1369 | |
| 1370 | nccl_control_blob = None |
| 1371 | |
| 1372 | for blob_name in blob_names: |
| 1373 | master_blob = model._device_grouped_blobs[blob_name][devices[0]] |
| 1374 | blobs_group = list(model._device_grouped_blobs[blob_name].values()) |
| 1375 | |
| 1376 | assert master_blob in blobs_group |
| 1377 | |
| 1378 | # Remark: NCCLReduce does not support in-place modifications |
| 1379 | # so we need a temporary blob |
| 1380 | reduced_blob = str(master_blob) + "_red" |
| 1381 | |
| 1382 | def allreduce(blobs, **kwargs): |
| 1383 | with core.DeviceScope(reducing_device_opt): |
| 1384 | comm_world, control_input = \ |
| 1385 | context.get_control_and_context(blobs[0]) |
| 1386 | net.Allreduce( |
| 1387 | inputs=[comm_world] + blobs, |
| 1388 | outputs=blobs, |
| 1389 | name=blob_name, |
| 1390 | engine=all_reduce_engine, |
| 1391 | control_input=control_input, |
| 1392 | **kwargs |
| 1393 | ) |
| 1394 | |
| 1395 | if rendezvous['engine'] == 'GLOO': |
| 1396 | # With Gloo cross GPU and cross machine allreduce |
| 1397 | # can be executed in a single operation. |
| 1398 | # Try to use GPUDirect if transport == ibverbs. |
| 1399 | allreduce( |
| 1400 | blobs_group, |
| 1401 | gpu_direct=(rendezvous.get("transport", None) == "ibverbs"), |
| 1402 | ) |
| 1403 | else: |
| 1404 | # Step 1: sum blobs from local GPUs to master GPU |
no test coverage detected
searching dependent graphs…