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

Method onGrad

tools/train/source/grad/ScaleGrad.cpp:17–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15class ScaleGrad : public OpGrad {
16public:
17 virtual std::vector<Express::VARP> onGrad(Express::EXPRP expr,
18 const std::vector<Express::VARP>& backwardOutput) override {
19 auto inputs = expr->inputs();
20 std::vector<VARP> res(inputs.size(), nullptr);
21 auto outputDiff = backwardOutput[0];
22
23 std::unique_ptr<OpT> forwardOp(expr->get()->UnPack());
24 auto param = forwardOp->main.AsScale();
25 auto channels = param->channels;
26 auto scale = param->scaleData;
27 auto zeros = std::vector<float>(scale.size(), 0.0f);
28
29 res[0] = _Scale(outputDiff, channels, std::move(scale), std::move(zeros));
30
31 return res;
32 }
33};
34
35static void _create() {

Callers

nothing calls this directly

Calls 5

_ScaleFunction · 0.85
AsScaleMethod · 0.80
sizeMethod · 0.45
UnPackMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected