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

Method GetGradientForOp

caffe2/python/core.py:1163–1182  ·  view source on GitHub ↗
(cls, op, g_output)

Source from the content-addressed store, hash-verified

1161
1162 @classmethod
1163 def GetGradientForOp(cls, op, g_output):
1164 try:
1165 gradient_ops, g_input = cls._GetGradientForOpCC(op, g_output)
1166 except Exception as e:
1167 # Not supported in C++; will try python registration next.
1168 if op.type in cls.gradient_registry_:
1169 gradient_ops, g_input = cls.gradient_registry_[op.type](
1170 op, g_output
1171 )
1172 else:
1173 raise Exception(
1174 "Exception when creating gradient for [{}]:{}.\nOp: \n{}".
1175 format(op.type, e, str(op))
1176 ) from e
1177
1178 if gradient_ops is None:
1179 return [], g_input
1180 if type(gradient_ops) is not list:
1181 gradient_ops = [gradient_ops]
1182 return gradient_ops, g_input
1183
1184 @classmethod
1185 def GetBackwardPass(cls, operators, ys, ys_generate_gradient=False):

Callers 3

getGradientForOpFunction · 0.80
test_hsm_forwardMethod · 0.80

Calls 3

ExceptionClass · 0.85
_GetGradientForOpCCMethod · 0.80
formatMethod · 0.45

Tested by 1

test_hsm_forwardMethod · 0.64