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
31 changes: 31 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 @@ -44,6 +44,11 @@
CONFIGS as _SELECT_CONFIGS,
SelectModule,
)
from executorch.backends.webgpu.test.ops.test_sigmoid import (
_det_input as _sigmoid_det_input,
N as _SIGMOID_N,
SigmoidModule,
)
from executorch.backends.webgpu.test.ops.test_view_copy import (
CONFIGS as _VIEW_CONFIGS,
ViewModule,
Expand Down Expand Up @@ -153,3 +158,29 @@
@register_op_test("select")
def _select_suite() -> WebGPUTestSuite:
return _fn_config_suite(SelectModule, _SELECT_CONFIGS)


def _sigmoid_full_range(_shape) -> torch.Tensor:
# Reuses the monolith's saturation-tail input (linspace(-12, 12)).
return _sigmoid_det_input()


@register_op_test("sigmoid")
def _sigmoid_suite() -> WebGPUTestSuite:
# sigmoid has no CONFIGS table; cover unary shapes directly (tol 1e-4).
return WebGPUTestSuite(
module_factory=lambda: SigmoidModule(),
cases=[
Case(name="vec", inputs=((M1,),)),
Case(name="mat", inputs=((M1, M2),)),
Case(name="rank3", inputs=((S1, M1, M2),)),
Case(name="rank4", inputs=((S1, S2, S2, M2),)),
# Saturation tails sigmoid(+-12) (~6e-6 / 0.999994) that randn shapes miss.
Case(
name="saturation",
inputs=(InputSpec(shape=(_SIGMOID_N,), gen=_sigmoid_full_range),),
),
],
atol=1e-4,
rtol=1e-4,
)
51 changes: 51 additions & 0 deletions backends/webgpu/test/ops/test_sigmoid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.sigmoid.default` module + input for the WebGPU op-test framework.

`SigmoidModule`, `N`, and `_det_input` are imported by `cases.py` to drive the
declarative op-test suite. `SigmoidTest` is the export-delegation
smoke test. Sigmoid is on the Llama critical path (`F.silu` -> `sigmoid` + `mul`); the
deterministic input spans the saturation tails.
"""

import unittest

import torch

from executorch.backends.vulkan.partitioner.vulkan_partitioner import VulkanPartitioner
from executorch.exir import to_edge_transform_and_lower

# Input length; the deterministic input spans the saturation tails.
N = 64


class SigmoidModule(torch.nn.Module):
def forward(self, x: torch.Tensor) -> torch.Tensor:
return torch.sigmoid(x)


def _det_input() -> torch.Tensor:
"""Deterministic fp32 input spanning negatives, zero, and large magnitudes."""
return torch.linspace(-12.0, 12.0, N, dtype=torch.float32)


def _export(m: torch.nn.Module, x: torch.Tensor):
ep = torch.export.export(m, (x,))
return to_edge_transform_and_lower(
ep, partitioner=[VulkanPartitioner()]
).to_executorch()


class SigmoidTest(unittest.TestCase):
def test_export_delegates(self) -> None:
et = _export(SigmoidModule().eval(), _det_input())
found = any(
d.id == "VulkanBackend"
for plan in et.executorch_program.execution_plan
for d in plan.delegates
)
self.assertTrue(found, "Expected a VulkanBackend delegate (sigmoid)")
1 change: 1 addition & 0 deletions backends/webgpu/test/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
exir_ops.edge.aten.mul.Tensor,
exir_ops.edge.aten.view_copy.default,
exir_ops.edge.aten.select_copy.int,
exir_ops.edge.aten.sigmoid.default,
]


Expand Down
Loading