Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GELU and approximate activation functions #8224

Merged
merged 13 commits into from
Apr 12, 2024
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM andrewmackrodt/nodejs
Vectorrent marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /app

COPY . .

RUN yarn install

CMD ["yarn", "run", "test"]
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.9'
Vectorrent marked this conversation as resolved.
Show resolved Hide resolved

services:
yarn:
build:
context: .
dockerfile: Dockerfile
deploy:
resources:
limits:
cpus: '0.25'
71 changes: 64 additions & 7 deletions tfjs-layers/src/activations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,61 @@ export class LogSoftmax extends Activation {
serialization.registerClass(LogSoftmax);

/**
* Swish activation function
* Gelu activation function
*/
export class Swish extends Activation {
export class Gelu extends Activation {
/** @nocollapse */
static readonly className = 'swish';
static readonly className = 'gelu';
/**
* Calculate the activation function.
*
* @param x Tensor.
* @param alpha Scaling factor for the sigmoid function.
* @returns a Tensor of the same shape as x
*/
apply(x: Tensor, alpha = 1): Tensor {
return tidy(() => tfc.mul(tfc.sigmoid(tfc.mul(x, alpha)), x));
apply(x: Tensor): Tensor {
return tidy(() => {
return tfc.tidy(() => {
const sqrtTwo = Math.sqrt(2);
// Compute Φ(x) using the erf function
const cdf = tfc.mul(0.5, tfc.add(1, tfc.erf(tfc.div(x, sqrtTwo))));
// Compute GELU(x) = x * Φ(x)
return tfc.mul(x, cdf);
});
});
}
}
serialization.registerClass(Swish);
serialization.registerClass(Gelu);

/**
* GeluNew activation function
*/
export class GeluNew extends Activation {
/** @nocollapse */
static readonly className = 'gelu_new';
/**
* Calculate the activation function.
*
* @param x Tensor.
* @returns a Tensor of the same shape as x
*/
apply(x: Tensor): Tensor {
return tidy(() => {
return tfc.mul(
0.5,
tfc.add(
1,
tfc.tanh(
tfc.mul(
tfc.sqrt(tfc.div(2, Math.PI)),
tfc.add(x, tfc.mul(0.044715, tfc.pow(x, 3)))
)
)
)
);
});
}
}
serialization.registerClass(GeluNew);

/**
* Mish activation function
Expand All @@ -245,6 +283,25 @@ export class Mish extends Activation {
}
serialization.registerClass(Mish);

/**
* Swish activation function
*/
export class Swish extends Activation {
/** @nocollapse */
static readonly className = 'swish';
/**
* Calculate the activation function.
*
* @param x Tensor.
* @param alpha Scaling factor for the sigmoid function.
* @returns a Tensor of the same shape as x
*/
apply(x: Tensor, alpha = 1): Tensor {
return tidy(() => tfc.mul(tfc.sigmoid(tfc.mul(x, alpha)), x));
}
}
serialization.registerClass(Swish);

export function serializeActivation(activation: Activation): string {
return activation.getClassName();
}
Expand Down
70 changes: 69 additions & 1 deletion tfjs-layers/src/activations_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
import {scalar, tensor1d, tensor2d, tensor3d} from '@tensorflow/tfjs-core';

import {Elu, HardSigmoid, Linear, LogSoftmax, Relu, Relu6, Selu, Sigmoid, Softmax, Softplus, Softsign, Tanh, Swish, Mish} from './activations';
import {Elu, HardSigmoid, Linear, LogSoftmax, Relu, Relu6, Selu, Sigmoid, Softmax, Softplus, Softsign, Tanh, Swish, Mish, Gelu, GeluNew} from './activations';
import {describeMathCPUAndGPU, expectNoLeakedTensors, expectTensorsClose} from './utils/test_utils';

describeMathCPUAndGPU('linear activation', () => {
Expand Down Expand Up @@ -366,3 +366,71 @@ describeMathCPUAndGPU('mish activation', () => {
expectNoLeakedTensors(() => mish(initX), 1);
});
});

describeMathCPUAndGPU('gelu activation', () => {
const gelu = new Gelu().apply;
// Setup: Array with initial values.
// Execute: Gelu on the last dimension.
// Expect: Output array matches size and approximate expected values.
it('1D', () => {
const initX = tensor1d([0, 1, 3, 9]);
const expectedVals = tensor1d([0.5, 0.841192, 0.9987875, 1]);
expectTensorsClose(gelu(initX), expectedVals);
});
it('1D all equal', () => {
const initX = tensor1d([-1, -1, -1, -1]);
const expectedVals = tensor1d([0.158808, 0.158808, 0.158808, 0.158808]);
expectTensorsClose(gelu(initX), expectedVals);
});
it('2D', () => {
const initX = tensor2d([[0, 1, 3, 9], [0, 1, 3, 9]]);
const expectedVals = tensor2d(
[[0.5, 0.841192, 0.9987875, 1], [0.5, 0.841192, 0.9987875, 1]]);
expectTensorsClose(gelu(initX), expectedVals);
});
it('3D', () => {
const initX = tensor3d([[[0, 1, 3, 9], [0, 1, 3, 9]]]);
const expectedVals = tensor3d(
[[[0.5, 0.841192, 0.9987875, 1], [0.5, 0.841192, 0.9987875, 1]]]);
expectTensorsClose(gelu(initX), expectedVals);
});
it('Does not leak', () => {
const initX = tensor1d([0, 1, 3, 9]);
expectNoLeakedTensors(() => gelu(initX), 1);
});
});

describeMathCPUAndGPU('gelu_new activation', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see the error, so I don't know what's failing. I can't imagine why webgl would fail while other backends would succeed, but maybe it's a difference in floating point precision between environments?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 1D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:378:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29642:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 1D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:378:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29642:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 1D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:378:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29642:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 113 of 4308 (1 FAILED) (0 secs / 2.725 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 1D all equal FAILED
	Error: Arrays differ: actual[0] = -0.15865525603294373, expected[0] = 0.15880799293518066.
	Actual:   -0.15865525603294373,-0.15865525603294373,-0.15865525603294373,-0.15865525603294373.
	Expected: 0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:383:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29647:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 1D all equal FAILED
	Error: Arrays differ: actual[0] = -0.15865525603294373, expected[0] = 0.15880799293518066.
	Actual:   -0.15865525603294373,-0.15865525603294373,-0.15865525603294373,-0.15865525603294373.
	Expected: 0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:383:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29647:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 1D all equal FAILED
	Error: Arrays differ: actual[0] = -0.15865525603294373, expected[0] = 0.15880799293518066.
	Actual:   -0.15865525603294373,-0.15865525603294373,-0.15865525603294373,-0.15865525603294373.
	Expected: 0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:383:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29647:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 114 of 4308 (2 FAILED) (0 secs / 2.726 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 2D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:389:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29652:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 2D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:389:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29652:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 2D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:389:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29652:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 115 of 4308 (3 FAILED) (0 secs / 2.727 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 3D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:395:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29657:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 3D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:395:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29657:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation cpu {} 3D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:395:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29657:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 116 of 4308 (4 FAILED) (0 secs / 2.728 secs)
WARN: 'Spec 'gelu activation cpu {} Does not leak' has no expectations.'
WARN: 'Spec 'gelu activation cpu {} Does not leak' has no expectations.'
WARN: 'Spec 'gelu activation cpu {} Does not leak' has no expectations.'
Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 116 of 4308 (4 FAILED) (0 secs / 2.728 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 117 of 4308 (4 FAILED) (0 secs / 2.729 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:378:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29642:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:378:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29642:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:378:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29642:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 118 of 4308 (5 FAILED) (0 secs / 2.882 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D all equal FAILED
	Error: Arrays differ: actual[0] = -0.15865522623062134, expected[0] = 0.15880799293518066.
	Actual:   -0.15865522623062134,-0.15865522623062134,-0.15865522623062134,-0.15865522623062134.
	Expected: 0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:383:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29647:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D all equal FAILED
	Error: Arrays differ: actual[0] = -0.15865522623062134, expected[0] = 0.15880799293518066.
	Actual:   -0.15865522623062134,-0.15865522623062134,-0.15865522623062134,-0.15865522623062134.
	Expected: 0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:383:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29647:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D all equal FAILED
	Error: Arrays differ: actual[0] = -0.15865522623062134, expected[0] = 0.15880799293518066.
	Actual:   -0.15865522623062134,-0.15865522623062134,-0.15865522623062134,-0.15865522623062134.
	Expected: 0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:383:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29647:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 119 of 4308 (6 FAILED) (0 secs / 2.885 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 2D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9,0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:389:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29652:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 2D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9,0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:389:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29652:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 2D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9,0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:389:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29652:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 120 of 4308 (7 FAILED) (0 secs / 2.974 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 3D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9,0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:395:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29657:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 3D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9,0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:395:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29657:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 3D FAILED
	Error: Arrays differ: actual[0] = 0, expected[0] = 0.5.
	Actual:   0,0.8413447737693787,2.995950222015381,9,0,0.8413447737693787,2.995950222015381,9.
	Expected: 0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:395:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29657:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 121 of 4308 (8 FAILED) (0 secs / 3.034 secs)
WARN: 'Spec 'gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} Does not leak' has no expectations.'
WARN: 'Spec 'gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} Does not leak' has no expectations.'
WARN: 'Spec 'gelu activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} Does not leak' has no expectations.'
Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 121 of 4308 (8 FAILED) (0 secs / 3.034 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 122 of 4308 (8 FAILED) (0 secs / 3.035 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 1D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:411:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29669:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 1D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:411:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29669:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 1D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:411:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29669:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 123 of 4308 (9 FAILED) (0 secs / 3.036 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 1D all equal FAILED
	Error: Arrays differ: actual[0] = 0.15880802273750305, expected[0] = -0.1586553007364273.
	Actual:   0.15880802273750305,0.15880802273750305,0.15880802273750305,0.15880802273750305.
	Expected: -0.1586553007364273,-0.1586553007364273,-0.1586553007364273,-0.1586553007364273.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:417:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29674:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 1D all equal FAILED
	Error: Arrays differ: actual[0] = 0.15880802273750305, expected[0] = -0.1586553007364273.
	Actual:   0.15880802273750305,0.15880802273750305,0.15880802273750305,0.15880802273750305.
	Expected: -0.1586553007364273,-0.1586553007364273,-0.1586553007364273,-0.1586553007364273.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:417:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29674:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 1D all equal FAILED
	Error: Arrays differ: actual[0] = 0.15880802273750305, expected[0] = -0.1586553007364273.
	Actual:   0.15880802273750305,0.15880802273750305,0.15880802273750305,0.15880802273750305.
	Expected: -0.1586553007364273,-0.1586553007364273,-0.1586553007364273,-0.1586553007364273.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:417:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29674:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 124 of 4308 (10 FAILED) (0 secs / 3.037 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 2D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.5611233115196228,2.850890874862671,8.998000144958496,0,0.5611233115196228,2.850890874862671,8.998000144958496.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:424:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29682:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 2D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.5611233115196228,2.850890874862671,8.998000144958496,0,0.5611233115196228,2.850890874862671,8.998000144958496.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:424:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29682:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 2D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.5611233115196228,2.850890874862671,8.998000144958496,0,0.5611233115196228,2.850890874862671,8.998000144958496.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:424:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29682:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 125 of 4308 (11 FAILED) (0 secs / 3.038 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 3D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:430:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29687:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 3D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:430:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29687:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation cpu {} 3D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.998787522315979,1,0.5,0.8411920070648193,0.998787522315979,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:430:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29687:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 126 of 4308 (12 FAILED) (0 secs / 3.039 secs)
WARN: 'Spec 'gelu_new activation cpu {} Does not leak' has no expectations.'
WARN: 'Spec 'gelu_new activation cpu {} Does not leak' has no expectations.'
WARN: 'Spec 'gelu_new activation cpu {} Does not leak' has no expectations.'
Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 126 of 4308 (12 FAILED) (0 secs / 3.039 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 127 of 4308 (12 FAILED) (0 secs / 3.04 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:411:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29669:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:411:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29669:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:411:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29669:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 128 of 4308 (13 FAILED) (0 secs / 3.176 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D all equal FAILED
	Error: Arrays differ: actual[0] = 0.15880799293518066, expected[0] = -0.1586553007364273.
	Actual:   0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	Expected: -0.1586553007364273,-0.1586553007364273,-0.1586553007364273,-0.1586553007364273.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:417:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29674:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D all equal FAILED
	Error: Arrays differ: actual[0] = 0.15880799293518066, expected[0] = -0.1586553007364273.
	Actual:   0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	Expected: -0.1586553007364273,-0.1586553007364273,-0.1586553007364273,-0.1586553007364273.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:417:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29674:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 1D all equal FAILED
	Error: Arrays differ: actual[0] = 0.15880799293518066, expected[0] = -0.1586553007364273.
	Actual:   0.15880799293518066,0.15880799293518066,0.15880799293518066,0.15880799293518066.
	Expected: -0.1586553007364273,-0.1586553007364273,-0.1586553007364273,-0.1586553007364273.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:417:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29674:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 129 of 4308 (14 FAILED) (0 secs / 3.181 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 2D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1,0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.5611233115196228,2.850890874862671,8.998000144958496,0,0.5611233115196228,2.850890874862671,8.998000144958496.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:424:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29682:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 2D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1,0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.5611233115196228,2.850890874862671,8.998000144958496,0,0.5611233115196228,2.850890874862671,8.998000144958496.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:424:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29682:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 2D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1,0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.5611233115196228,2.850890874862671,8.998000144958496,0,0.5611233115196228,2.850890874862671,8.998000144958496.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:424:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29682:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7): Executed 130 of 4308 (15 FAILED) (0 secs / 3.288 secs)
Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 3D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1,0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:430:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29687:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 3D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1,0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:430:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29687:11)
	    at 

Chrome 116.0.0.0 (Mac OS 10.15.7) gelu_new activation webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} 3D FAILED
	Error: Arrays differ: actual[0] = 0.5, expected[0] = 0.
	Actual:   0.5,0.8411920070648193,0.9987875819206238,1,0.5,0.8411920070648193,0.9987875819206238,1.
	Expected: 0,0.8413447141647339,2.995950222015381,9,0,0.8413447141647339,2.995950222015381,9.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10062:15)
	    at Object.expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:10024:12)
	    at expectTensorsClose (tfjs-layers/src/utils/test_utils.ts:51:13 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29245:23)
	    at UserContext. (tfjs-layers/src/activations_test.ts:430:5 <- tfjs/tfjs-layers/src/tfjs-layers_test_bundle.js:29687:11)
	    at 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I screwed up so badly, but every single test value was wrong. I just went through and updated every one of them by-hand; tests should be fixed now. Sorry about that!

Copy link
Collaborator

@pyu10055 pyu10055 Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries, thanks for fixing the test.
can you run following in the tfjs directory:
tslint -p tsconfig_tslint.json
and fix the lint errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I'll remember to check the linting in future commits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I'm back in office now, so I've taken a look.

I think this implementation of gelu_new might be computing just Φ(x) instead of x Φ(x)

According to help(keras.activations.gelu) in python,

    Returns:
        The gaussian error linear activation:
        `0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))`
        if `approximate` is `True` or
        `x * P(X <= x) = 0.5 * x * (1 + erf(x / sqrt(2)))`,
        where `P(X) ~ N(0, 1)`,
        if `approximate` is `False`.

0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3))) is the approximate form that gelu_new is computing, but I think the implementation is missing the * x. That's why all the values were wrong.

I tried adding a * x to the implementation and the values look closer:

gelu(initX).print()
    [0, 0.8413447, 2.9959502, 9]

geluNew(initX).print()
    [0, 0.841192, 2.9963627, 9]

const geluNew = new GeluNew().apply;
// Setup: Array with initial values.
// Execute: GeluNew on the last dimension.
// Expect: Output array matches size and approximate expected values.
it('1D', () => {
const initX = tensor1d([0, 1, 3, 9]);
const expectedVals = tensor1d([0, 0.8413447, 2.9959502, 9]);
expectTensorsClose(geluNew(initX), expectedVals);
});
it('1D all equal', () => {
const initX = tensor1d([-1, -1, -1, -1]);
const expectedVals = tensor1d(
[-0.1586553, -0.1586553, -0.1586553, -0.1586553]);
expectTensorsClose(geluNew(initX), expectedVals);
});
it('2D', () => {
const initX = tensor2d([[0, 1, 3, 9], [0, 1, 3, 9]]);
const expectedVals = tensor2d(
[[0, 0.5611233, 2.8508909, 8.9980001],
[0, 0.5611233, 2.8508909, 8.9980001]]);
expectTensorsClose(geluNew(initX), expectedVals);
});
it('3D', () => {
const initX = tensor3d([[[0, 1, 3, 9], [0, 1, 3, 9]]]);
const expectedVals = tensor3d(
[[[0, 0.8413447, 2.9959502, 9], [0, 0.8413447, 2.9959502, 9]]]);
expectTensorsClose(geluNew(initX), expectedVals);
});
it('Does not leak', () => {
const initX = tensor1d([0, 1, 3, 9]);
expectNoLeakedTensors(() => geluNew(initX), 1);
});
});
4 changes: 2 additions & 2 deletions tfjs-layers/src/keras_format/activation_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {stringLiteralArray} from './utils';
*/
export const activationOptions = stringLiteralArray([
'elu', 'hard_sigmoid', 'linear', 'relu', 'relu6', 'selu', 'sigmoid',
'softmax', 'softplus', 'softsign', 'tanh', 'swish', 'mish'
'softmax', 'softplus', 'softsign', 'tanh', 'swish', 'mish', 'gelu', 'gelu_new'
]);

/**
Expand All @@ -28,4 +28,4 @@ export type ActivationSerialization = typeof activationOptions[number];
// e.g. to src/common.ts. Maybe even duplicate *all* of these to be pedantic?
/** @docinline */
export type ActivationIdentifier = 'elu'|'hardSigmoid'|'linear'|'relu'|'relu6'|
'selu'|'sigmoid'|'softmax'|'softplus'|'softsign'|'tanh'|'swish'|'mish';
'selu'|'sigmoid'|'softmax'|'softplus'|'softsign'|'tanh'|'swish'|'mish'|'gelu'|'gelu_new';
3 changes: 1 addition & 2 deletions tfjs-layers/src/layers/nlp/models/gpt2/gpt2_backbone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ export class GPT2Backbone extends Backbone {
numHeads: args.numHeads,
dropout: args.dropout,
layerNormEpsilon: 1e-05,
// TODO(pforderique): Implement gelu.
activation: getActivation('relu'),
activation: getActivation('gelu'),
kernelInitializer: gpt2KernelInitializer(0.02),
normalizeFirst: true,
name: `transformer_layer_${i}`,
Expand Down