def test_gelu_operator_with_array(): runtime = get_runtime() data_value = np.array([[-5, 1], [-2, 3]], dtype=np.float32) model = ng.gelu(data_value, "erf") computation = runtime.computation(model) result = computation() expected = np.array([[-1.6391277e-06, 8.4134471e-01], [-4.5500278e-02, 2.9959502]], dtype=np.float32) assert np.allclose(result, expected, 1e-6, 1e-6)
def test_gelu_tanh_operator_with_array(): runtime = get_runtime() data_value = np.array([[-5, 1], [-2, 3]], dtype=np.float32) model = ng.gelu(data_value, "tanh") computation = runtime.computation(model) result = computation() expected = np.array([[0.0, 0.841192], [-0.04540223, 2.9963627]], dtype=np.float32) assert np.allclose(result, expected, 1e-6, 1e-6)
def test_gelu_operator_with_parameters(): runtime = get_runtime() data_value = np.array([[-5, 1], [-2, 3]], dtype=np.float32) data_shape = [2, 2] parameter_data = ng.parameter(data_shape, name="Data", dtype=np.float32) model = ng.gelu(parameter_data) computation = runtime.computation(model, parameter_data) result = computation(data_value) expected = np.array([[-1.4901161e-06, 8.4134471e-01], [-4.5500278e-02, 2.9959502]], dtype=np.float32) assert np.allclose(result, expected, 0.007, 0.007)
def test_gelu_tanh_operator_with_parameters(): runtime = get_runtime() data_value = np.array([[-5, 1], [-2, 3]], dtype=np.float32) data_shape = [2, 2] parameter_data = ng.parameter(data_shape, name="Data", dtype=np.float32) model = ng.gelu(parameter_data, "tanh") computation = runtime.computation(model, parameter_data) result = computation(data_value) expected = np.array([[0.0, 0.841192], [-0.04540223, 2.9963627]], dtype=np.float32) assert np.allclose(result, expected, 1e-6, 1e-6)