MCPcopy Create free account
hub / github.com/alibaba/MNN / onGrad

Method onGrad

tools/train/source/grad/SelectGrad.cpp:20–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 mType = SEMI_LINEAR;
19 }
20 virtual std::vector<Express::VARP> onGrad(Express::EXPRP expr,
21 const std::vector<Express::VARP>& backwardOutput) override {
22 auto inputs = expr->inputs();
23 auto type = inputs[1]->getInfo()->type;
24 std::vector<VARP> result(inputs.size(), nullptr);
25 if (type.code != halide_type_float) {
26 return result;
27 }
28 auto outputDiff = backwardOutput[0];
29 // d (select(x, a, b)) = da * (x>0) + db * (x < 0)
30 {
31 auto zero = MNN::Express::_ZerosLike(expr->inputs()[1]);
32 result[1] = MNN::Express::_Select(inputs[0], outputDiff, zero);
33 result[2] = MNN::Express::_Select(inputs[0], zero, outputDiff);
34 }
35 return result;
36 }
37};
38
39static void _create() {

Callers

nothing calls this directly

Calls 4

_ZerosLikeFunction · 0.85
_SelectFunction · 0.85
getInfoMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected