From 33248821a909d636c078da39e61dd046c7e95f51 Mon Sep 17 00:00:00 2001 From: Julian Ng-Thow-Hing Date: Thu, 16 Jul 2026 14:49:04 -0700 Subject: [PATCH] Update [ghstack-poisoned] --- backends/webgpu/test/op_tests/cases.py | 26 +++++++++++++++++++++ backends/webgpu/test/ops/test_leaky_relu.py | 21 +++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 backends/webgpu/test/ops/test_leaky_relu.py diff --git a/backends/webgpu/test/op_tests/cases.py b/backends/webgpu/test/op_tests/cases.py index 1563fa7313c..ef0222afd48 100644 --- a/backends/webgpu/test/op_tests/cases.py +++ b/backends/webgpu/test/op_tests/cases.py @@ -653,6 +653,32 @@ def _upsample_nearest2d_suite() -> WebGPUTestSuite: 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, diff --git a/backends/webgpu/test/ops/test_leaky_relu.py b/backends/webgpu/test/ops/test_leaky_relu.py new file mode 100644 index 00000000000..57020749e43 --- /dev/null +++ b/backends/webgpu/test/ops/test_leaky_relu.py @@ -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)