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

Function MeanGrad

tensorflow/cc/gradients/math_grad.cc:742–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

740REGISTER_GRADIENT_OP("Sum", SumGrad);
741
742Status MeanGrad(const Scope& scope, const Operation& op,
743 const std::vector<Output>& grad_inputs,
744 std::vector<Output>* grad_outputs) {
745 // The Mean gradient is just like the Sum gradient, except that
746 // all gradients are also divided by the size of reduced groups.
747 auto sum_grad = SumGradHelper(scope, op, grad_inputs);
748
749 // The product of all entries in a tensor's shape is the total
750 // number of entries in the tensor. This step calculates
751 // n_input_entries/n_output_entries
752 // = group_size
753 auto input_shape = Shape(scope, op.input(0));
754 auto output_shape = Shape(scope, op.output(0));
755 auto zero = Const(scope, 0);
756 auto group_size = SafeDivHelper(scope, Prod(scope, input_shape, zero),
757 Prod(scope, output_shape, zero));
758
759 // propagate sum_grad/group_size
760 grad_outputs->push_back(
761 Div(scope, sum_grad, Cast(scope, group_size, sum_grad.type())));
762
763 // Stop propagation along reduction_indices
764 grad_outputs->push_back(NoGradient());
765 return scope.status();
766}
767REGISTER_GRADIENT_OP("Mean", MeanGrad);
768
769Status ErfGrad(const Scope& scope, const Operation& op,

Callers

nothing calls this directly

Calls 13

SumGradHelperFunction · 0.85
SafeDivHelperFunction · 0.85
NoGradientFunction · 0.85
outputMethod · 0.65
typeMethod · 0.65
ShapeClass · 0.50
ConstFunction · 0.50
ProdClass · 0.50
DivFunction · 0.50
CastFunction · 0.50
inputMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected