(cls, op_def, g_output)
| 1120 | |
| 1121 | @classmethod |
| 1122 | def _GetGradientForOpCC(cls, op_def, g_output): |
| 1123 | # TODO(tulloch) - Propagate GradientWrapper up through the stack. |
| 1124 | def from_untyped(grad): |
| 1125 | if grad is None: |
| 1126 | w = C.GradientWrapper() |
| 1127 | assert w.is_empty() |
| 1128 | return w |
| 1129 | try: |
| 1130 | (indices, values) = grad |
| 1131 | w = C.GradientWrapper() |
| 1132 | w.indices = indices |
| 1133 | w.values = values |
| 1134 | assert w.is_sparse() |
| 1135 | return w |
| 1136 | except ValueError: |
| 1137 | w = C.GradientWrapper() |
| 1138 | w.dense = grad |
| 1139 | assert w.is_dense() |
| 1140 | return w |
| 1141 | |
| 1142 | g_output = [from_untyped(grad) for grad in g_output] |
| 1143 | grad_defs_str, g_input = C.get_gradient_defs( |
| 1144 | op_def.SerializeToString(), g_output) |
| 1145 | |
| 1146 | def to_untyped(grad_wrapper): |
| 1147 | if grad_wrapper.is_empty(): |
| 1148 | return None |
| 1149 | if grad_wrapper.is_sparse(): |
| 1150 | return GradientSlice(grad_wrapper.indices, grad_wrapper.values) |
| 1151 | assert grad_wrapper.is_dense() |
| 1152 | return grad_wrapper.dense |
| 1153 | |
| 1154 | g_input = [to_untyped(grad_wrapper) for grad_wrapper in g_input] |
| 1155 | grad_defs = [] |
| 1156 | for grad_def_str in grad_defs_str: |
| 1157 | grad_def = caffe2_pb2.OperatorDef() |
| 1158 | grad_def.ParseFromString(grad_def_str) |
| 1159 | grad_defs.append(grad_def) |
| 1160 | return grad_defs, g_input |
| 1161 | |
| 1162 | @classmethod |
| 1163 | def GetGradientForOp(cls, op, g_output): |
no test coverage detected