Skip to content

Conversation

@justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Aug 30, 2024

Introduce OpSignature accessible from the .op_signature property of all OpLike objects (traced function, onnx function and op). The OpSignature class leverages the IR to represent the signature of an operator, preserving ordering of all inputs and provides easy to work with type representations.

The PR also deprecates the ParamSchema class and properties.

Fixes #1697

The next PR will replace param_schemas usage.

@justinchuby justinchuby added topic: api module: IR Intermediate representation labels Aug 30, 2024
@justinchuby justinchuby marked this pull request as draft August 30, 2024 22:59
@codecov
Copy link

codecov bot commented Aug 30, 2024

❌ 19 Tests Failed:

Tests completed Failed Passed Skipped
14911 19 14892 2049
View the full list of 3 ❄️ flaky tests
tests.eager_mode_test.TestEagerModeArguments_0_reference_runtime test_function_all_input_by_kwargs

Flake rate in main: 35.66% (Passed 4270 times, Failed 2367 times)

Stack Traces | 0.002s run time
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:91: in run
    res = self._run(x, y)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:139: in _run
    res = (convert_from_ml_dtypes(res[0]),)
..../test_torch_nightly/lib/python3.12.../onnx/reference/custom_element_types.py:50: in convert_from_ml_dtypes
    return array.view(dtype=dtype)
E   ValueError: Changing the dtype of a 0d array is only supported if the itemsize is unchanged

The above exception was the direct cause of the following exception:
tests/eager_mode_test.py:109: in test_function_all_input_by_kwargs
    self.assertEqual(add_with_alpha(this=1.0, other=2.0), 3.0)
onnxscript/values.py:576: in __call__
    return evaluator.default().eval_function(self, args, kwargs)
onnxscript/evaluator.py:307: in eval_function
    result = function.function(*adapted_args, **adapted_kwargs)
tests/eager_mode_test.py:59: in add_with_alpha
    other = op.Mul(other, alpha)
.../onnx_opset/_impl/opset14.py:696: in Mul
    return op(*self._prepare_inputs(schema, A, B))
onnxscript/values.py:304: in __call__
    return evaluator.default().eval(schema, args, kwargs)
onnxscript/evaluator.py:194: in eval
    outputs = self._eval(schema, inputs, attributes, closure)
onnxscript/evaluator.py:524: in _eval
    result = session.run(None, session_run_input)
