Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'aten_upsample_bilinear2d_vec' for unet #1249

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 13 additions & 1 deletion onnxscript/function_libs/torch_lib/ops/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2306,11 +2306,23 @@ def aten_upsample_bilinear2d(
result = _aten_upsample_bilinear2d_output_size(self, output_size)
else:
assert scales_h is not None
assert scales_h == scales_w
assert scales_h == scales_w, f"scale_h({scales_h}) != scale_w({scales_w})"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why there is this restriction.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiaowuhu could you help?

result = _aten_upsample_bilinear2d_scales(self, scales_h, scales_w)
return result


@torch_op("aten::upsample_bilinear2d.vec", trace_only=True)
def aten_upsample_bilinear2d_vec(
self: TReal,
output_size: Optional[INT64] = None,
align_corners: bool = True,
scale_factors: Optional[Sequence[float]] = None,
) -> TReal:
return aten_upsample_bilinear2d(
BowenBao marked this conversation as resolved.
Show resolved Hide resolved
self, output_size, scale_factors[0], scale_factors[1], align_corners
)


@torch_op("aten::upsample_bilinear2d", private=True)
def _aten_upsample_bilinear2d_output_size(
self: TReal,
Expand Down
18 changes: 18 additions & 0 deletions onnxscript/tests/function_libs/torch_lib/ops_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ def _upsample_bilinear2d_input_wrangler(
return args, kwargs


def _upsample_bilinear2d_vec_input_wrangler(
args: list[Any], kwargs: dict[str, Any]
) -> tuple[list[Any], dict[str, Any]]:
if "size" in kwargs:
args.append(np.array(kwargs["size"], dtype=np.int64))
del kwargs["size"] # promote tensor type kwargs to args
if "scale_factor" in kwargs:
kwargs["scale_factors"] = [kwargs["scale_factor"]] * 2
del kwargs["scale_factor"] # adapt the function signature
return args, kwargs


def _upsample_input_wrangler(
args: list[Any], kwargs: dict[str, Any]
) -> tuple[list[Any], dict[str, Any]]:
Expand Down Expand Up @@ -2122,6 +2134,12 @@ def _where_input_wrangler(
input_wrangler=_upsample_bilinear2d_input_wrangler,
trace_only=True,
),
TorchLibOpInfo(
"nn.functional.upsample_bilinear2d",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably test against the .vec overload?

nn_ops.aten_upsample_bilinear2d_vec,
input_wrangler=_upsample_bilinear2d_vec_input_wrangler,
trace_only=True,
),
TorchLibOpInfo(
"ops.aten.upsample_bicubic2d",
nn_ops.aten_upsample_bicubic2d,
Expand Down
Loading