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 @@ -669,3 +669,29 @@
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,
)
27 changes: 27 additions & 0 deletions backends/webgpu/test/ops/test_relu.py
Original file line number Diff line number Diff line change
@@ -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)
Loading