Skip to content
Merged
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
18 changes: 18 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 @@ -78,6 +78,8 @@
ClampModule,
HARDTANH_CONFIGS,
HardtanhModule,
POW_SCALAR_CONFIGS,
PowScalarModule,
UNARY_G1,
UnaryModule,
)
Expand Down Expand Up @@ -1042,3 +1044,19 @@
for n, (lo, hi) in HARDTANH_CONFIGS.items()
],
)


@register_op_test("pow_scalar")
def _pow_scalar_suite() -> WebGPUTestSuite:
# Positive base: WGSL pow(neg base)=NaN for any exponent; exponent baked.
return WebGPUTestSuite(
module_factory=lambda exponent: PowScalarModule(exponent),
cases=[
Case(
name=n,
construct={"exponent": e},
inputs=(InputSpec(shape=(M1, M2), gen=_unary_lin(0.1, 4.0)),),
)
for n, e in POW_SCALAR_CONFIGS.items()
],
)
18 changes: 18 additions & 0 deletions backends/webgpu/test/ops/test_unary_activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
}


class PowScalarModule(torch.nn.Module):
"""aten.pow.Tensor_Scalar with a baked exponent (exponent → the min slot)."""

def __init__(self, exponent) -> None:
super().__init__()
self.exponent = exponent

def forward(self, x: torch.Tensor) -> torch.Tensor:
return torch.pow(x, self.exponent)


# name -> exponent construct kwarg; the suite uses a positive base to avoid NaN.
POW_SCALAR_CONFIGS = {
"square": 2.0,
"sqrt": 0.5,
}


def _lin(lo: float, hi: float):
"""Deterministic linspace input of the requested shape over [lo, hi]."""

Expand Down
Loading