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)
| 1641 | |
| 1642 | |
| 1643 | def _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 | |
| 1678 | def _ValidateParams(params): |
no test coverage detected
searching dependent graphs…