| 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): |