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

Function MatMulGradCommon

tensorflow/cc/gradients/math_grad.cc:1089–1120  ·  view source on GitHub ↗

MatMulGrad common used to read and check node attr state, and determine proper MatMul products for gradients based on input matrix transposition combinations.

Source from the content-addressed store, hash-verified

1087// proper MatMul products for gradients based on input matrix transposition
1088// combinations.
1089Status MatMulGradCommon(const Scope& scope, const Operation& op,
1090 const bool is_batch,
1091 const std::vector<Output>& grad_inputs,
1092 const string& attr_adj_x, const string& attr_adj_y,
1093 std::vector<Output>* grad_outputs) {
1094 auto a = op.input(0);
1095 auto b = op.input(1);
1096 // Use conjugate of the inputs for MatMul
1097 if (is_batch == false) {
1098 a = ConjugateHelper(scope, a);
1099 b = ConjugateHelper(scope, b);
1100 }
1101 auto product = op.output(0);
1102
1103 bool ta;
1104 bool tb;
1105 TF_RETURN_IF_ERROR(GetNodeAttr(product.node()->attrs(), attr_adj_x, &ta));
1106 TF_RETURN_IF_ERROR(GetNodeAttr(product.node()->attrs(), attr_adj_y, &tb));
1107
1108 if (!ta && !tb) {
1109 return MatMulGradHelper(scope, is_batch, grad_inputs[0], false, b, true, a,
1110 true, grad_inputs[0], false, grad_outputs);
1111 } else if (!ta && tb) {
1112 return MatMulGradHelper(scope, is_batch, grad_inputs[0], false, b, false,
1113 grad_inputs[0], true, a, false, grad_outputs);
1114 } else if (ta && !tb) {
1115 return MatMulGradHelper(scope, is_batch, b, false, grad_inputs[0], true, a,
1116 false, grad_inputs[0], false, grad_outputs);
1117 }
1118 return MatMulGradHelper(scope, is_batch, b, true, grad_inputs[0], true,
1119 grad_inputs[0], true, a, true, grad_outputs);
1120}
1121
1122Status MatMulGrad(const Scope& scope, const Operation& op,
1123 const std::vector<Output>& grad_inputs,

Callers 2

MatMulGradFunction · 0.70
BatchMatMulGradFunction · 0.70

Calls 7

ConjugateHelperFunction · 0.85
MatMulGradHelperFunction · 0.70
outputMethod · 0.65
GetNodeAttrFunction · 0.50
inputMethod · 0.45
attrsMethod · 0.45
nodeMethod · 0.45

Tested by

no test coverage detected