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

Function _GroupByDevice

caffe2/python/data_parallel_model.py:1643–1675  ·  view source on GitHub ↗

Groups blobs by device, returning a map of [blobname] = {0: BlobRef, 1: ..}. Returns ordered dictionary, ensuring the original order.

(model, devices, params, non_data_params)

Source from the content-addressed store, hash-verified

1641
1642
1643def _GroupByDevice(model, devices, params, non_data_params):
1644 '''
1645 Groups blobs by device, returning a map of [blobname] = {0: BlobRef, 1: ..}.
1646 Returns ordered dictionary, ensuring the original order.
1647 '''
1648 grouped = OrderedDict()
1649 # Only consider params that were created to be "data parallel"
1650 params = params[len(non_data_params):]
1651
1652 for _i, p in enumerate(params):
1653 assert isinstance(p, core.BlobReference) or \
1654 isinstance(p, core.GradientSlice), \
1655 "Param {} is not BlobReference or GradientSlice".format(p)
1656
1657 name = stripBlobName(p)
1658 gpuid = None
1659
1660 if isinstance(p, core.BlobReference):
1661 gpuid = int(p.GetNameScope().split("_")[1].split("/")[0])
1662 assert "{}_{}/".format(model._device_prefix, gpuid) in p.GetNameScope(),\
1663 "Param {} expected to have namescope '{}_{}'".format(str(p), model._device_prefix, gpuid)
1664 else:
1665 gpuid = int(p.indices.GetNameScope().split("_")[1].split("/")[0])
1666 assert "{}_{}/".format(model._device_prefix, gpuid) in p.indices.GetNameScope(),\
1667 "Indices {} expected to have namescope '{}_{}'".format(str(p), model._device_prefix, gpuid)
1668 assert "{}_{}/".format(model._device_prefix, gpuid) in p.values.GetNameScope(),\
1669 "Values {} expected to have namescope '{}_{}'".format(str(p), model._device_prefix, gpuid)
1670
1671 if name not in grouped:
1672 grouped[name] = {}
1673 grouped[name][gpuid] = p
1674
1675 return grouped
1676
1677
1678def _ValidateParams(params):

Callers 2

ParallelizeFunction · 0.85
Parallelize_BMUFFunction · 0.85

Calls 5

isinstanceFunction · 0.85
stripBlobNameFunction · 0.85
GetNameScopeMethod · 0.80
formatMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…