pytorch/caffe2/operators/lstm_unit_op.cc
Nikita Shulga a9b0a921d5 Disable avoid-non-const-global-variables lint check (#62008)
Summary:
As GoogleTest `TEST` macro is non-compliant with it as well as `DEFINE_DISPATCH`

All changes but the ones to `.clang-tidy` are generated using following script:
```
for i in `find . -type f -iname "*.c*" -or -iname "*.h"|xargs grep cppcoreguidelines-avoid-non-const-global-variables|cut -f1 -d:|sort|uniq`;  do sed -i "/\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)/d" $i; done
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/62008

Reviewed By: driazati, r-barnes

Differential Revision: D29838584

Pulled By: malfet

fbshipit-source-id: 1b2f8602c945bd4ce50a9bfdd204755556e31d13
2021-07-22 18:04:40 -07:00

53 lines
1.8 KiB
C++

#include "lstm_unit_op.h"
namespace caffe2 {
REGISTER_CPU_OPERATOR(LSTMUnit, LSTMUnitOp<CPUContext>);
OPERATOR_SCHEMA(LSTMUnit)
.NumInputs(4, 5)
.NumOutputs(2)
.SetDoc(R"DOC(
LSTMUnit computes the activations of a standard LSTM (without peephole
connections), in a sequence-length aware fashion.
Concretely, given the (fused) inputs X (TxNxD), the previous cell
state (NxD), and the sequence lengths (N), computes the LSTM
activations, avoiding computation if the input is invalid (as in, the
value at X{t][n] >= seqLengths[n].
)DOC")
.Arg("forget_bias", "Bias term to add in while calculating forget gate")
.Arg(
"sequence_lengths",
"When false, the sequence lengths input is left out, "
"and all following inputs are shifted left by one.");
REGISTER_CPU_OPERATOR(LSTMUnitGradient, LSTMUnitGradientOp<CPUContext>);
OPERATOR_SCHEMA(LSTMUnitGradient)
.NumInputs(8, 9)
.NumOutputs(3)
.Arg(
"sequence_lengths",
"When false, the sequence lengths input is left out, "
"and all following inputs are shifted left by one.");
class GetLSTMUnitGradient : public GradientMakerBase {
using GradientMakerBase::GradientMakerBase;
vector<OperatorDef> GetGradientDefs() override {
if (GetFlagArgument(def_, "sequence_lengths", true)) {
return SingleGradientDef(
"LSTMUnitGradient",
"",
vector<string>{
I(0), I(1), I(2), I(3), I(4), O(0), O(1), GO(0), GO(1)},
vector<string>{GI(0), GI(1), GI(2)});
} else {
return SingleGradientDef(
"LSTMUnitGradient",
"",
vector<string>{I(0), I(1), I(2), I(3), O(0), O(1), GO(0), GO(1)},
vector<string>{GI(0), GI(1), GI(2)});
}
}
};
REGISTER_GRADIENT(LSTMUnit, GetLSTMUnitGradient);
}