3 #include "caffe2/operators/glu_op.h" 8 float sigmoid(
const float x) {
10 return 1. / (1. + exp(-x));
12 const float exp_x = exp(x);
13 return exp_x / (1 + exp_x);
19 void GluOp<float, CPUContext>::ComputeGlu(
25 const int xStride = 2 * split_dim * N;
26 const int yStride = split_dim * N;
27 for (
int i = 0; i < M; ++i) {
28 const int idx = i * xStride;
29 const int idy = i * yStride;
30 for (
int j = 0; j < split_dim; ++j) {
32 const int jdx1 = idx + jN;
33 const int jdx2 = idx + (j + split_dim) * N;
34 const int jdy = idy + jN;
35 for (
int k = 0; k < N; ++k) {
36 const float x1 = Xdata[jdx1 + k];
37 const float x2 = Xdata[jdx2 + k];
38 Ydata[jdy + k] = x1 * sigmoid(x2);
48 Applies gated linear unit to the input Tensor X. The output Y is half the size 49 of the input X, so if the shape of X is [d1, d2, ..., N] shape of Y will be 50 [d1, d2, ..., dn/2] and Y(:dn-1, i) = GLU(X(:dn-1, i), X(:dn-1, i+N/2)) = 51 X(dn-1, i) * sigmoid(X(dn-1, i+N/2)) 53 .Input(0, "X",
"1D input tensor")
54 .Output(0,
"Y",
"1D output tensor");
56 REGISTER_CPU_OPERATOR(Glu, GluOp<float, CPUContext>);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...