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

Method regularizeParameters

tools/train/source/optimizer/SGD.cpp:54–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54Express::VARP SGD::regularizeParameters(Express::VARP param, Express::VARP grad) {
55 VARP addWeightDecayGrad;
56 if (mRegularizationMethod == L1) {
57 auto temp = _Sign(param);
58 addWeightDecayGrad = _Const(mWeightDecay, {}, NCHW) * temp + grad;
59 } else if (mRegularizationMethod == L2) {
60 addWeightDecayGrad = _Const(mWeightDecay, {}, NCHW) * param + grad;
61 } else if (mRegularizationMethod == L1L2) {
62 auto temp = _Sign(param);
63 auto L1 = _Const(mWeightDecay, {}, NCHW) * temp;
64 auto L2 = _Const(mWeightDecay, {}, NCHW) * param;
65 addWeightDecayGrad = L1 + L2 + grad;
66 }
67
68 return addWeightDecayGrad;
69}
70
71Express::VARP SGD::onComputeUpdateValue(Express::VARP param, Express::VARP grad) {
72 auto lr = _Const(mLearningRate, {}, NCHW);

Callers

nothing calls this directly

Calls 2

_SignFunction · 0.85
_ConstFunction · 0.85

Tested by

no test coverage detected