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

Method Compile

tensorflow/compiler/tf2xla/kernels/elu_op.cc:91–104  ·  view source on GitHub ↗

Return the lhs (incoming gradient) if the rhs (input feature) > 0, otherwise return lhs * (1 + rhs).

Source from the content-addressed store, hash-verified

89 // Return the lhs (incoming gradient) if the rhs (input feature) > 0,
90 // otherwise return lhs * (1 + rhs).
91 void Compile(XlaOpKernelContext* ctx) override {
92 xla::XlaBuilder* b = ctx->builder();
93 const auto zero = XlaHelpers::Zero(b, input_type(0));
94 const auto scale = XlaHelpers::FloatLiteral(b, input_type(0),
95 1.0507009873554804934193349852946);
96 const auto scale_alpha = XlaHelpers::FloatLiteral(b, input_type(0),
97 1.7580993408473768599402175208123);
98 const auto grad = ctx->Input(0);
99 const auto activation = ctx->Input(1);
100 const auto lin_grad = xla::Mul(grad, scale);
101 const auto exp_grad = xla::Mul(grad, xla::Add(activation, scale_alpha));
102 const auto pred = xla::Gt(activation, zero);
103 ctx->SetOutput(0, xla::Select(pred, lin_grad, exp_grad));
104 }
105};
106
107REGISTER_XLA_OP(Name("Selu"), SeluOp);

Callers

nothing calls this directly

Calls 9

FloatLiteralFunction · 0.85
ZeroFunction · 0.50
MulFunction · 0.50
AddClass · 0.50
GtClass · 0.50
SelectFunction · 0.50
builderMethod · 0.45
InputMethod · 0.45
SetOutputMethod · 0.45

Tested by

no test coverage detected