Skip to content

[Migration][DO NOT MERGE] Fix and enable all new tests #1331

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

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install nox
run: python -m pip install nox
- name: Pull Test Data
run: git lfs pull
- name: Run tests
run: nox -t ${{ matrix.nox-tag }} --forcecolor -- -v --cov=onnxscript --cov-report=xml --cov-append --cov-branch -n=auto --junit-xml pytest.xml
env:
Expand Down
12 changes: 6 additions & 6 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include_patterns = [
'**/*.pyi',
]
exclude_patterns = [
'onnxscript/tests/models/**',
'tests/models/**',
]
command = [
'python',
Expand Down Expand Up @@ -43,7 +43,7 @@ exclude_patterns = [
'onnxscript/evaluator_test.py',
'onnxscript/evaluator.py',
'onnxscript/onnx_types.py',
'onnxscript/tests/**', # Skip linting test files for speed
'tests/**', # Skip linting test files for speed
'onnxscript/**/*_test.py', # Skip linting test files for speed
'onnxscript/function_libs/torch_lib/ops/**', # Operators typing do not play well with mypy
]
Expand Down Expand Up @@ -74,7 +74,7 @@ include_patterns = [
'**/*.py',
]
exclude_patterns = [
'onnxscript/tests/onnx_backend_test_code/**',
'tests/onnx_backend_test_code/**',
]
command = [
'python',
Expand Down Expand Up @@ -105,9 +105,9 @@ exclude_patterns = [
'docs/examples/**',
'docs/tutorial/examples/**',
'onnxscript/converter_test.py',
'onnxscript/tests/functions/**',
'onnxscript/tests/models/**',
'onnxscript/tests/onnx_backend_test_code/**',
'tests/functions/**',
'tests/models/**',
'tests/onnx_backend_test_code/**',
]
command = [
'python',
Expand Down
6 changes: 3 additions & 3 deletions onnxscript/backend/onnx_export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import onnxscript.testing
import onnxscript.values
from onnxscript.backend import onnx_backend, onnx_export
from onnxscript.tests.models import type_double
from tests.models import type_double


@dataclasses.dataclass
Expand Down Expand Up @@ -112,7 +112,7 @@ def extract_functions(name: str, content: str, test_folder: pathlib.Path):
init.touch(exist_ok=True)
file = test_folder / f"{name}.py"
file.write_text(content, encoding="utf-8")
import_name = f"onnxscript.tests.{test_folder.parts[-1]}.{name}"
import_name = f"tests.{test_folder.parts[-1]}.{name}"
try:
mod = importlib.import_module(import_name)
except (SyntaxError, ImportError) as e:
Expand All @@ -133,7 +133,7 @@ def exec_main(f, *inputs):


class TestOnnxBackEnd(unittest.TestCase):
root_folder = pathlib.Path(__file__).parent.parent
root_folder = pathlib.Path(__file__).parent.parent.parent
test_folder = root_folder / "tests" / "onnx_backend_test_code"
temp_folder = root_folder / "tests" / "export"

Expand Down
60 changes: 30 additions & 30 deletions onnxscript/converter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from onnxscript import BOOL, FLOAT, INT64, converter, graph, script, tensor
from onnxscript.onnx_opset import opset11 as op11
from onnxscript.onnx_opset import opset15 as op
from onnxscript.tests.common import onnx_script_test_case, testutils
from tests.common import onnx_script_test_case, testutils

TEST_INPUT_DIR = pathlib.Path(__file__).parent / "tests" / "models"
TEST_OUTPUT_DIR = TEST_INPUT_DIR / "testoutputs"
Expand Down Expand Up @@ -132,7 +132,7 @@ def validate_run(self, script_tests):
self.check_run(val.function, val.input, val.output[0])

def test_eager_op(self):
from onnxscript.tests.models import eager_op
from tests.models import eager_op

test_functions = self.validate_save(eager_op, check_ort=True)

Expand Down Expand Up @@ -195,39 +195,39 @@ def cast_add(x, y):
self.assertEqual(output_value_info.type.tensor_type.elem_type, onnx.TensorProto.FLOAT)

def test_onnxfns1(self):
from onnxscript.tests.models import onnxfns1
from tests.models import onnxfns1

self.validate(onnxfns1)

def test_onnxfns1A(self):
from onnxscript.tests.models import onnxfns1A
from tests.models import onnxfns1A

self.validate(onnxfns1A)

def test_ort_custom_ops(self):
from onnxscript.tests.functions import ort_custom_ops
from tests.functions import ort_custom_ops

self.validate(ort_custom_ops)

def test_unary_op(self):
from onnxscript.tests.models import m1
from tests.models import m1

self.validate_save(m1)

def test_subfunction_check_model(self):
from onnxscript.tests.models import subfunction
from tests.models import subfunction

model = subfunction.MyElu.function_ir.to_model_proto(producer_name="p2o")
model = onnx.shape_inference.infer_shapes(model)
onnx.checker.check_model(model)

def test_subfunction(self):
from onnxscript.tests.models import subfunction
from tests.models import subfunction

self.validate_save(subfunction, check_ort=True)

def test_if_models(self):
from onnxscript.tests.models import if_statement
from tests.models import if_statement

self.validate_save(if_statement)

Expand All @@ -246,28 +246,28 @@ def sumprod(x: FLOAT["N"], N: INT64) -> (FLOAT["N"], FLOAT["N"]): # noqa: F821
self.assertEqual(proto.doc_string.strip(), "Combines ReduceSum, ReduceProd.")

def test_signal(self):
from onnxscript.tests.models import signal_dft
from tests.models import signal_dft

# shape_inference crashes on stft.
self.validate_save(signal_dft, shape_inference=False)

def test_multi(self):
from onnxscript.tests.models import multi
from tests.models import multi

self.validate_save(multi, shape_inference=False)

def test_dropout(self):
from onnxscript.tests.models import dropout
from tests.models import dropout

self.validate_save(dropout, shape_inference=False)

def test_attrref(self):
from onnxscript.tests.models import attrref
from tests.models import attrref

self.validate_save(attrref, shape_inference=False)

def test_renaming(self):
from onnxscript.tests.models import renaming
from tests.models import renaming

self.validate_save(renaming, shape_inference=False)

Expand All @@ -276,18 +276,18 @@ def test_renaming(self):
reason="default_opset must be specified in script for functions that do not contain any use of an ONNX op",
)
def test_opt_output(self):
from onnxscript.tests.models import opt_output
from tests.models import opt_output

self.validate_save(opt_output, shape_inference=False)

def test_opt_input(self):
from onnxscript.tests.models import opt_input
from tests.models import opt_input

self.validate_save(opt_input, shape_inference=False)

@unittest.skip("A function with attributes cannot be exported as a model.")
def test_onnxfns2(self):
from onnxscript.tests.models import onnxfns2
from tests.models import onnxfns2

self.validate_save(onnxfns2, shape_inference=False)

Expand All @@ -301,7 +301,7 @@ def clipmax(x: FLOAT, max: FLOAT):
self.validate_save(clipmax)

def test_type_double(self):
from onnxscript.tests.models import type_double
from tests.models import type_double

fcts = self.validate_save(type_double, check_ort=False)
f = fcts["double_abs"]
Expand All @@ -320,17 +320,17 @@ def test_type_double(self):
self.validate_save(type_double, check_ort=True)

def test_cast_like(self):
from onnxscript.tests.models import cast_like
from tests.models import cast_like

self.validate_expansion(cast_like)

def test_identity(self):
from onnxscript.tests.models import identity
from tests.models import identity

self.validate_expansion(identity)

def test_opset_import(self):
from onnxscript.tests.models import different_opset
from tests.models import different_opset

fcts = self.validate_save(different_opset, shape_inference=False)
s16 = str(fcts["shape_A"])
Expand All @@ -345,7 +345,7 @@ def test_opset_import(self):
self.assertNotIn("version: 15", sdef)

def test_sequences(self):
from onnxscript.tests.models import sequences
from tests.models import sequences

test_functions = self.validate_save(sequences, check_ort=True)

Expand All @@ -372,7 +372,7 @@ def test_sequences(self):
np.testing.assert_almost_equal(eager_mode, result)

def test_loops_break(self):
from onnxscript.tests.models import loops_break
from tests.models import loops_break

test_functions = self.validate_save(loops_break, check_ort=True)
self.assertIn("loop1", test_functions)
Expand All @@ -392,7 +392,7 @@ def test_loops_break(self):
self.assertEqual(y.tolist(), [0, 11, -22])

def test_loops_while(self):
from onnxscript.tests.models import loops_while
from tests.models import loops_while

test_functions = self.validate_save(loops_while, check_ort=True)
self.assertIn("loop1", test_functions)
Expand All @@ -409,7 +409,7 @@ def test_loops_while(self):
self.assertEqual(res.tolist(), [0, 10, -20])

def test_getitem(self):
from onnxscript.tests.models import getitem
from tests.models import getitem

self.validate_save(getitem, check_ort=True, skip_check_ort=None)
self.validate_run(getitem)
Expand Down Expand Up @@ -459,28 +459,28 @@ def check_run(self, onnxfn, inputs, expected_output):
np.testing.assert_equal(output, expected_output)

def test_graph_attr_scan(self):
from onnxscript.tests.models.graph_attr import cumulative_sum
from tests.models.graph_attr import cumulative_sum

inputs = [np.array([1, 2, 3, 4, 5], dtype=np.int64)]
expected_output = np.array([1, 3, 6, 10, 15], dtype=np.int64)
self.check_run(cumulative_sum, inputs, expected_output)

def test_graph_attr_loop(self):
from onnxscript.tests.models.graph_attr import sum_to
from tests.models.graph_attr import sum_to

inputs = [np.array(6, dtype=np.int64)]
expected_output = np.array([0, 1, 3, 6, 10, 15], dtype=np.int64)
self.check_run(sum_to, inputs, expected_output)

def test_graph_attr_loop_error(self):
from onnxscript.tests.models.graph_attr import sum_to_error
from tests.models.graph_attr import sum_to_error

input = np.array(6, dtype=np.int64)
with self.assertRaisesRegex(TypeError, "@graph"):
sum_to_error(input)

def test_loop_outer_scope(self):
from onnxscript.tests.models.graph_attr import loop_add
from tests.models.graph_attr import loop_add

input_x = np.array([1, 2, 3], dtype=np.int64)
input_m = np.array(3, dtype=np.int64)
Expand All @@ -504,7 +504,7 @@ def inner():
return op.DummyOp(body=inner)

def test_attr(self):
from onnxscript.tests.functions import attr_test
from tests.functions import attr_test

self.validate_run(attr_test)

Expand Down
6 changes: 3 additions & 3 deletions onnxscript/ir/irbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import onnx

from onnxrewriter import ir
from onnxrewriter.ir import visitor
from onnxrewriter.utils import utils
from onnxscript import ir
from onnxscript.ir import visitor
from onnxscript.utils import utils

""" NOTE: IRBuilder and function visiting

Expand Down
2 changes: 1 addition & 1 deletion onnxscript/ir/irbuilder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import onnx.parser

from onnxrewriter.ir import irbuilder
from onnxscript.ir import irbuilder


class IRBuilderTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion onnxscript/ir/protobuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import onnx.helper
from onnx.helper import make_attribute

from onnxrewriter import ir
from onnxscript import ir


class ModelProtoBuilder:
Expand Down
6 changes: 3 additions & 3 deletions onnxscript/ir/protobuilder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import onnx.checker
import onnx.parser

from onnxrewriter.ir import irbuilder, protobuilder
from onnxrewriter.rewriter import pattern
from onnxrewriter.rewriter.onnxruntime import instance_to_group_normalization
from onnxscript.ir import irbuilder, protobuilder
from onnxscript.rewriter import pattern
from onnxscript.rewriter.onnxruntime import instance_to_group_normalization

op = pattern.onnxop

Expand Down
Loading