..../test_torch_nightly/lib/python3.12.../onnx/reference/reference_evaluator.py:599: in run
    outputs = node.run(*inputs, **linked_attributes)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:114: in run
    res = OpRunBinary.run(self, x, y)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:93: in run
    raise TypeError(
E   TypeError: Issues with types <class 'numpy.ndarray'>, <class 'numpy.ndarray'> (binary operator 'Mul').
tests.eager_mode_test.TestEagerModeArguments_0_reference_runtime test_function_attribute_by_positional_args

Flake rate in main: 35.66% (Passed 4270 times, Failed 2367 times)

Stack Traces | 0.002s run time
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:91: in run
    res = self._run(x, y)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:139: in _run
    res = (convert_from_ml_dtypes(res[0]),)
..../test_torch_nightly/lib/python3.12.../onnx/reference/custom_element_types.py:50: in convert_from_ml_dtypes
    return array.view(dtype=dtype)
E   ValueError: Changing the dtype of a 0d array is only supported if the itemsize is unchanged

The above exception was the direct cause of the following exception:
tests/eager_mode_test.py:112: in test_function_attribute_by_positional_args
    self.assertEqual(add_with_alpha(1.0, 2.0, 3.0), 7.0)
onnxscript/values.py:576: in __call__
    return evaluator.default().eval_function(self, args, kwargs)
onnxscript/evaluator.py:307: in eval_function
    result = function.function(*adapted_args, **adapted_kwargs)
tests/eager_mode_test.py:59: in add_with_alpha
    other = op.Mul(other, alpha)
.../onnx_opset/_impl/opset14.py:696: in Mul
    return op(*self._prepare_inputs(schema, A, B))
onnxscript/values.py:304: in __call__
    return evaluator.default().eval(schema, args, kwargs)
onnxscript/evaluator.py:194: in eval
    outputs = self._eval(schema, inputs, attributes, closure)
onnxscript/evaluator.py:524: in _eval
    result = session.run(None, session_run_input)
..../test_torch_nightly/lib/python3.12.../onnx/reference/reference_evaluator.py:599: in run
    outputs = node.run(*inputs, **linked_attributes)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:114: in run
    res = OpRunBinary.run(self, x, y)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:93: in run
    raise TypeError(
E   TypeError: Issues with types <class 'numpy.ndarray'>, <class 'numpy.ndarray'> (binary operator 'Mul').
tests.eager_mode_test.TestEagerModeArguments_0_reference_runtime test_function_input_and_attribute_by_kwargs_out_of_order

Flake rate in main: 35.66% (Passed 4270 times, Failed 2367 times)

Stack Traces | 0.003s run time
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:91: in run
    res = self._run(x, y)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:139: in _run
    res = (convert_from_ml_dtypes(res[0]),)
..../test_torch_nightly/lib/python3.12.../onnx/reference/custom_element_types.py:50: in convert_from_ml_dtypes
    return array.view(dtype=dtype)
E   ValueError: Changing the dtype of a 0d array is only supported if the itemsize is unchanged

The above exception was the direct cause of the following exception:
tests/eager_mode_test.py:115: in test_function_input_and_attribute_by_kwargs_out_of_order
    self.assertEqual(add_with_alpha(alpha=3.0, other=2.0, this=1.0), 7.0)
onnxscript/values.py:576: in __call__
    return evaluator.default().eval_function(self, args, kwargs)
onnxscript/evaluator.py:307: in eval_function
    result = function.function(*adapted_args, **adapted_kwargs)
tests/eager_mode_test.py:59: in add_with_alpha
    other = op.Mul(other, alpha)
.../onnx_opset/_impl/opset14.py:696: in Mul
    return op(*self._prepare_inputs(schema, A, B))
onnxscript/values.py:304: in __call__
    return evaluator.default().eval(schema, args, kwargs)
onnxscript/evaluator.py:194: in eval
    outputs = self._eval(schema, inputs, attributes, closure)
onnxscript/evaluator.py:524: in _eval
    result = session.run(None, session_run_input)
..../test_torch_nightly/lib/python3.12.../onnx/reference/reference_evaluator.py:599: in run
    outputs = node.run(*inputs, **linked_attributes)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:114: in run
    res = OpRunBinary.run(self, x, y)
..../test_torch_nightly/lib/python3.12.../reference/ops/_op.py:93: in run
    raise TypeError(
E   TypeError: Issues with types <class 'numpy.ndarray'>, <class 'numpy.ndarray'> (binary operator 'Mul').

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@github-actions
Copy link

github-actions bot commented Aug 30, 2024

Test Results

     24 files  ±  0      24 suites  ±0   2h 44m 6s ⏱️ + 4m 1s
 14 152 tests + 34  11 778 ✅ + 36    2 336 💤 ±0   32 ❌  - 2   6 🔥 ±0 
355 111 runs  +238  81 240 ✅ +240  273 617 💤 ±0  212 ❌  - 2  42 🔥 ±0 

For more details on these failures and errors, see this check.

Results for commit ff1aaa5. ± Comparison against base commit fac4825.

♻️ This comment has been updated with latest results.

@justinchuby justinchuby changed the title Introduce OpSignature and deprecate ParamSchema Introduce OpSignature Oct 23, 2024
@justinchuby justinchuby changed the title Introduce OpSignature Introduce OpSignature to IR Oct 23, 2024
@justinchuby justinchuby marked this pull request as ready for review October 23, 2024 23:04
@titaiwangms titaiwangms self-assigned this Oct 23, 2024
@justinchuby
Copy link
Collaborator Author

When the signature property is defined, PyTorch onnx exporter will not generate a new signature, and instead use what is here. However, since it is doing isinstance checks on the signature the exporter itself defines, we get isinstance errors there.


def param_schemas(self) -> Optional[tuple[ParamSchema, ...]]: ...
@property
def op_signature(self) -> Optional[_schemas.OpSignature]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
@justinchuby justinchuby enabled auto-merge (squash) October 29, 2024 19:18
@justinchuby justinchuby merged commit 3e795f2 into main Oct 29, 2024
24 of 41 checks passed
@justinchuby justinchuby deleted the justinchu/op-signature branch October 29, 2024 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: IR Intermediate representation topic: api

Projects

Development

Successfully merging this pull request may close these issues.

[core] Migrate OpSignature to ONNX Script

3 participants