(param_name, grad, param_to_device=None, default_device=None)
| 2045 | |
| 2046 | |
| 2047 | def get_param_device(param_name, grad, param_to_device=None, default_device=None): |
| 2048 | device = default_device |
| 2049 | param_to_device = param_to_device or {} |
| 2050 | # We first check if parameter's device has been inferred. If not, |
| 2051 | # we check the gradient. This can happen if parameter is not output |
| 2052 | # by any blob but created by a FetchBlob. |
| 2053 | if param_name in param_to_device: |
| 2054 | device = param_to_device[param_name] |
| 2055 | else: |
| 2056 | if isinstance(grad, core.GradientSlice): |
| 2057 | grad = grad |
| 2058 | if str(grad.values) in param_to_device: |
| 2059 | device = param_to_device[str(grad.values)] |
| 2060 | elif str(grad.indices) in param_to_device: |
| 2061 | device = param_to_device[str(grad.indices)] |
| 2062 | else: |
| 2063 | grad_name = str(grad) |
| 2064 | if grad_name in param_to_device: |
| 2065 | device = param_to_device[grad_name] |
| 2066 | |
| 2067 | assert device is not None, "Cannot infer device for {}: no op creates it".format( |
| 2068 | param_name |
| 2069 | ) |
| 2070 | return device |
| 2071 | |
| 2072 | |
| 2073 | def get_lr_injection(): |
no test coverage detected
searching dependent graphs…