(self, ys)
| 991 | AUTOGEN_GRAD_SUFFIX = "_autogen_grad" |
| 992 | |
| 993 | def _GetInitGradients(self, ys): |
| 994 | input_to_grad = {} |
| 995 | gradient_ops = [] |
| 996 | |
| 997 | for y, g in ys.items(): |
| 998 | autograd_op = None |
| 999 | if g is None: |
| 1000 | autograd_op = CreateOperator( |
| 1001 | "ConstantFill", [y], [str(y) + IR.AUTOGEN_GRAD_SUFFIX], |
| 1002 | value=1.0) |
| 1003 | gradient_ops.append(autograd_op) |
| 1004 | g = autograd_op.output[0] |
| 1005 | # Since the C++ gradient registry does not have notion of |
| 1006 | # NameScopes, we will convert all references to strings. |
| 1007 | input_to_grad[str(y)] = ( |
| 1008 | GradientSlice(str(g[0]), str(g[1])) |
| 1009 | if isinstance(g, GradientSlice) else str(g)) |
| 1010 | # Autogenerated gradients are assumed to be provided for the last |
| 1011 | # input version |
| 1012 | if autograd_op is not None: |
| 1013 | self._AppendAutoGradGenerator(y, g, autograd_op) |
| 1014 | |
| 1015 | return input_to_grad, gradient_ops |
| 1016 | |
| 1017 | def _GenerateGradientsForForwardOp( |
| 1018 | self, forward_op_idx, input_to_grad): |
no test coverage detected