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

Function _ComputeBlobsToSync

caffe2/python/data_parallel_model.py:1691–1731  ·  view source on GitHub ↗

We sync all blobs that are generated by param init net and are 'data parallel', i.e assigned to a device

(model)

Source from the content-addressed store, hash-verified

1689
1690
1691def _ComputeBlobsToSync(model):
1692 '''
1693 We sync all blobs that are generated by param init net and
1694 are 'data parallel', i.e assigned to a device
1695 '''
1696 sync_names = set()
1697
1698 # We don't sync params if the model is shared
1699 if model._shared_model:
1700 blobs_to_sync = [str(p) for p in model.GetComputedParams('')]
1701 sync_names = [stripBlobName(p) for p in blobs_to_sync]
1702 else:
1703 blobs_to_sync = []
1704
1705 for op in model.param_init_net.Proto().op:
1706 dp_outputs = [
1707 o for o in op.output
1708 if o.startswith("{}_".format(model._device_prefix))
1709 ]
1710 sync_names.update([stripBlobName(o) for o in dp_outputs])
1711 blobs_to_sync.extend(dp_outputs)
1712
1713 # Sanity check
1714 diff = set(model._param_names) - sync_names
1715 assert diff == set(), \
1716 "Some params not instantiated in param init net: {}".format(diff)
1717
1718 # Remove duplicates and sort
1719 prefixlen = len(model._device_prefix) + 1
1720
1721 def extract_sort_key(b):
1722 # Sort first based on device id, and then by whole string
1723 deviceid = int(b[prefixlen:b.index(scope._NAMESCOPE_SEPARATOR)])
1724 return (deviceid, b)
1725
1726 blobs_to_sync = sorted(
1727 list(set(blobs_to_sync)),
1728 key=extract_sort_key)
1729
1730 blobs_to_sync = [core.BlobReference(b) for b in blobs_to_sync]
1731 return (blobs_to_sync, sync_names)
1732
1733
1734def _OptimizeGradientMemorySimple(model, losses_by_gpu, devices):

Callers 3

ParallelizeFunction · 0.85
GetCheckpointParamsFunction · 0.85
FinalizeAfterCheckpointFunction · 0.85

Calls 7

stripBlobNameFunction · 0.85
listFunction · 0.85
GetComputedParamsMethod · 0.80
ProtoMethod · 0.45
formatMethod · 0.45
updateMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…