| 1039 | REGISTER_GRADIENT_OP("Prod", ProdGrad); |
| 1040 | |
| 1041 | Status SegmentSumGrad(const Scope& scope, const Operation& op, |
| 1042 | const std::vector<Output>& grad_inputs, |
| 1043 | std::vector<Output>* grad_outputs) { |
| 1044 | // The SegmentSum operation sums segments of the Tensor that have the same |
| 1045 | // index in the segment_ids parameter. |
| 1046 | // i.e z = [2, 3, 4, 5], segment_ids [0, 0, 0, 1] |
| 1047 | // will produce [2 + 3 + 4, 5] = [9, 5] |
| 1048 | // The gradient that will flow back to the gather operation will look like |
| 1049 | // [x1, x2], it will have the same shape as the output of the SegmentSum |
| 1050 | // operation. The differentiation step of the SegmentSum operation just |
| 1051 | // broadcast the gradient in order to retrieve the z's shape. |
| 1052 | // dy/dz = [x1, x1, x1, x2] |
| 1053 | grad_outputs->push_back(Gather(scope, grad_inputs[0], op.input(1))); |
| 1054 | |
| 1055 | // stop propagation along segment_ids |
| 1056 | grad_outputs->push_back(NoGradient()); |
| 1057 | return scope.status(); |
| 1058 | } |
| 1059 | REGISTER_GRADIENT_OP("SegmentSum", SegmentSumGrad); |
| 1060 | |
| 1061 | // MatMulGrad helper function used to compute two MatMul operations |
nothing calls this directly
no test coverage detected