Skip to content
Open
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
26 changes: 26 additions & 0 deletions backends/webgpu/test/op_tests/cases.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
Expand Down Expand Up @@ -653,6 +653,32 @@
atol=1e-4,
rtol=1e-3,
)
from executorch.backends.webgpu.test.ops.test_leaky_relu import (
LeakyReluModule,
)


@register_op_test("leaky_relu")
def _leaky_relu_suite() -> WebGPUTestSuite:
# Real-ESRGAN SRVGGNetCompact body activation. The det input spans negatives,
# exercising the negative_slope branch; a 4D and a 2D case.
return WebGPUTestSuite(
module_factory=lambda negative_slope: LeakyReluModule(negative_slope),
cases=[
Case(
name="default_slope",
construct={"negative_slope": 0.01},
inputs=(InputSpec(shape=(1, 16, 8, 8), gen=_upsample_det_input),),
),
Case(
name="slope_0_2",
construct={"negative_slope": 0.2},
inputs=(InputSpec(shape=(3, 32), gen=_upsample_det_input),),
),
],
atol=1e-4,
rtol=1e-3,
)
from executorch.backends.webgpu.test.ops.test_max_pool2d import (
_det_input as _maxpool_det_input,
MaxPool2dModule,
Expand Down
21 changes: 21 additions & 0 deletions backends/webgpu/test/ops/test_leaky_relu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""`aten.leaky_relu.default` module for the WebGPU op-test framework.

LeakyReLU is the activation in Real-ESRGAN's SRVGGNetCompact body.
"""

import torch


class LeakyReluModule(torch.nn.Module):
def __init__(self, negative_slope: float) -> None:
super().__init__()
self.negative_slope = negative_slope

def forward(self, x: torch.Tensor) -> torch.Tensor:
return torch.nn.functional.leaky_relu(x, self.negative_slope)
Loading