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

Function get_param_device

caffe2/python/optimizer.py:2047–2070  ·  view source on GitHub ↗
(param_name, grad, param_to_device=None, default_device=None)

Source from the content-addressed store, hash-verified

2045
2046
2047def 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
2073def get_lr_injection():

Callers 5

apply_optimizersMethod · 0.90
modify_netMethod · 0.90
_calc_norm_ratioFunction · 0.85
_buildFunction · 0.85

Calls 2

isinstanceFunction · 0.85
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…