Skip to content

Implement split_function_and_wrangler | test(torchlib) #688

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

Merged
merged 55 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c6505cf
Move version_utils to _internal | chore
justinchuby Apr 12, 2023
268ad8f
Merge `attrs` and `attr_protos` in `IRFunction` | chore(irbuilder)
justinchuby Apr 12, 2023
1f900c1
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 12, 2023
01f9378
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 12, 2023
1b7391e
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 12, 2023
304fa0d
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 12, 2023
ac60dce
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 12, 2023
3eb45c6
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 12, 2023
f7b9b79
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 13, 2023
59523f5
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 13, 2023
758ce59
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 13, 2023
fdd2f22
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 13, 2023
d4b0db6
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 13, 2023
cc977b1
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 13, 2023
8ffd7e7
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 13, 2023
831a416
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 13, 2023
1fd4d2e
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 13, 2023
62105f3
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 13, 2023
9c6bfae
Update base for Update on "Merge `attrs` and `attr_protos` in `IRFunc…
justinchuby Apr 13, 2023
c63ccd5
Update on "Merge `attrs` and `attr_protos` in `IRFunction` | chore(ir…
justinchuby Apr 13, 2023
4e38a29
Analyze type annotation for input types | feat(op_schema)
justinchuby Apr 14, 2023
b34551c
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 14, 2023
f3911bf
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 14, 2023
b48d6ef
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 14, 2023
9018509
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 17, 2023
f6a934d
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 17, 2023
7014658
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 18, 2023
40c29c6
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 18, 2023
a80742f
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 18, 2023
509aea0
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 18, 2023
f2046cc
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 18, 2023
b8c3450
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 18, 2023
d6ec312
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 20, 2023
b50b72c
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 20, 2023
84f7014
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 20, 2023
e9f383b
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 20, 2023
03f64d4
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 20, 2023
7804c7f
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 20, 2023
6538959
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 21, 2023
f31f30c
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 21, 2023
8648dd3
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 22, 2023
2b90e31
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 22, 2023
5f04381
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 22, 2023
0f605cd
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 22, 2023
d272e20
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 22, 2023
cbcf5b1
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 22, 2023
ca76465
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 25, 2023
724c0ef
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 25, 2023
5d8f60e
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 27, 2023
9d7d12f
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 27, 2023
e61bffe
Update base for Update on "Analyze type annotation for input types | …
justinchuby Apr 27, 2023
52c198e
Update on "Analyze type annotation for input types | feat(op_schema)"
justinchuby Apr 27, 2023
0f76ccf
Implement split_function_and_wrangler | test(torchlib)
justinchuby Apr 27, 2023
a46b481
Update base for Update on "Implement split_function_and_wrangler | te…
justinchuby Apr 27, 2023
b38c7bb
Update on "Implement split_function_and_wrangler | test(torchlib)"
justinchuby Apr 27, 2023
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: 21 additions & 23 deletions onnxscript/tests/function_libs/torch_lib/ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from __future__ import annotations

import unittest
from typing import Callable, Optional, Sequence, Tuple
from typing import Any, Callable, Optional, Sequence, Tuple

import numpy as np
import onnx
Expand Down Expand Up @@ -56,14 +56,23 @@ def _should_skip_xfail_test_sample(
return None, None


def _split_function_and_wrangler(
onnx_function_and_wrangler: Callable[..., Any]
| tuple[Callable[..., Any], Callable[..., Any]]
) -> tuple[Callable[..., Any], Callable[..., Any] | None]:
"""Splits a function with an optional input wrangler into a function and an input wrangler."""
if isinstance(onnx_function_and_wrangler, tuple):
return onnx_function_and_wrangler

assert callable(onnx_function_and_wrangler)
return onnx_function_and_wrangler, None


class TestFunctionValidity(unittest.TestCase):
def test_all_script_functions_are_onnx_functions(self):
functions = set()
for func_with_wrangler in ops_test_data.OPINFO_FUNCTION_MAPPING_SCRIPTED.values():
if isinstance(func_with_wrangler, tuple):
func = func_with_wrangler[0]
else:
func = func_with_wrangler
func, _ = _split_function_and_wrangler(func_with_wrangler)
functions.add(func)

# TODO(justinchuby): Add from the registry
Expand All @@ -77,10 +86,7 @@ def test_all_script_functions_are_onnx_functions(self):

def test_all_trace_only_functions_are_not_onnx_functions(self):
for func_with_wrangler in ops_test_data.OPINFO_FUNCTION_MAPPING_TRACE_ONLY.values():
if isinstance(func_with_wrangler, tuple):
func = func_with_wrangler[0]
else:
func = func_with_wrangler
func, _ = _split_function_and_wrangler(func_with_wrangler)
if isinstance(func, onnxscript.OnnxFunction):
raise AssertionError(
f"'{func.name}' is an OnnxFunction. "
Expand All @@ -96,10 +102,7 @@ def test_all_trace_only_functions_are_not_onnx_functions(self):
"Function checker is not available before ONNX 1.14",
)
def test_script_function_passes_checker(self, _, func_with_wrangler):
if isinstance(func_with_wrangler, tuple):
func = func_with_wrangler[0]
else:
func = func_with_wrangler
func, _ = _split_function_and_wrangler(func_with_wrangler)
function_proto = func.to_function_proto()
onnx.checker.check_function(function_proto) # type: ignore[attr-defined]

Expand Down Expand Up @@ -128,16 +131,11 @@ def run_test_output_match(
)

onnx_function_and_wrangler = ops_test_data.OPINFO_FUNCTION_MAPPING[op.name]
input_wrangler = None
if isinstance(onnx_function_and_wrangler, tuple):
# Obtain the input_wrangler that manipulates the OpInfo inputs
# to match the aten operator signature
# An example is nn.functional.upsample_nearest2d, which has a different signature
# than the aten operator upsample_nearest2d
onnx_function, input_wrangler = onnx_function_and_wrangler
else:
assert callable(onnx_function_and_wrangler)
onnx_function = onnx_function_and_wrangler
# Obtain the input_wrangler that manipulates the OpInfo inputs
# to match the aten operator signature
# An example is nn.functional.upsample_nearest2d, which has a different signature
# than the aten operator upsample_nearest2d
onnx_function, input_wrangler = _split_function_and_wrangler(onnx_function_and_wrangler)

for i, cpu_sample in enumerate(samples):
inputs = (cpu_sample.input, *cpu_sample.args)
Expand Down