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

LeakyRelu #13488 #13492

Merged
merged 20 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ivy/functional/frontends/tensorflow/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ def softmax(logits, axis=None, name=None):
return ivy.softmax(logits, axis=axis)


@with_unsupported_dtypes({"2.9.0 and below": "float16"}, "tensorflow")
@to_ivy_arrays_and_back
def leaky_relu(features, alpha, name=None):
sherry30 marked this conversation as resolved.
Show resolved Hide resolved
return ivy.leaky_relu(features, alpha=alpha)


@to_ivy_arrays_and_back
def crelu(features, axis=-1, name=None):
c = ivy.concat([features, -features], axis=axis)
Expand Down
30 changes: 30 additions & 0 deletions ivy/functional/frontends/tensorflow/raw_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ def Concat(*, concat_dim, values, name="Concat"):

Cos = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.cos))


@to_ivy_arrays_and_back
def Cross(*, a, b, name='Cross'):
a, b = check_tensorflow_casting(a, b)
return ivy.cross(a, b)


@to_ivy_arrays_and_back
def Cosh(*, x, name="Cosh"):
return ivy.cosh(x)
Expand Down Expand Up @@ -750,6 +752,34 @@ def BatchMatMulV3(x, y, Tout=ivy.Dtype, adj_x=False, adj_y=False, name="BatchMat

Slice = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.slice))

LeakyRelu = to_ivy_arrays_and_back(
map_raw_ops_alias(
tf_frontend.nn.leaky_relu,
))

LeakyRelu.supported_dtypes = {
"numpy": (
"float32",
"float64",
),
"tensorflow": (
"bfloat16",
"float16",
"float32",
"float64",
),
"torch": (
"float32",
"float64",
),
"jax": (
"bfloat16",
"float16",
"float32",
"float64",
),
}


@to_ivy_arrays_and_back
def Prod(*, input, axis, keep_dims=False, name="Prod"):
Expand Down
30 changes: 30 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_tensorflow/test_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@
)


@handle_frontend_test(
fn_tree="tensorflow.nn.leaky_relu",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_num_dims=1,
),
test_with_out=st.just(False),
alpha=helpers.floats(min_value=0, max_value=1)
)
def test_tensorflow_leaky_relu(
*,
dtype_and_x,
alpha,
frontend,
test_flags,
fn_tree,
on_device,
):
dtype, x = dtype_and_x
return helpers.test_frontend_function(
input_dtypes=dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
features=x[0],
alpha=alpha
)


@st.composite
def _x_and_filters(
draw,
Expand Down
43 changes: 37 additions & 6 deletions ivy_tests/test_ivy/test_frontends/test_tensorflow/test_raw_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ def test_tensorflow_Cos( # NOQA

# Cross
@handle_frontend_test(
fn_tree='tensorflow.raw_ops.Cross',
dtype_and_x=helpers.dtype_and_values(
fn_tree='tensorflow.raw_ops.Cross',
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_num_dims=1,
max_num_dims=5,
Expand All @@ -324,11 +324,11 @@ def test_tensorflow_Cos( # NOQA
safety_factor_scale="log",
num_arrays=2,
shared_dtype=True,
),
test_with_out=st.just(False),
),
test_with_out=st.just(False),
)
def test_tensorflow_Cross( # NOQA
*,
*,
dtype_and_x,
frontend,
test_flags,
Expand All @@ -346,6 +346,7 @@ def test_tensorflow_Cross( # NOQA
b=xs[1],
)


# Rsqrt
@handle_frontend_test(
fn_tree="tensorflow.raw_ops.Rsqrt",
Expand Down Expand Up @@ -381,7 +382,7 @@ def test_tensorflow_Rsqrt(
),
test_with_out=st.just(False),
)
def test_tensorflow_Cosh( # NOQA
def test_tensorflow_Cosh(
*,
dtype_and_x,
frontend,
Expand Down Expand Up @@ -3691,3 +3692,33 @@ def test_tensorflow_Prod( # NOQA
axis=axis,
keep_dims=keep_dims,
)


@handle_frontend_test(
fn_tree="tensorflow.raw_ops.LeakyRelu",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_num_dims=1,
),
test_with_out=st.just(False),
alpha=helpers.floats(min_value=0, max_value=1)
)
def test_tensorflow_LeakyReLU(
*,
dtype_and_x,
alpha,
frontend,
test_flags,
fn_tree,
on_device,
):
dtype, x = dtype_and_x
return helpers.test_frontend_function(
input_dtypes=dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
features=x[0],
alpha=alpha
)