diff --git a/backends/webgpu/test/op_tests/cases.py b/backends/webgpu/test/op_tests/cases.py index 62ecdaec3d2..205ece53601 100644 --- a/backends/webgpu/test/op_tests/cases.py +++ b/backends/webgpu/test/op_tests/cases.py @@ -669,3 +669,29 @@ def _max_pool2d_suite() -> WebGPUTestSuite: atol=1e-4, rtol=1e-3, ) +from executorch.backends.webgpu.test.ops.test_relu import ( + _det_input as _relu_det_input, + ReluModule, +) + + +@register_op_test("relu") +def _relu_suite() -> WebGPUTestSuite: + # SAM2/SAM3 mask-decoder MLP path; tiny + a decoder_mlp-shaped case. + return WebGPUTestSuite( + module_factory=lambda: ReluModule(), + cases=[ + Case( + name="tiny", + construct={}, + inputs=(InputSpec(shape=(1, 4, 8), gen=_relu_det_input),), + ), + Case( + name="decoder_mlp", + construct={}, + inputs=(InputSpec(shape=(1, 576, 768), gen=_relu_det_input),), + ), + ], + atol=1e-4, + rtol=1e-3, + ) diff --git a/backends/webgpu/test/ops/test_relu.py b/backends/webgpu/test/ops/test_relu.py new file mode 100644 index 00000000000..f8303fcde58 --- /dev/null +++ b/backends/webgpu/test/ops/test_relu.py @@ -0,0 +1,27 @@ +# 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.relu.default` module for the WebGPU op-test framework. + +ReLU is on the SAM2/SAM3 mask-decoder MLP path. +""" + +import torch + + +class ReluModule(torch.nn.Module): + def forward(self, x: torch.Tensor) -> torch.Tensor: + return torch.relu(x) + + +def _det_input(shape) -> torch.Tensor: + # ((i % 23) - 11) / 16: exact in fp32, spans negatives through positives + # so the clamp is exercised, not just an identity pass-through. + n = 1 + for s in shape: + n *= s + idx = torch.arange(n, dtype=torch.int64) + return (((idx % 23) - 11).to(torch.float32) / 16.0).reshape(shape)