MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / SegmentSumGrad

Function SegmentSumGrad

tensorflow/cc/gradients/math_grad.cc:1041–1058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1039REGISTER_GRADIENT_OP("Prod", ProdGrad);
1040
1041Status 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}
1059REGISTER_GRADIENT_OP("SegmentSum", SegmentSumGrad);
1060
1061// MatMulGrad helper function used to compute two MatMul operations

Callers

nothing calls this directly

Calls 5

NoGradientFunction · 0.85
GatherFunction · 0.50
push_backMethod · 0.45
inputMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected