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
44 changes: 44 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 @@ -679,6 +679,50 @@
atol=1e-4,
rtol=1e-3,
)
from executorch.backends.webgpu.test.ops.test_upsample_bilinear2d import (
UpsampleBilinear2dModule,
)


@register_op_test("upsample_bilinear2d")
def _upsample_bilinear2d_suite() -> WebGPUTestSuite:
# DPT/Depth-Anything bilinear resize head. Both align_corners branches +
# a non-integer ratio (5->8) that discriminates the two source-index
# formulas (see upsample_bilinear2d.wgsl).
return WebGPUTestSuite(
module_factory=lambda scale_factor, align_corners: UpsampleBilinear2dModule(
scale_factor, align_corners
),
cases=[
Case(
name="af_false_2x",
construct={"scale_factor": 2.0, "align_corners": False},
inputs=(InputSpec(shape=(1, 8, 36, 36), gen=_upsample_det_input),),
),
Case(
name="af_false_non_2x",
construct={"scale_factor": 1.6, "align_corners": False},
inputs=(InputSpec(shape=(1, 2, 5, 5), gen=_upsample_det_input),),
),
Case(
name="af_false_tiny",
construct={"scale_factor": 2.0, "align_corners": False},
inputs=(InputSpec(shape=(1, 4, 5, 7), gen=_upsample_det_input),),
),
Case(
name="af_true_2x",
construct={"scale_factor": 2.0, "align_corners": True},
inputs=(InputSpec(shape=(1, 4, 7, 7), gen=_upsample_det_input),),
),
Case(
name="af_true_non_2x",
construct={"scale_factor": 1.6, "align_corners": True},
inputs=(InputSpec(shape=(1, 2, 5, 5), 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,
Expand Down
29 changes: 29 additions & 0 deletions backends/webgpu/test/ops/test_upsample_bilinear2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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.upsample_bilinear2d.vec` module for the WebGPU op-test framework.

Bilinear upsample is on the Depth-Anything / DPT reassemble+fusion head
(`F.interpolate(..., mode="bilinear", align_corners=...)`), which resizes the
ViT patch grid back to image resolution.
"""

import torch


class UpsampleBilinear2dModule(torch.nn.Module):
def __init__(self, scale_factor: float, align_corners: bool) -> None:
super().__init__()
self.scale_factor = scale_factor
self.align_corners = align_corners

def forward(self, x: torch.Tensor) -> torch.Tensor:
return torch.nn.functional.interpolate(
x,
scale_factor=self.scale_factor,
mode="bilinear",
align_corners=self.align_corners,
)
Loading