diff --git a/docs/conf.py b/docs/conf.py index 547b74de7..49d3a135e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ -# Configuration file for the Sphinx documentation builder. -# To run the documentation: python -m sphinx docs dist/html +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +"""Configuration file for the Sphinx documentation builder. + +To run the documentation: python -m sphinx docs dist/html +""" import os import re diff --git a/docs/examples/01_plot_selu.py b/docs/examples/01_plot_selu.py index 57a1f03c1..5ad3c4935 100644 --- a/docs/examples/01_plot_selu.py +++ b/docs/examples/01_plot_selu.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """ Generating a FunctionProto ========================== diff --git a/docs/examples/02_plot_square_loss.py b/docs/examples/02_plot_square_loss.py index 5dce3545c..181e4cd2a 100644 --- a/docs/examples/02_plot_square_loss.py +++ b/docs/examples/02_plot_square_loss.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """ Generating a ModelProto ======================= diff --git a/docs/examples/03_export_lib.py b/docs/examples/03_export_lib.py index 8a8993b7a..f710fcb88 100644 --- a/docs/examples/03_export_lib.py +++ b/docs/examples/03_export_lib.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """ Generating a LibProto ===================== diff --git a/docs/examples/04_plot_eager_mode_evaluation.py b/docs/examples/04_plot_eager_mode_evaluation.py index 740e2275a..d1c8f7fb7 100644 --- a/docs/examples/04_plot_eager_mode_evaluation.py +++ b/docs/examples/04_plot_eager_mode_evaluation.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """ Eager mode evaluation ===================== diff --git a/docs/examples/05_plot_model_props.py b/docs/examples/05_plot_model_props.py index 4e10339be..950b0e346 100644 --- a/docs/examples/05_plot_model_props.py +++ b/docs/examples/05_plot_model_props.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """ ModelProto Properties ===================== diff --git a/docs/examples/06_plot_model_local_funs.py b/docs/examples/06_plot_model_local_funs.py index 3a60b3e6c..fdb0e434b 100644 --- a/docs/examples/06_plot_model_local_funs.py +++ b/docs/examples/06_plot_model_local_funs.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """ Model Local Functions ===================== diff --git a/docs/test/test_documentation_examples.py b/docs/test/test_documentation_examples.py index dcdcde281..eec42c6e6 100644 --- a/docs/test/test_documentation_examples.py +++ b/docs/test/test_documentation_examples.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import os import subprocess diff --git a/docs/tutorial/examples/dropout.py b/docs/tutorial/examples/dropout.py index 850b22edc..4530c7f34 100644 --- a/docs/tutorial/examples/dropout.py +++ b/docs/tutorial/examples/dropout.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/firstdim.py b/docs/tutorial/examples/firstdim.py index 187fedf56..63476949f 100644 --- a/docs/tutorial/examples/firstdim.py +++ b/docs/tutorial/examples/firstdim.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/forloop.py b/docs/tutorial/examples/forloop.py index 3b32b1a0e..75a13205d 100644 --- a/docs/tutorial/examples/forloop.py +++ b/docs/tutorial/examples/forloop.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/forwhileloop.py b/docs/tutorial/examples/forwhileloop.py index 100f246c7..ffca170d4 100644 --- a/docs/tutorial/examples/forwhileloop.py +++ b/docs/tutorial/examples/forwhileloop.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/hardmax_end_to_end.py b/docs/tutorial/examples/hardmax_end_to_end.py index e4cd881eb..9b49a5ca7 100644 --- a/docs/tutorial/examples/hardmax_end_to_end.py +++ b/docs/tutorial/examples/hardmax_end_to_end.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import onnx # We use ONNX opset 15 to define the function below. diff --git a/docs/tutorial/examples/leaky_relu.py b/docs/tutorial/examples/leaky_relu.py index 92fce52b1..e1d09a2a3 100644 --- a/docs/tutorial/examples/leaky_relu.py +++ b/docs/tutorial/examples/leaky_relu.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/leaky_relu_attr_promoted.py b/docs/tutorial/examples/leaky_relu_attr_promoted.py index eb736162e..058dc1936 100644 --- a/docs/tutorial/examples/leaky_relu_attr_promoted.py +++ b/docs/tutorial/examples/leaky_relu_attr_promoted.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/omitted_input.py b/docs/tutorial/examples/omitted_input.py index b4e839dd2..df35f4968 100644 --- a/docs/tutorial/examples/omitted_input.py +++ b/docs/tutorial/examples/omitted_input.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/outerscope_redef_error.py b/docs/tutorial/examples/outerscope_redef_error.py index a810e8eb7..41bd820d9 100644 --- a/docs/tutorial/examples/outerscope_redef_error.py +++ b/docs/tutorial/examples/outerscope_redef_error.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import graph, script from onnxscript import opset15 as op @@ -13,7 +15,7 @@ def Sum(sum_in, next): return sum_out, sum_out g = op.Constant(value=1) - all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1) + _all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1) return cumulative_sum except Exception as e: diff --git a/docs/tutorial/examples/scanloop.py b/docs/tutorial/examples/scanloop.py index c12da498d..6a409716a 100644 --- a/docs/tutorial/examples/scanloop.py +++ b/docs/tutorial/examples/scanloop.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import graph, script from onnxscript import opset15 as op @@ -9,5 +11,5 @@ def Sum(sum_in, next): sum_out = sum_in + next return sum_out, sum_out - all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1) + _all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1) return cumulative_sum diff --git a/docs/tutorial/examples/softplus.py b/docs/tutorial/examples/softplus.py index 0929bc0a0..18c194ea5 100644 --- a/docs/tutorial/examples/softplus.py +++ b/docs/tutorial/examples/softplus.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. # We use ONNX opset 15 to define the function below. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/tensor_attr.py b/docs/tutorial/examples/tensor_attr.py index de24de9f7..312ad7c5e 100644 --- a/docs/tutorial/examples/tensor_attr.py +++ b/docs/tutorial/examples/tensor_attr.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnx import TensorProto, helper from onnxscript import opset15 as op diff --git a/docs/tutorial/examples/tensor_attr2.py b/docs/tutorial/examples/tensor_attr2.py index a602b914c..eb60b04bc 100644 --- a/docs/tutorial/examples/tensor_attr2.py +++ b/docs/tutorial/examples/tensor_attr2.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnx import TensorProto, helper from onnxscript import opset15 as op diff --git a/docs/tutorial/examples/tensor_attr_short.py b/docs/tutorial/examples/tensor_attr_short.py index ddf32295c..b6a2452b9 100644 --- a/docs/tutorial/examples/tensor_attr_short.py +++ b/docs/tutorial/examples/tensor_attr_short.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript import opset15 as op from onnxscript import script diff --git a/docs/tutorial/examples/whileloop.py b/docs/tutorial/examples/whileloop.py index 36b153c81..68bcfbea4 100644 --- a/docs/tutorial/examples/whileloop.py +++ b/docs/tutorial/examples/whileloop.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnx import TensorProto from onnx.helper import make_tensor diff --git a/docs/tutorial/rewriter/examples/broadcast_matmul.py b/docs/tutorial/rewriter/examples/broadcast_matmul.py index ad48842a9..e529f39d0 100644 --- a/docs/tutorial/rewriter/examples/broadcast_matmul.py +++ b/docs/tutorial/rewriter/examples/broadcast_matmul.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Onnx Pattern Rewriting with match condition parameter. This script shows how to define a rewriting rule based on patterns while diff --git a/docs/tutorial/rewriter/examples/erfgelu.py b/docs/tutorial/rewriter/examples/erfgelu.py index 02c012b1c..a7f16cea0 100644 --- a/docs/tutorial/rewriter/examples/erfgelu.py +++ b/docs/tutorial/rewriter/examples/erfgelu.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Onnx Pattern Rewriting. This script shows how to define a rewriting rule based on patterns. diff --git a/docs/update_readme.py b/docs/update_readme.py index ddc5859cd..7d3940688 100644 --- a/docs/update_readme.py +++ b/docs/update_readme.py @@ -1,4 +1,6 @@ -# Script to update end-to-end example in README.md. +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +"""Script to update end-to-end example in README.md.""" updated_readme = [] with open("README.md", encoding="utf-8") as f: @@ -12,7 +14,7 @@ with open( "docs/tutorial/examples/hardmax_end_to_end.py", encoding="utf-8" ) as example_f: - example_code = example_f.readlines() + example_code = example_f.readlines()[2:] # Skip the copyright header updated_readme += example_code if line == "```\n" and in_stub: updated_readme.append(line) diff --git a/examples/pattern_rewriting.py b/examples/pattern_rewriting.py index c9dc2394f..7b5c56d5e 100644 --- a/examples/pattern_rewriting.py +++ b/examples/pattern_rewriting.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Onnx Pattern Rewriting. This script shows how to define a rewriting rule based on patterns. @@ -74,7 +76,9 @@ def rotary_match_pattern(op, x, pos_ids, axis): matmul = op.MatMul(pos_ids, cast) transpose = op.Transpose(matmul) - output, length = op.ConcatTraining(transpose, transpose, domain="com.microsoft", outputs=2) + output, _length = op.ConcatTraining( + transpose, transpose, domain="com.microsoft", outputs=2 + ) sin = op.Sin(output) cast1 = op.Cast(sin, to=onnx.TensorProto.FLOAT) diff --git a/noxfile.py b/noxfile.py index 33b1d1cfe..fd13236f5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Test with different environment configuration with nox. Documentation: diff --git a/onnxscript/__init__.py b/onnxscript/__init__.py index 96f1fa5ef..a4e6c92d1 100644 --- a/onnxscript/__init__.py +++ b/onnxscript/__init__.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- __all__ = [ "script", diff --git a/onnxscript/_internal/analysis.py b/onnxscript/_internal/analysis.py index 0901382ee..0403f60c9 100644 --- a/onnxscript/_internal/analysis.py +++ b/onnxscript/_internal/analysis.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import ast diff --git a/onnxscript/_internal/analysis_test.py b/onnxscript/_internal/analysis_test.py index 5531ec383..74e7ca4c1 100644 --- a/onnxscript/_internal/analysis_test.py +++ b/onnxscript/_internal/analysis_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import ast diff --git a/onnxscript/_internal/ast_utils.py b/onnxscript/_internal/ast_utils.py index 974ae75a0..17dea02e6 100644 --- a/onnxscript/_internal/ast_utils.py +++ b/onnxscript/_internal/ast_utils.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Utilities for working with Python ASTs.""" from __future__ import annotations diff --git a/onnxscript/_internal/autocast.py b/onnxscript/_internal/autocast.py index b79180ae5..00fab2432 100644 --- a/onnxscript/_internal/autocast.py +++ b/onnxscript/_internal/autocast.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations diff --git a/onnxscript/_internal/deprecation.py b/onnxscript/_internal/deprecation.py index 57769ba09..301565c8d 100644 --- a/onnxscript/_internal/deprecation.py +++ b/onnxscript/_internal/deprecation.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Utility for deprecating APIs.""" # Reference: https://github.com/pytorch/pytorch/blob/aed9bee0413dac190452fbfa9ab2a44b6e6843f5/torch/onnx/_deprecation.py diff --git a/onnxscript/_internal/param_manipulation.py b/onnxscript/_internal/param_manipulation.py index 54593abf3..5d1332315 100644 --- a/onnxscript/_internal/param_manipulation.py +++ b/onnxscript/_internal/param_manipulation.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Function for manipulating input parameters of an Op or a OnnxFunction.""" from __future__ import annotations diff --git a/onnxscript/_internal/param_manipulation_test.py b/onnxscript/_internal/param_manipulation_test.py index f7148268e..7b67e4380 100644 --- a/onnxscript/_internal/param_manipulation_test.py +++ b/onnxscript/_internal/param_manipulation_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. # mypy: disable-error-code=misc import collections diff --git a/onnxscript/_internal/runtime_typing.py b/onnxscript/_internal/runtime_typing.py index 54e7dae0c..1dae48643 100644 --- a/onnxscript/_internal/runtime_typing.py +++ b/onnxscript/_internal/runtime_typing.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """An internal wrapper for the beartype library. Decorate a function with `@runtime_typing.checked` to enable runtime diff --git a/onnxscript/_internal/utils.py b/onnxscript/_internal/utils.py index c4537e3bc..e081bb34a 100644 --- a/onnxscript/_internal/utils.py +++ b/onnxscript/_internal/utils.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import numbers diff --git a/onnxscript/_internal/version_utils.py b/onnxscript/_internal/version_utils.py index 3d179a59d..3a57bcdd0 100644 --- a/onnxscript/_internal/version_utils.py +++ b/onnxscript/_internal/version_utils.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Version utils for testing.""" import packaging.version diff --git a/onnxscript/_legacy_ir/__init__.py b/onnxscript/_legacy_ir/__init__.py index 74aa69359..6c4e0c07e 100644 --- a/onnxscript/_legacy_ir/__init__.py +++ b/onnxscript/_legacy_ir/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import dataclasses diff --git a/onnxscript/_legacy_ir/visitor.py b/onnxscript/_legacy_ir/visitor.py index 300ae054e..2a7257451 100644 --- a/onnxscript/_legacy_ir/visitor.py +++ b/onnxscript/_legacy_ir/visitor.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import dataclasses diff --git a/onnxscript/_legacy_ir/visitor_test.py b/onnxscript/_legacy_ir/visitor_test.py index e4559472e..7c0ebc05d 100644 --- a/onnxscript/_legacy_ir/visitor_test.py +++ b/onnxscript/_legacy_ir/visitor_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx diff --git a/onnxscript/_thirdparty/asciichartpy.py b/onnxscript/_thirdparty/asciichartpy.py index 3cd91f84f..68def718a 100644 --- a/onnxscript/_thirdparty/asciichartpy.py +++ b/onnxscript/_thirdparty/asciichartpy.py @@ -1,5 +1,5 @@ -# SPDX-License-Identifier: MIT -# Modifications Copyright (c) Microsoft. +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. # # Copyright © 2016 Igor Kroitor # diff --git a/onnxscript/backend/__init__.py b/onnxscript/backend/__init__.py index 862c45ce3..59e481eb9 100644 --- a/onnxscript/backend/__init__.py +++ b/onnxscript/backend/__init__.py @@ -1,4 +1,2 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- diff --git a/onnxscript/backend/onnx_backend.py b/onnxscript/backend/onnx_backend.py index 83c9bca39..78089ebe6 100644 --- a/onnxscript/backend/onnx_backend.py +++ b/onnxscript/backend/onnx_backend.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import os @@ -291,7 +289,7 @@ def enumerate_onnx_tests(series, fct_filter=None) -> Iterator[OnnxBackendTest]: sub = os.path.join(root, "data", series) if not os.path.exists(sub): raise FileNotFoundError( - "Unable to find series of tests in {root!r}, subfolders:\n" + f"Unable to find series of tests in {root!r}, subfolders:\n" + "\n".join(os.listdir(root)) ) tests = os.listdir(sub) diff --git a/onnxscript/backend/onnx_backend_test.py b/onnxscript/backend/onnx_backend_test.py index b64033149..efd9d823d 100644 --- a/onnxscript/backend/onnx_backend_test.py +++ b/onnxscript/backend/onnx_backend_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import os import unittest diff --git a/onnxscript/backend/onnx_export.py b/onnxscript/backend/onnx_export.py index 01ab09c8f..47720951e 100644 --- a/onnxscript/backend/onnx_export.py +++ b/onnxscript/backend/onnx_export.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations from typing import Any, Optional, Sequence @@ -311,7 +309,7 @@ def _translate_onnx_var_ref(self, var): def _rename_domain(self, domain: str) -> str: if domain in {"", "ai.onnx"}: - return "opset" # TODO: Need checks to avoid name conflicts. + return "opset" # TODO: Need checks to avoid name conflicts. return _cleanup_variable_name(domain) # type: ignore[return-value] def _make_opset_name(self, domain, version): diff --git a/onnxscript/backend/onnx_export_test.py b/onnxscript/backend/onnx_export_test.py index efcc8ae8a..d5d49acc3 100644 --- a/onnxscript/backend/onnx_export_test.py +++ b/onnxscript/backend/onnx_export_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import dataclasses diff --git a/onnxscript/converter.py b/onnxscript/converter.py index 515829488..2f9b690c9 100644 --- a/onnxscript/converter.py +++ b/onnxscript/converter.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import ast @@ -429,9 +427,7 @@ def _emit_copy(self, original_var: str, suggested_name: str) -> str: def _is_constant_expr(self, node: ast.AST) -> None: if isinstance(node, ast.UnaryOp): - if self._is_constant_expr(node.operand): - return True - return False + return self._is_constant_expr(node.operand) if isinstance( node, ( @@ -527,7 +523,7 @@ def _translate_attr( # in a NodeProto. if val is None: if attr_meta and attr_meta.required: - self.fail(expr, "Attribute '{attr_name}' is required.") + self.fail(expr, f"Attribute '{attr_name}' is required.") return None attr_type = attr_meta.type if attr_meta else None attr = self._make_onnx_attr(attr_name, val, attr_type) diff --git a/onnxscript/converter_test.py b/onnxscript/converter_test.py index 121175755..46d88f9f1 100644 --- a/onnxscript/converter_test.py +++ b/onnxscript/converter_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import ast import inspect diff --git a/onnxscript/diagnostics/infra/__init__.py b/onnxscript/diagnostics/infra/__init__.py index 1d771666f..d271aea2e 100644 --- a/onnxscript/diagnostics/infra/__init__.py +++ b/onnxscript/diagnostics/infra/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from ._infra import ( DiagnosticOptions, Graph, diff --git a/onnxscript/diagnostics/infra/_infra.py b/onnxscript/diagnostics/infra/_infra.py index f225a191f..1d8d4264b 100644 --- a/onnxscript/diagnostics/infra/_infra.py +++ b/onnxscript/diagnostics/infra/_infra.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """This file defines an additional layer of abstraction on top of the SARIF OM.""" from __future__ import annotations diff --git a/onnxscript/diagnostics/infra/context.py b/onnxscript/diagnostics/infra/context.py index 26d0c1bd2..081ba9f65 100644 --- a/onnxscript/diagnostics/infra/context.py +++ b/onnxscript/diagnostics/infra/context.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """A diagnostic context based on SARIF.""" from __future__ import annotations @@ -324,7 +326,7 @@ def pretty_print( formatter.pretty_print_title(f"Diagnostic Run {self.name} version {self.version}") print(f"verbose: {verbose}, log level: {log_level}") - diagnostic_stats = {level: 0 for level in infra.Level} + diagnostic_stats = dict.fromkeys(infra.Level, 0) for diagnostic in self.diagnostics: diagnostic_stats[diagnostic.level] += 1 formatter.pretty_print_title( diff --git a/onnxscript/diagnostics/infra/decorator.py b/onnxscript/diagnostics/infra/decorator.py index e72da19c4..56a362624 100644 --- a/onnxscript/diagnostics/infra/decorator.py +++ b/onnxscript/diagnostics/infra/decorator.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import functools diff --git a/onnxscript/diagnostics/infra/formatter.py b/onnxscript/diagnostics/infra/formatter.py index c54e81fed..1ccf77b5c 100644 --- a/onnxscript/diagnostics/infra/formatter.py +++ b/onnxscript/diagnostics/infra/formatter.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import dataclasses diff --git a/onnxscript/diagnostics/infra/utils.py b/onnxscript/diagnostics/infra/utils.py index bc8f5f9c7..463fc3ea0 100644 --- a/onnxscript/diagnostics/infra/utils.py +++ b/onnxscript/diagnostics/infra/utils.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import functools diff --git a/onnxscript/evaluator.py b/onnxscript/evaluator.py index a936824ca..6020f9e78 100644 --- a/onnxscript/evaluator.py +++ b/onnxscript/evaluator.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import abc @@ -369,7 +367,7 @@ def _onnxscript_to_numpy_value(v): if isinstance(v, list): return [_onnxscript_to_numpy_value(x) for x in v] if isinstance(v, tuple): - if len(v) > 0 and type(v[0]) is int: # noqa: E721 # pylint: disable=unidiomatic-typecheck + if len(v) > 0 and type(v[0]) is int: # pylint: disable=unidiomatic-typecheck return np.array(v, dtype=np.int64) return np.array(v) if v is None: diff --git a/onnxscript/evaluator_test.py b/onnxscript/evaluator_test.py index a5ad41a78..d42b1bab7 100644 --- a/onnxscript/evaluator_test.py +++ b/onnxscript/evaluator_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import numpy as np diff --git a/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints.py b/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints.py index 37232c84e..20b343697 100644 --- a/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints.py +++ b/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import copy @@ -151,11 +153,9 @@ def __repr__(self): " Type Constraints: ", ] # Trick to get unique type constraints but maintain the order. - ordered_unique_type_constraints = { - v: None for v in self.input_type_constraints.values() - } + ordered_unique_type_constraints = dict.fromkeys(self.input_type_constraints.values()) ordered_unique_type_constraints.update( - {v: None for v in self.output_type_constraints.values()} + dict.fromkeys(self.output_type_constraints.values()) ) repr_strs += [ f" {type_constraint.name}: {type_constraint.type_strs}" @@ -175,9 +175,9 @@ def __repr__(self): repr_strs += [ " Intermediate Type Constraints: ", ] - ordered_unique_type_constraints = { - v: None for v in self.intermediate_type_constraints.values() - } + ordered_unique_type_constraints = dict.fromkeys( + self.intermediate_type_constraints.values() + ) repr_strs += [ f" {type_constraint.name}: {type_constraint.type_strs}" for type_constraint in ordered_unique_type_constraints diff --git a/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints_test.py b/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints_test.py index 25586085e..a8d15c242 100644 --- a/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints_test.py +++ b/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Test cases for type constraint deduction functionality.""" from __future__ import annotations diff --git a/onnxscript/function_libs/torch_lib/__init__.py b/onnxscript/function_libs/torch_lib/__init__.py index 4c4966c2b..18e9054a6 100644 --- a/onnxscript/function_libs/torch_lib/__init__.py +++ b/onnxscript/function_libs/torch_lib/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """A torch function library for onnxscript. The modules are named after the torch module names for grouping: diff --git a/onnxscript/function_libs/torch_lib/_constants.py b/onnxscript/function_libs/torch_lib/_constants.py index 58cc2c068..f4e14061e 100644 --- a/onnxscript/function_libs/torch_lib/_constants.py +++ b/onnxscript/function_libs/torch_lib/_constants.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Shared constants for the library.""" DOMAIN = "pkg.onnxscript.torch_lib" diff --git a/onnxscript/function_libs/torch_lib/_flags.py b/onnxscript/function_libs/torch_lib/_flags.py index b19ae2630..f3645ecae 100644 --- a/onnxscript/function_libs/torch_lib/_flags.py +++ b/onnxscript/function_libs/torch_lib/_flags.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Experimental flags. NOTE: These flags are experimental only. Any flag here can be removed at any diff --git a/onnxscript/function_libs/torch_lib/graph_building/__init__.py b/onnxscript/function_libs/torch_lib/graph_building/__init__.py index e70f7f4c2..58acc6c05 100644 --- a/onnxscript/function_libs/torch_lib/graph_building/__init__.py +++ b/onnxscript/function_libs/torch_lib/graph_building/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """APIs for building an ONNX graph from a PyTorch model. This module exposes only three classes that will be used to build an ONNX graph diff --git a/onnxscript/function_libs/torch_lib/graph_building/_graph_building_ir.py b/onnxscript/function_libs/torch_lib/graph_building/_graph_building_ir.py index 015c0e2be..1270c6376 100644 --- a/onnxscript/function_libs/torch_lib/graph_building/_graph_building_ir.py +++ b/onnxscript/function_libs/torch_lib/graph_building/_graph_building_ir.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Graph building functions using the ONNX IR, compatible with the original TorchScriptGraph usage.""" from __future__ import annotations @@ -210,7 +212,7 @@ def eval_function( # type: ignore[override] else: # Fall to call add_function_call pass - elif isinstance(args[0], Sequence): # noqa: SIM103 + elif isinstance(args[0], Sequence): return False else: # Python constants are scalars @@ -592,7 +594,7 @@ def _fetch_function_dict( ) # Fetch torchlib function protos. for identifier, function in self._function_store.items(): - function_dict[identifier] = function + function_dict[identifier] = function # noqa: PERF403 return function_dict def add_op_call( diff --git a/onnxscript/function_libs/torch_lib/graph_building/_graph_building_torch.py b/onnxscript/function_libs/torch_lib/graph_building/_graph_building_torch.py index a00df9f93..5e0a48077 100644 --- a/onnxscript/function_libs/torch_lib/graph_building/_graph_building_torch.py +++ b/onnxscript/function_libs/torch_lib/graph_building/_graph_building_torch.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Graph building functions for torchscript graph backend.""" from __future__ import annotations @@ -363,7 +365,7 @@ def eval_function( # type: ignore[override] else: # Fall to call add_function_call pass - elif isinstance(args[0], Sequence): # noqa: SIM103 + elif isinstance(args[0], Sequence): return False else: # Python constants are scalars diff --git a/onnxscript/function_libs/torch_lib/graph_building/graph_building_test.py b/onnxscript/function_libs/torch_lib/graph_building/graph_building_test.py index 76464b70e..d5352be7c 100644 --- a/onnxscript/function_libs/torch_lib/graph_building/graph_building_test.py +++ b/onnxscript/function_libs/torch_lib/graph_building/graph_building_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Test cases for graph building functionality.""" # mypy: disable-error-code="arg-type,type-arg,valid-type" diff --git a/onnxscript/function_libs/torch_lib/ops/__init__.py b/onnxscript/function_libs/torch_lib/ops/__init__.py index 5a1cfd76c..ef023013b 100644 --- a/onnxscript/function_libs/torch_lib/ops/__init__.py +++ b/onnxscript/function_libs/torch_lib/ops/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. __all__ = [ "core", "fft", diff --git a/onnxscript/function_libs/torch_lib/ops/common.py b/onnxscript/function_libs/torch_lib/ops/common.py index ecef6852b..cae319e2e 100644 --- a/onnxscript/function_libs/torch_lib/ops/common.py +++ b/onnxscript/function_libs/torch_lib/ops/common.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Common operators shared in the torchlib library.""" import onnxscript diff --git a/onnxscript/function_libs/torch_lib/registration.py b/onnxscript/function_libs/torch_lib/registration.py index 2b3e6577e..505edee06 100644 --- a/onnxscript/function_libs/torch_lib/registration.py +++ b/onnxscript/function_libs/torch_lib/registration.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Registry for aten functions.""" from __future__ import annotations diff --git a/onnxscript/ir/__init__.py b/onnxscript/ir/__init__.py index fa58bc296..80df83bbf 100644 --- a/onnxscript/ir/__init__.py +++ b/onnxscript/ir/__init__.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """In-memory intermediate representation for ONNX graphs.""" __all__ = [ diff --git a/onnxscript/ir/_convenience.py b/onnxscript/ir/_convenience.py index f0c41b109..b53d88fe5 100644 --- a/onnxscript/ir/_convenience.py +++ b/onnxscript/ir/_convenience.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Convenience methods for constructing and manipulating the IR. This is an internal only module. We should choose to expose some of the methods diff --git a/onnxscript/ir/_core.py b/onnxscript/ir/_core.py index c391a63d5..1442ba5e9 100644 --- a/onnxscript/ir/_core.py +++ b/onnxscript/ir/_core.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """data structures for the intermediate representation.""" # NOTES for developers: @@ -298,13 +296,13 @@ class Tensor(TensorBase, _protocols.TensorProtocol, Generic[TArrayCompatible]): """ __slots__ = ( - "_raw", "_dtype", + "_metadata", + "_metadata_props", + "_raw", "_shape", - "name", "doc_string", - "_metadata_props", - "_metadata", + "name", ) def __init__( @@ -487,17 +485,17 @@ class ExternalTensor(TensorBase, _protocols.TensorProtocol): # pylint: disable= """ __slots__ = ( - "_path", - "_offset", - "_length", + "_array", "_dtype", + "_length", + "_metadata", + "_metadata_props", + "_offset", + "_path", "_shape", - "name", "doc_string", - "_array", + "name", "raw", - "_metadata_props", - "_metadata", ) def __init__( @@ -647,12 +645,12 @@ class StringTensor(TensorBase, _protocols.TensorProtocol): # pylint: disable=to """Multidimensional array of strings (as binary data to match the string_data field in TensorProto).""" __slots__ = ( + "_metadata", + "_metadata_props", "_raw", "_shape", - "name", "doc_string", - "_metadata_props", - "_metadata", + "name", ) def __init__( @@ -947,18 +945,18 @@ class Node(_protocols.NodeProtocol, _display.PrettyPrintable): """ __slots__ = ( - "_name", + "_attributes", "_domain", - "_op_type", + "_graph", "_inputs", + "_metadata", + "_metadata_props", + "_name", + "_op_type", "_outputs", - "_attributes", "_overload", "_version", "doc_string", - "_metadata", - "_metadata_props", - "_graph", ) def __init__( @@ -1057,7 +1055,7 @@ def _create_outputs( if num_outputs is not None and outputs is not None and num_outputs != len(outputs): raise ValueError( "num_outputs must be the same as len(outputs) when num_outputs is specified." - "num_outputs: {num_outputs}, outputs: {outputs}" + f"num_outputs: {num_outputs}, outputs: {outputs}" ) # 1. If outputs is specified (can be empty []), use the outputs if outputs is not None: @@ -1393,8 +1391,8 @@ class Value(_protocols.ValueProtocol, _display.PrettyPrintable): __slots__ = ( "_const_value", "_index", - "_metadata_props", "_metadata", + "_metadata_props", "_name", "_producer", "_shape", @@ -1685,16 +1683,16 @@ class Graph(_protocols.GraphProtocol, Sequence[Node], _display.PrettyPrintable): """ __slots__ = ( - "name", - "_inputs", - "_outputs", - "_initializers", "_doc_string", - "_opset_imports", - "_nodes", + "_initializers", + "_inputs", "_metadata", "_metadata_props", "_name_authority", + "_nodes", + "_opset_imports", + "_outputs", + "name", ) def __init__( @@ -1973,10 +1971,10 @@ def _graph_str(graph: Graph | GraphView) -> str: signature = f"""\ graph( name={graph.name or 'anonymous_graph:' + str(id(graph))}, - inputs=({textwrap.indent(inputs_text, ' '*8)} + inputs=({textwrap.indent(inputs_text, ' ' * 8)} ), - outputs=({textwrap.indent(outputs_text, ' '*8)} - ),{textwrap.indent(initializers_text, ' '*4)} + outputs=({textwrap.indent(outputs_text, ' ' * 8)} + ),{textwrap.indent(initializers_text, ' ' * 4)} )""" node_count = len(graph) number_width = len(str(node_count)) @@ -2011,10 +2009,10 @@ def _graph_repr(graph: Graph | GraphView) -> str: return f"""\ {graph.__class__.__name__}( name={graph.name or 'anonymous_graph:' + str(id(graph))!r}, - inputs=({textwrap.indent(inputs_text, ' '*8)} + inputs=({textwrap.indent(inputs_text, ' ' * 8)} ), - outputs=({textwrap.indent(outputs_text, ' '*8)} - ),{textwrap.indent(initializers_text, ' '*4)} + outputs=({textwrap.indent(outputs_text, ' ' * 8)} + ),{textwrap.indent(initializers_text, ' ' * 4)} len()={len(graph)} )""" @@ -2053,15 +2051,15 @@ class GraphView(Sequence[Node], _display.PrettyPrintable): """ __slots__ = ( - "name", - "inputs", - "outputs", - "initializers", - "doc_string", - "opset_imports", - "nodes", "_metadata", "_metadata_props", + "doc_string", + "initializers", + "inputs", + "name", + "nodes", + "opset_imports", + "outputs", ) def __init__( @@ -2127,16 +2125,16 @@ def __repr__(self) -> str: class Model(_protocols.ModelProtocol, _display.PrettyPrintable): __slots__ = ( + "_functions", + "_metadata", + "_metadata_props", + "doc_string", + "domain", "graph", "ir_version", + "model_version", "producer_name", "producer_version", - "domain", - "model_version", - "doc_string", - "_functions", - "_metadata", - "_metadata_props", ) """IR Model. @@ -2256,13 +2254,13 @@ class Function(_protocols.FunctionProtocol, Sequence[Node], _display.PrettyPrint """ __slots__ = ( + "_attributes", "_domain", - "_name", - "_overload", "_graph", - "_attributes", "_metadata", "_metadata_props", + "_name", + "_overload", ) def __init__( @@ -2428,10 +2426,10 @@ def __str__(self) -> str: > def {full_name}( inputs=( -{textwrap.indent(inputs_text, ' '*8)} - ),{textwrap.indent(attributes_text, ' '*4)} +{textwrap.indent(inputs_text, ' ' * 8)} + ),{textwrap.indent(attributes_text, ' ' * 4)} outputs=( -{textwrap.indent(outputs_text, ' '*8)} +{textwrap.indent(outputs_text, ' ' * 8)} ), )""" node_count = len(self) @@ -2507,7 +2505,7 @@ def __repr__(self) -> str: class Attr(_protocols.AttributeProtocol, _display.PrettyPrintable): """Base class for ONNX attributes.""" - __slots__ = ("name", "type", "value", "doc_string") + __slots__ = ("doc_string", "name", "type", "value") def __init__( self, diff --git a/onnxscript/ir/_core_test.py b/onnxscript/ir/_core_test.py index 95fc1f339..1fbbca692 100644 --- a/onnxscript/ir/_core_test.py +++ b/onnxscript/ir/_core_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import copy diff --git a/onnxscript/ir/_display.py b/onnxscript/ir/_display.py index 937af9299..d0e400b95 100644 --- a/onnxscript/ir/_display.py +++ b/onnxscript/ir/_display.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Internal utilities for displaying the intermediate representation of a model. NOTE: All third-party imports should be scoped and imported only when used to avoid diff --git a/onnxscript/ir/_display_test.py b/onnxscript/ir/_display_test.py index 33e603a9b..ee745b484 100644 --- a/onnxscript/ir/_display_test.py +++ b/onnxscript/ir/_display_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Test display() methods in various classes.""" import contextlib diff --git a/onnxscript/ir/_enums.py b/onnxscript/ir/_enums.py index 66522134a..d561ad58d 100644 --- a/onnxscript/ir/_enums.py +++ b/onnxscript/ir/_enums.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """ONNX IR enums that matches the ONNX spec.""" from __future__ import annotations diff --git a/onnxscript/ir/_enums_test.py b/onnxscript/ir/_enums_test.py index a08debf0b..661681920 100644 --- a/onnxscript/ir/_enums_test.py +++ b/onnxscript/ir/_enums_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import numpy as np diff --git a/onnxscript/ir/_graph_comparison.py b/onnxscript/ir/_graph_comparison.py index 788b4b4d5..e13b8ba47 100644 --- a/onnxscript/ir/_graph_comparison.py +++ b/onnxscript/ir/_graph_comparison.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Utilities for comparing IR graphs.""" from __future__ import annotations diff --git a/onnxscript/ir/_linked_list.py b/onnxscript/ir/_linked_list.py index 059a88f2b..2c12ad856 100644 --- a/onnxscript/ir/_linked_list.py +++ b/onnxscript/ir/_linked_list.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Mutable list for nodes in a graph with safe mutation properties.""" from __future__ import annotations @@ -32,7 +30,7 @@ class _LinkBox(Generic[T]): value: The actual object in the list. """ - __slots__ = ("prev", "next", "value", "owning_list") + __slots__ = ("next", "owning_list", "prev", "value") def __init__(self, owner: DoublyLinkedSet[T], value: T | None) -> None: """Create a new link box. @@ -66,7 +64,7 @@ def __repr__(self) -> str: return f"_LinkBox({self.value!r}, erased={self.erased}, prev={self.prev.value!r}, next={self.next.value!r})" -class DoublyLinkedSet(Generic[T], Sequence[T]): +class DoublyLinkedSet(Sequence[T], Generic[T]): """A doubly linked ordered set of nodes. The container can be viewed as a set as it does not allow duplicate values. The order of the @@ -92,7 +90,7 @@ class DoublyLinkedSet(Generic[T], Sequence[T]): Values need to be hashable. ``None`` is not a valid value in the set. """ - __slots__ = ("_root", "_length", "_value_ids_to_boxes") + __slots__ = ("_length", "_root", "_value_ids_to_boxes") def __init__(self, values: Iterable[T] | None = None) -> None: # Using the root node simplifies the mutation implementation a lot diff --git a/onnxscript/ir/_linked_list_test.py b/onnxscript/ir/_linked_list_test.py index a82b0e172..00f03e71e 100644 --- a/onnxscript/ir/_linked_list_test.py +++ b/onnxscript/ir/_linked_list_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Unit tests for the _linked_list module.""" from __future__ import annotations diff --git a/onnxscript/ir/_metadata.py b/onnxscript/ir/_metadata.py index bbb01a959..77db7cc41 100644 --- a/onnxscript/ir/_metadata.py +++ b/onnxscript/ir/_metadata.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Class for storing metadata about the IR objects.""" from __future__ import annotations diff --git a/onnxscript/ir/_name_authority.py b/onnxscript/ir/_name_authority.py index d89d57023..ab12be532 100644 --- a/onnxscript/ir/_name_authority.py +++ b/onnxscript/ir/_name_authority.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Auxiliary class for managing names in the IR.""" from __future__ import annotations diff --git a/onnxscript/ir/_name_authority_test.py b/onnxscript/ir/_name_authority_test.py index 4bf7c6c7d..1a0fed80c 100644 --- a/onnxscript/ir/_name_authority_test.py +++ b/onnxscript/ir/_name_authority_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest from onnxscript import ir diff --git a/onnxscript/ir/_protocols.py b/onnxscript/ir/_protocols.py index f97c592eb..980078c66 100644 --- a/onnxscript/ir/_protocols.py +++ b/onnxscript/ir/_protocols.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Protocols for the ONNX IR. This file defines the interfaces for tools to interact with the IR. The interfaces diff --git a/onnxscript/ir/_type_casting.py b/onnxscript/ir/_type_casting.py index 0dc300627..3f3611000 100644 --- a/onnxscript/ir/_type_casting.py +++ b/onnxscript/ir/_type_casting.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Numpy utilities for non-native type operation.""" # TODO(justinchuby): Upstream the logic to onnx diff --git a/onnxscript/ir/_type_casting_test.py b/onnxscript/ir/_type_casting_test.py index c7ca82eb5..abe4923ee 100644 --- a/onnxscript/ir/_type_casting_test.py +++ b/onnxscript/ir/_type_casting_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest import numpy as np diff --git a/onnxscript/ir/convenience.py b/onnxscript/ir/convenience.py index cd09ccad9..03140f16a 100644 --- a/onnxscript/ir/convenience.py +++ b/onnxscript/ir/convenience.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Convenience methods for constructing and manipulating the IR.""" from __future__ import annotations diff --git a/onnxscript/ir/passes/__init__.py b/onnxscript/ir/passes/__init__.py index 14a364027..9cea129d2 100644 --- a/onnxscript/ir/passes/__init__.py +++ b/onnxscript/ir/passes/__init__.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- __all__ = [ "PassBase", diff --git a/onnxscript/ir/passes/_pass_infra.py b/onnxscript/ir/passes/_pass_infra.py index 30ba13d55..c03a23bd8 100644 --- a/onnxscript/ir/passes/_pass_infra.py +++ b/onnxscript/ir/passes/_pass_infra.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- # # This module implements some APIs described in # https://pytorch.org/executorch/stable/compiler-custom-compiler-passes.html diff --git a/onnxscript/ir/serde.py b/onnxscript/ir/serde.py index b1237b30d..a435d599e 100644 --- a/onnxscript/ir/serde.py +++ b/onnxscript/ir/serde.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Serialize and deserialize the intermediate representation to/from ONNX protos.""" # NOTES for developers: diff --git a/onnxscript/ir/serde_test.py b/onnxscript/ir/serde_test.py index 645e29cd4..50d0f568f 100644 --- a/onnxscript/ir/serde_test.py +++ b/onnxscript/ir/serde_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import ml_dtypes diff --git a/onnxscript/ir/traversal.py b/onnxscript/ir/traversal.py index 4227b42b8..5951506fe 100644 --- a/onnxscript/ir/traversal.py +++ b/onnxscript/ir/traversal.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """Utilities for traversing the IR graph.""" from __future__ import annotations diff --git a/onnxscript/ir/traversal_test.py b/onnxscript/ir/traversal_test.py index b5cd30232..5ed4d3147 100644 --- a/onnxscript/ir/traversal_test.py +++ b/onnxscript/ir/traversal_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import unittest diff --git a/onnxscript/irbuilder.py b/onnxscript/irbuilder.py index 90923a3f6..407a1ccdb 100644 --- a/onnxscript/irbuilder.py +++ b/onnxscript/irbuilder.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import dataclasses diff --git a/onnxscript/main.py b/onnxscript/main.py index 51c180e27..0b394a1b2 100644 --- a/onnxscript/main.py +++ b/onnxscript/main.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- # pylint disable: protected-access from __future__ import annotations diff --git a/onnxscript/onnx_types.py b/onnxscript/onnx_types.py index 6af57d4b1..d4ddb2fe8 100644 --- a/onnxscript/onnx_types.py +++ b/onnxscript/onnx_types.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations diff --git a/onnxscript/optimizer/__init__.py b/onnxscript/optimizer/__init__.py index 0931e45c3..2a359171e 100644 --- a/onnxscript/optimizer/__init__.py +++ b/onnxscript/optimizer/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import logging from typing import Any diff --git a/onnxscript/optimizer/constant_folding.py b/onnxscript/optimizer/constant_folding.py index c835173fa..82c0f2536 100644 --- a/onnxscript/optimizer/constant_folding.py +++ b/onnxscript/optimizer/constant_folding.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/optimizer/constant_folding_test.py b/onnxscript/optimizer/constant_folding_test.py index 64a27e33d..8fc7fe4a0 100644 --- a/onnxscript/optimizer/constant_folding_test.py +++ b/onnxscript/optimizer/constant_folding_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx diff --git a/onnxscript/optimizer/fold_constants_v0.py b/onnxscript/optimizer/fold_constants_v0.py index 556f824b8..9be7c9eda 100644 --- a/onnxscript/optimizer/fold_constants_v0.py +++ b/onnxscript/optimizer/fold_constants_v0.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations from typing import Any, Sequence diff --git a/onnxscript/optimizer/function_folding_test.py b/onnxscript/optimizer/function_folding_test.py index 296048a44..1d911bd91 100644 --- a/onnxscript/optimizer/function_folding_test.py +++ b/onnxscript/optimizer/function_folding_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx diff --git a/onnxscript/optimizer/remove_unused.py b/onnxscript/optimizer/remove_unused.py index 57357f3db..2b8cd6789 100644 --- a/onnxscript/optimizer/remove_unused.py +++ b/onnxscript/optimizer/remove_unused.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/optimizer/remove_unused_function.py b/onnxscript/optimizer/remove_unused_function.py index 10ef18ab3..dedf69d91 100644 --- a/onnxscript/optimizer/remove_unused_function.py +++ b/onnxscript/optimizer/remove_unused_function.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import logging diff --git a/onnxscript/optimizer/remove_unused_test.py b/onnxscript/optimizer/remove_unused_test.py index 350808def..656d808a9 100644 --- a/onnxscript/optimizer/remove_unused_test.py +++ b/onnxscript/optimizer/remove_unused_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx diff --git a/onnxscript/optimizer/simple_function_folding.py b/onnxscript/optimizer/simple_function_folding.py index 8b6f6662b..3abd6d8c9 100644 --- a/onnxscript/optimizer/simple_function_folding.py +++ b/onnxscript/optimizer/simple_function_folding.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Inlines the function if it only contains very few number of nodes.""" from __future__ import annotations diff --git a/onnxscript/optimizer/simple_function_folding_test.py b/onnxscript/optimizer/simple_function_folding_test.py index 34a9e613b..ffb987476 100644 --- a/onnxscript/optimizer/simple_function_folding_test.py +++ b/onnxscript/optimizer/simple_function_folding_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import unittest diff --git a/onnxscript/rewriter/__init__.py b/onnxscript/rewriter/__init__.py index e3add1ac1..1174006d9 100644 --- a/onnxscript/rewriter/__init__.py +++ b/onnxscript/rewriter/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations from typing import Sequence, Union diff --git a/onnxscript/rewriter/_ir_utils.py b/onnxscript/rewriter/_ir_utils.py index 702e5a3f9..c7a7b7ad0 100644 --- a/onnxscript/rewriter/_ir_utils.py +++ b/onnxscript/rewriter/_ir_utils.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """This is a temporary utility to assist new IR while it's still under development.""" from __future__ import annotations diff --git a/onnxscript/rewriter/_tape.py b/onnxscript/rewriter/_tape.py index 5b35b0dbc..8ebed05fa 100644 --- a/onnxscript/rewriter/_tape.py +++ b/onnxscript/rewriter/_tape.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Convenience methods for constructing the IR.""" # NOTE: This is a temporary solution for constructing the IR. It should be replaced diff --git a/onnxscript/rewriter/broadcast_to_matmul.py b/onnxscript/rewriter/broadcast_to_matmul.py index da12ae3ad..3ae5562cd 100644 --- a/onnxscript/rewriter/broadcast_to_matmul.py +++ b/onnxscript/rewriter/broadcast_to_matmul.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/broadcast_to_matmul_test.py b/onnxscript/rewriter/broadcast_to_matmul_test.py index 4f7aecae8..49c97d2c7 100644 --- a/onnxscript/rewriter/broadcast_to_matmul_test.py +++ b/onnxscript/rewriter/broadcast_to_matmul_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import unittest diff --git a/onnxscript/rewriter/cast_constant_of_shape.py b/onnxscript/rewriter/cast_constant_of_shape.py index a13da7c27..bd58af933 100644 --- a/onnxscript/rewriter/cast_constant_of_shape.py +++ b/onnxscript/rewriter/cast_constant_of_shape.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/cast_constant_of_shape_test.py b/onnxscript/rewriter/cast_constant_of_shape_test.py index c16ac082d..35151e17d 100644 --- a/onnxscript/rewriter/cast_constant_of_shape_test.py +++ b/onnxscript/rewriter/cast_constant_of_shape_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx.checker diff --git a/onnxscript/rewriter/erfgelu.py b/onnxscript/rewriter/erfgelu.py index 516cefbcb..ea8d27a4e 100644 --- a/onnxscript/rewriter/erfgelu.py +++ b/onnxscript/rewriter/erfgelu.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import math from onnxscript.rewriter import pattern diff --git a/onnxscript/rewriter/function_rule.py b/onnxscript/rewriter/function_rule.py index b9272dffd..c19229b81 100644 --- a/onnxscript/rewriter/function_rule.py +++ b/onnxscript/rewriter/function_rule.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import functools diff --git a/onnxscript/rewriter/gemm_to_matmul_add.py b/onnxscript/rewriter/gemm_to_matmul_add.py index 21ba82177..0b9ee373b 100644 --- a/onnxscript/rewriter/gemm_to_matmul_add.py +++ b/onnxscript/rewriter/gemm_to_matmul_add.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript.rewriter import pattern from onnxscript.rewriter.broadcast_to_matmul import check_if_not_need_reshape diff --git a/onnxscript/rewriter/gemm_to_matmul_add_test.py b/onnxscript/rewriter/gemm_to_matmul_add_test.py index cb285036b..aab56cc3f 100644 --- a/onnxscript/rewriter/gemm_to_matmul_add_test.py +++ b/onnxscript/rewriter/gemm_to_matmul_add_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx.parser diff --git a/onnxscript/rewriter/generic_pattern.py b/onnxscript/rewriter/generic_pattern.py index 1fad112bd..71d650e1b 100644 --- a/onnxscript/rewriter/generic_pattern.py +++ b/onnxscript/rewriter/generic_pattern.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import collections @@ -592,7 +594,7 @@ def match( self._debug["iteration"] = iteration if iteration >= max_iter and stack: - self._hint("reached {iteration}>={max_iter} iterations") + self._hint(f"reached {iteration}>={max_iter} iterations") return self.none(node, inspect.currentframe().f_lineno) if self.verbose > 5: diff --git a/onnxscript/rewriter/generic_pattern_test.py b/onnxscript/rewriter/generic_pattern_test.py index c96aa37d9..174468cda 100644 --- a/onnxscript/rewriter/generic_pattern_test.py +++ b/onnxscript/rewriter/generic_pattern_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import contextlib @@ -257,7 +259,7 @@ def match_pattern(op, x, pos_ids, axis): matmul = op.MatMul(pos_ids, cast) transpose = op.Transpose(matmul) - output, length = op.ConcatTraining( + output, _length = op.ConcatTraining( transpose, transpose, domain="com.microsoft", @@ -329,7 +331,7 @@ def rotary_match_pattern(op, x, pos_ids, axis): matmul = op.MatMul(pos_ids, cast) transpose = op.Transpose(matmul) - output, length = op.ConcatTraining( + output, _length = op.ConcatTraining( transpose, transpose, domain="com.microsoft", outputs=2 ) @@ -394,7 +396,7 @@ def rotary_match_pattern(op, x, pos_ids, axis): matmul = op.MatMul(pos_ids, cast) transpose = op.Transpose(matmul) - output, length = op.ConcatTraining( + output, _length = op.ConcatTraining( transpose, transpose, domain="com.microsoft", outputs=2 ) diff --git a/onnxscript/rewriter/llama_rule_sets.py b/onnxscript/rewriter/llama_rule_sets.py index 72a64a9ff..f6a347773 100644 --- a/onnxscript/rewriter/llama_rule_sets.py +++ b/onnxscript/rewriter/llama_rule_sets.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import onnxscript.ir as ir diff --git a/onnxscript/rewriter/llama_rule_sets_test.py b/onnxscript/rewriter/llama_rule_sets_test.py index 0491d69a0..1fe6c31c4 100644 --- a/onnxscript/rewriter/llama_rule_sets_test.py +++ b/onnxscript/rewriter/llama_rule_sets_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import unittest diff --git a/onnxscript/rewriter/no_op.py b/onnxscript/rewriter/no_op.py index 5ba828a8d..95c3e2434 100644 --- a/onnxscript/rewriter/no_op.py +++ b/onnxscript/rewriter/no_op.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from onnxscript.rewriter import pattern op = pattern.onnxop diff --git a/onnxscript/rewriter/no_op_test.py b/onnxscript/rewriter/no_op_test.py index 1cc1a47cf..92172ec1f 100644 --- a/onnxscript/rewriter/no_op_test.py +++ b/onnxscript/rewriter/no_op_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx.parser diff --git a/onnxscript/rewriter/onnxruntime/__init__.py b/onnxscript/rewriter/onnxruntime/__init__.py index 4a8ffa61b..2c72aec43 100644 --- a/onnxscript/rewriter/onnxruntime/__init__.py +++ b/onnxscript/rewriter/onnxruntime/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import onnx diff --git a/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter.py b/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter.py index 16d8838f7..1d5136f9f 100644 --- a/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter.py +++ b/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import logging from onnxscript import ir diff --git a/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter_test.py b/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter_test.py index 8effd0b28..b9666fba3 100644 --- a/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter_test.py +++ b/onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import numpy as np diff --git a/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu.py b/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu.py index b3d81d6f1..843ad920b 100644 --- a/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu.py +++ b/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu_test.py b/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu_test.py index ced611685..6b4741d95 100644 --- a/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu_test.py +++ b/onnxscript/rewriter/onnxruntime/group_normalization_merge_silu_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import numpy as np diff --git a/onnxscript/rewriter/onnxruntime/instance_to_group_normalization.py b/onnxscript/rewriter/onnxruntime/instance_to_group_normalization.py index 559033a7c..bcd7c2d38 100644 --- a/onnxscript/rewriter/onnxruntime/instance_to_group_normalization.py +++ b/onnxscript/rewriter/onnxruntime/instance_to_group_normalization.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/onnxruntime/instance_to_group_normalization_test.py b/onnxscript/rewriter/onnxruntime/instance_to_group_normalization_test.py index 991a3d44a..81a20a984 100644 --- a/onnxscript/rewriter/onnxruntime/instance_to_group_normalization_test.py +++ b/onnxscript/rewriter/onnxruntime/instance_to_group_normalization_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import numpy as np diff --git a/onnxscript/rewriter/onnxruntime/softmax.py b/onnxscript/rewriter/onnxruntime/softmax.py index 63a7fda8f..12ad97672 100644 --- a/onnxscript/rewriter/onnxruntime/softmax.py +++ b/onnxscript/rewriter/onnxruntime/softmax.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/onnxruntime/softmax_test.py b/onnxscript/rewriter/onnxruntime/softmax_test.py index 8c26adbe0..f2aa37c1f 100644 --- a/onnxscript/rewriter/onnxruntime/softmax_test.py +++ b/onnxscript/rewriter/onnxruntime/softmax_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import onnx.parser diff --git a/onnxscript/rewriter/onnxruntime/transformers/__init__.py b/onnxscript/rewriter/onnxruntime/transformers/__init__.py index 84c73d7b7..be0085ae0 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/__init__.py +++ b/onnxscript/rewriter/onnxruntime/transformers/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations from onnxscript.rewriter import function_rule diff --git a/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu.py b/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu.py index 591527b59..b63eb0cce 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu.py +++ b/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu_test.py b/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu_test.py index 196367c00..0812ae3d3 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu_test.py +++ b/onnxscript/rewriter/onnxruntime/transformers/biassplitgelu_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import unittest diff --git a/onnxscript/rewriter/onnxruntime/transformers/fastgelu.py b/onnxscript/rewriter/onnxruntime/transformers/fastgelu.py index b852401f9..b0967c7ed 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/fastgelu.py +++ b/onnxscript/rewriter/onnxruntime/transformers/fastgelu.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/onnxruntime/transformers/fastgelu_test.py b/onnxscript/rewriter/onnxruntime/transformers/fastgelu_test.py index db26adf28..e6de540b8 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/fastgelu_test.py +++ b/onnxscript/rewriter/onnxruntime/transformers/fastgelu_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import unittest diff --git a/onnxscript/rewriter/onnxruntime/transformers/layernorm.py b/onnxscript/rewriter/onnxruntime/transformers/layernorm.py index d6e5fe1d5..edbfa4e02 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/layernorm.py +++ b/onnxscript/rewriter/onnxruntime/transformers/layernorm.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import logging diff --git a/onnxscript/rewriter/onnxruntime/transformers/layernorm_test.py b/onnxscript/rewriter/onnxruntime/transformers/layernorm_test.py index f4f494aa1..c47c77ee7 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/layernorm_test.py +++ b/onnxscript/rewriter/onnxruntime/transformers/layernorm_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import unittest diff --git a/onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py b/onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py index 1ed949d4b..85053479f 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py +++ b/onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. r"""POC experimenting function aware pattern re-write. In this case we don't want to spell-out the entire source pattern. diff --git a/onnxscript/rewriter/onnxruntime/transformers/multihead_attention_test.py b/onnxscript/rewriter/onnxruntime/transformers/multihead_attention_test.py index 1e2f1d51c..f752a00a7 100644 --- a/onnxscript/rewriter/onnxruntime/transformers/multihead_attention_test.py +++ b/onnxscript/rewriter/onnxruntime/transformers/multihead_attention_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import unittest diff --git a/onnxscript/rewriter/pattern.py b/onnxscript/rewriter/pattern.py index 337e9cd43..7a48b0629 100644 --- a/onnxscript/rewriter/pattern.py +++ b/onnxscript/rewriter/pattern.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import abc diff --git a/onnxscript/rewriter/pattern_test.py b/onnxscript/rewriter/pattern_test.py index fde2c3b06..e35699621 100644 --- a/onnxscript/rewriter/pattern_test.py +++ b/onnxscript/rewriter/pattern_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import contextlib import io import logging diff --git a/onnxscript/sourceinfo.py b/onnxscript/sourceinfo.py index 1e02551f2..b1e19eff7 100644 --- a/onnxscript/sourceinfo.py +++ b/onnxscript/sourceinfo.py @@ -33,7 +33,7 @@ def msg(self, error_message: str) -> str: if self.function_name: source_loc = f"Function '{self.function_name}', line {lineno}" else: - source_loc = "Line {lineno}" + source_loc = f"Line {lineno}" if self.code: lines = self.code.split("\n") diff --git a/onnxscript/tensor.py b/onnxscript/tensor.py index 9acb80467..21ca3c4a6 100644 --- a/onnxscript/tensor.py +++ b/onnxscript/tensor.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations diff --git a/onnxscript/tensor_test.py b/onnxscript/tensor_test.py index e81d01472..afe490e8d 100644 --- a/onnxscript/tensor_test.py +++ b/onnxscript/tensor_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Unit tests for the tensor module.""" import unittest diff --git a/onnxscript/testing/__init__.py b/onnxscript/testing/__init__.py index bacfe9777..c731f6e95 100644 --- a/onnxscript/testing/__init__.py +++ b/onnxscript/testing/__init__.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations __all__ = [ diff --git a/onnxscript/type_annotation.py b/onnxscript/type_annotation.py index 53b640ab7..b47e34cfa 100644 --- a/onnxscript/type_annotation.py +++ b/onnxscript/type_annotation.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import collections diff --git a/onnxscript/type_annotation_test.py b/onnxscript/type_annotation_test.py index 18728ae76..4104eb51d 100644 --- a/onnxscript/type_annotation_test.py +++ b/onnxscript/type_annotation_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest from typing import Any, List, Optional, Sequence, TypeVar, Union diff --git a/onnxscript/utils/evaluation_utils.py b/onnxscript/utils/evaluation_utils.py index eb93b79cb..b981fe670 100644 --- a/onnxscript/utils/evaluation_utils.py +++ b/onnxscript/utils/evaluation_utils.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import pathlib diff --git a/onnxscript/utils/timing_utils.py b/onnxscript/utils/timing_utils.py index 6805a7e19..98c48dc6d 100644 --- a/onnxscript/utils/timing_utils.py +++ b/onnxscript/utils/timing_utils.py @@ -1,18 +1,18 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import time import onnx from onnxscript import optimizer -# from onnxscript.rewriter.rules import all_rules - def timeit(f, message): def timed(*args, **kw): ts = time.time() result = f(*args, **kw) te = time.time() - print(f"{message} time: {te-ts}") + print(f"{message} time: {te - ts}") return result return timed diff --git a/onnxscript/utils/utils.py b/onnxscript/utils/utils.py index 26ef525b1..39457e7ab 100644 --- a/onnxscript/utils/utils.py +++ b/onnxscript/utils/utils.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations from typing import Any diff --git a/onnxscript/values.py b/onnxscript/values.py index fc4846b5d..8e36cdfa2 100644 --- a/onnxscript/values.py +++ b/onnxscript/values.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import dataclasses diff --git a/onnxscript/values_test.py b/onnxscript/values_test.py index f5d08ad72..c33e62333 100644 --- a/onnxscript/values_test.py +++ b/onnxscript/values_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import inspect diff --git a/opgen/onnx_opset_builder.py b/opgen/onnx_opset_builder.py index 8e528d5c1..41b926940 100644 --- a/opgen/onnx_opset_builder.py +++ b/opgen/onnx_opset_builder.py @@ -346,7 +346,7 @@ def constraint_is_compatible( for existing_constraints in input_constraints, output_constraints: if (existing := existing_constraints.get(constraint_name, None)) is not None: if len(existing) != len(constraint_types): - return False # differing number of constraints, can't be compatible + return False # differing number of constraints, can't be compatible for a, b in zip(existing, constraint_types): if str(a) != str(b): return False # a constrained type does not match diff --git a/opgen/pygen.py b/opgen/pygen.py index ffc412f9e..bea743118 100644 --- a/opgen/pygen.py +++ b/opgen/pygen.py @@ -367,7 +367,7 @@ def accept(self, visitor: Visitor): self._dispatch_visit(visitor.visit_constant) -class ExprList(Expr, Generic[TExpr], ABC): +class ExprList(Expr, ABC, Generic[TExpr]): class Roles: Elements = Role("ExprList.Elements") diff --git a/pyproject.toml b/pyproject.toml index e4431e536..26918c09e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -137,7 +137,10 @@ disable = [ convention = "google" [tool.ruff] +line-length = 95 target-version = "py38" + +[tool.ruff.lint] select = [ "B", # flake8-bugbear "C4", # flake8-comprehensions @@ -163,7 +166,13 @@ select = [ "W", # pycodestyle "YTT", # flake8-2020 ] +# Select preview rules +preview = true +extend-select = [ + "CPY001", # Copyright header +] ignore = [ + "B9", # Opinionated bugbear rules "C408", # Sometimes it is preferable when we construct kwargs "D1", # D1 is for missing docstrings, which is not yet enforced. "D202", # D202 Too strict. "No blank lines allowed after function docstring" @@ -172,7 +181,9 @@ ignore = [ "D400", "D401", # First line of docstring should be in imperative mood "D415", # D415 Not yet enforced. "First line should end with a period, question mark, or exclamation point" + "E1", "E2", "E3", # Pycodestyle formatting rules that conflicts with the formatter "E501", # Line length. Not enforced because black will handle formatting + "SIM103", # "Return the condition directly" obscures logic sometimes "N802", # Nxx: ONNX Script function sometimes use upper case for names. "N803", "N806", @@ -181,6 +192,7 @@ ignore = [ "PERF203", # try-except in loops sometimes necessary "PERF401", # List comprehension is not always readable "PYI041", # int | float is more clear + "RUF022", # We don't need to sort __all__ for elements to be grouped "SIM102", # Collapible if statements are not always more readable "SIM108", # We don't always encourage ternary operators "SIM114", # Don't always combine if branches for debugability @@ -189,21 +201,23 @@ ignore = [ "UP006", # keep-runtime-typing "UP007", # keep-runtime-typing ] -line-length = 95 ignore-init-module-imports = true [tool.ruff.lint.flake8-tidy-imports.banned-api] "pathlib".msg = "Using pathlib can impact performance. Use os.path instead" -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "__init__.py" = ["TID252"] # Allow relative imports in init files "setup.py" = ["TID251"] # pathlib is allowed in supporting code "**/{examples,tests,docs,tools,utils,opgen}/*" = ["TID251"] # pathlib is allowed in supporting code "**/*_test.py" = ["TID251"] # pathlib is allowed in tests -[tool.ruff.flake8-tidy-imports] +[tool.ruff.lint.flake8-tidy-imports] # Disallow all relative imports. ban-relative-imports = "all" -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "google" + +[tool.ruff.lint.flake8-copyright] +notice-rgx = "(?i)Copyright \\(c\\) Microsoft Corporation" diff --git a/setup.py b/setup.py index 32d496b7a..d63a39ab6 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """NOTE: Put all metadata in pyproject.toml. Do not include complex logic in setup.py.""" import datetime diff --git a/tests/__init__.py b/tests/__init__.py index 862c45ce3..59e481eb9 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,2 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- diff --git a/tests/common/__init__.py b/tests/common/__init__.py index 4c5748064..8099de9f1 100644 --- a/tests/common/__init__.py +++ b/tests/common/__init__.py @@ -1 +1,3 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Shared components for testing.""" diff --git a/tests/common/onnx_script_test_case.py b/tests/common/onnx_script_test_case.py index 85f5431d2..3a46a870a 100644 --- a/tests/common/onnx_script_test_case.py +++ b/tests/common/onnx_script_test_case.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import copy diff --git a/tests/common/testutils.py b/tests/common/testutils.py index c0dafbff1..2ea566646 100644 --- a/tests/common/testutils.py +++ b/tests/common/testutils.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations import functools diff --git a/tests/eager_mode_test.py b/tests/eager_mode_test.py index b8ea940da..566169f22 100644 --- a/tests/eager_mode_test.py +++ b/tests/eager_mode_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest diff --git a/tests/eager_test.py b/tests/eager_test.py index ffed8be5f..a39a455f3 100644 --- a/tests/eager_test.py +++ b/tests/eager_test.py @@ -1,11 +1,12 @@ -# SPDX-License-Identifier: Apache-2.0 -# pylint: disable=import-outside-toplevel +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import itertools import unittest import numpy as np import parameterized +import torch from tests.common import onnx_script_test_case from tests.models import signal_dft @@ -82,10 +83,6 @@ def _stft( onesided=False, hop_length=None, ): - try: - import torch - except ImportError as e: - raise ImportError("torch is not installed.") from e ft = torch.stft( torch.from_numpy(x), n_fft=fft_length, diff --git a/tests/external_tensor_test.py b/tests/external_tensor_test.py index d908ba6cf..f12e5720c 100644 --- a/tests/external_tensor_test.py +++ b/tests/external_tensor_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import os import tempfile import unittest diff --git a/tests/function_libs/torch_lib/error_reproduction.py b/tests/function_libs/torch_lib/error_reproduction.py index 544866646..141946c56 100644 --- a/tests/function_libs/torch_lib/error_reproduction.py +++ b/tests/function_libs/torch_lib/error_reproduction.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import difflib diff --git a/tests/function_libs/torch_lib/extra_opinfo.py b/tests/function_libs/torch_lib/extra_opinfo.py index 8c935c72e..de67909e2 100644 --- a/tests/function_libs/torch_lib/extra_opinfo.py +++ b/tests/function_libs/torch_lib/extra_opinfo.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """ Test data for aten operators which don't exist in PyTorch file: pytorch/torch/testing/_internal/common_methods_invocations.py. diff --git a/tests/function_libs/torch_lib/ops_test.py b/tests/function_libs/torch_lib/ops_test.py index cf29a8b80..f12f9024e 100644 --- a/tests/function_libs/torch_lib/ops_test.py +++ b/tests/function_libs/torch_lib/ops_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Test op correctness by comparing with PyTorch results. Usage: diff --git a/tests/function_libs/torch_lib/ops_test_common.py b/tests/function_libs/torch_lib/ops_test_common.py index ae0578abd..2064c8b87 100644 --- a/tests/function_libs/torch_lib/ops_test_common.py +++ b/tests/function_libs/torch_lib/ops_test_common.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Common utils for testing operators.""" from __future__ import annotations diff --git a/tests/function_libs/torch_lib/ops_test_data.py b/tests/function_libs/torch_lib/ops_test_data.py index cff34897d..5aa78cc11 100644 --- a/tests/function_libs/torch_lib/ops_test_data.py +++ b/tests/function_libs/torch_lib/ops_test_data.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Test op correctness by comparing with PyTorch results. ## Usage diff --git a/tests/functions/gemmgelu.py b/tests/functions/gemmgelu.py index 026948858..32a326aab 100644 --- a/tests/functions/gemmgelu.py +++ b/tests/functions/gemmgelu.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript import script from onnxscript.onnx_opset import opset15 as op diff --git a/tests/functions/gemmgelu_test.py b/tests/functions/gemmgelu_test.py index c9ae89b75..6de6f131f 100644 --- a/tests/functions/gemmgelu_test.py +++ b/tests/functions/gemmgelu_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest diff --git a/tests/functions/if_test.py b/tests/functions/if_test.py index bc80179ca..0887b296f 100644 --- a/tests/functions/if_test.py +++ b/tests/functions/if_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest diff --git a/tests/functions/onnxfns1A_test.py b/tests/functions/onnxfns1A_test.py index 7f19ebaf7..36d12e4b4 100644 --- a/tests/functions/onnxfns1A_test.py +++ b/tests/functions/onnxfns1A_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import pytest diff --git a/tests/functions/onnxfns2_test.py b/tests/functions/onnxfns2_test.py index 3cf067dbd..ce1164357 100644 --- a/tests/functions/onnxfns2_test.py +++ b/tests/functions/onnxfns2_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest from tests.common import onnx_script_test_case diff --git a/tests/functions/onnxfns_test.py b/tests/functions/onnxfns_test.py index 105721459..1e9e10d30 100644 --- a/tests/functions/onnxfns_test.py +++ b/tests/functions/onnxfns_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest diff --git a/tests/functions/ort_custom_ops.py b/tests/functions/ort_custom_ops.py index 2ce6fa57e..1df3a0f10 100644 --- a/tests/functions/ort_custom_ops.py +++ b/tests/functions/ort_custom_ops.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import math from onnxscript import script diff --git a/tests/if_test.py b/tests/if_test.py index 346334c09..2a1e759b8 100644 --- a/tests/if_test.py +++ b/tests/if_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest diff --git a/tests/ir/graph_view_test.py b/tests/ir/graph_view_test.py index 699ce4c68..83a51cdaa 100644 --- a/tests/ir/graph_view_test.py +++ b/tests/ir/graph_view_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import pathlib import unittest diff --git a/tests/ir/public_api_test.py b/tests/ir/public_api_test.py index 1247db9e9..ac2655cf4 100644 --- a/tests/ir/public_api_test.py +++ b/tests/ir/public_api_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- # Adapted from # https://github.com/pytorch/pytorch/blob/b505e8647547f029d0f7df408ee5f2968f757f89/test/test_public_bindings.py#L523 # Original code PyTorch license https://github.com/pytorch/pytorch/blob/main/LICENSE diff --git a/tests/ir/serde_roundtrip_test.py b/tests/ir/serde_roundtrip_test.py index 250735005..ad4c8c923 100644 --- a/tests/ir/serde_roundtrip_test.py +++ b/tests/ir/serde_roundtrip_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import pathlib diff --git a/tests/loop_test.py b/tests/loop_test.py index 0be895c08..698457b9d 100644 --- a/tests/loop_test.py +++ b/tests/loop_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. import unittest import numpy as np diff --git a/tests/models/__init__.py b/tests/models/__init__.py index 862c45ce3..59e481eb9 100644 --- a/tests/models/__init__.py +++ b/tests/models/__init__.py @@ -1,4 +1,2 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- diff --git a/tests/models/attrref.py b/tests/models/attrref.py index 352b8f87e..c321229e9 100644 --- a/tests/models/attrref.py +++ b/tests/models/attrref.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript.onnx_opset import opset15 as op diff --git a/tests/models/cast_like.py b/tests/models/cast_like.py index 5f5380692..fa5b47a4f 100644 --- a/tests/models/cast_like.py +++ b/tests/models/cast_like.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- # Test cases for automatic introduction of CastLike around constants: diff --git a/tests/models/different_opset.py b/tests/models/different_opset.py index 737588478..62438d9f8 100644 --- a/tests/models/different_opset.py +++ b/tests/models/different_opset.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnx import TensorProto from onnx.helper import make_tensor diff --git a/tests/models/dropout.py b/tests/models/dropout.py index fc3ac96d2..b756d41b9 100644 --- a/tests/models/dropout.py +++ b/tests/models/dropout.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript.onnx_opset import opset15 as op diff --git a/tests/models/eager_op.py b/tests/models/eager_op.py index bc41a4f63..86c6c6d13 100644 --- a/tests/models/eager_op.py +++ b/tests/models/eager_op.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript import script diff --git a/tests/models/eg1.py b/tests/models/eg1.py index 13dd49f7f..09e09d2b4 100644 --- a/tests/models/eg1.py +++ b/tests/models/eg1.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript import opset15 as op from onnxscript.onnx_types import FLOAT diff --git a/tests/models/getitem.py b/tests/models/getitem.py index ae7da8270..091febbb9 100644 --- a/tests/models/getitem.py +++ b/tests/models/getitem.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from __future__ import annotations diff --git a/tests/models/graph_attr.py b/tests/models/graph_attr.py index 69eff59a1..f7ee36136 100644 --- a/tests/models/graph_attr.py +++ b/tests/models/graph_attr.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript import graph, script from onnxscript.onnx_opset import opset15 as op diff --git a/tests/models/identity.py b/tests/models/identity.py index fabd6dcca..18ab6e6f6 100644 --- a/tests/models/identity.py +++ b/tests/models/identity.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- # Test cases for automatic introduction of Identity (copy) diff --git a/tests/models/if_statement.py b/tests/models/if_statement.py index 2188ff41e..509dd1ca7 100644 --- a/tests/models/if_statement.py +++ b/tests/models/if_statement.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnx import TensorProto from onnx.helper import make_tensor diff --git a/tests/models/loops_break.py b/tests/models/loops_break.py index 77807c67c..b9cd4e6df 100644 --- a/tests/models/loops_break.py +++ b/tests/models/loops_break.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnx import TensorProto from onnx.helper import make_tensor diff --git a/tests/models/loops_while.py b/tests/models/loops_while.py index 724f56a16..93e2b98c7 100644 --- a/tests/models/loops_while.py +++ b/tests/models/loops_while.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnx import TensorProto from onnx.helper import make_tensor diff --git a/tests/models/m1.py b/tests/models/m1.py index 127e53a97..fe5e55838 100644 --- a/tests/models/m1.py +++ b/tests/models/m1.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript.onnx_opset import opset15 as op from onnxscript.onnx_types import FLOAT diff --git a/tests/models/multi.py b/tests/models/multi.py index d4f13793d..c79a77563 100644 --- a/tests/models/multi.py +++ b/tests/models/multi.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript.onnx_opset import opset15 as op from onnxscript.onnx_types import FLOAT diff --git a/tests/models/onnxfns1.py b/tests/models/onnxfns1.py index ae04e7077..84a2ba636 100644 --- a/tests/models/onnxfns1.py +++ b/tests/models/onnxfns1.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- # Features included: # Overloaded operators such as <=, +, / diff --git a/tests/models/onnxfns1A.py b/tests/models/onnxfns1A.py index 4a23aba35..14be3cbbb 100644 --- a/tests/models/onnxfns1A.py +++ b/tests/models/onnxfns1A.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- # Same functions as in onnxfns1.py, using autocast and default-attribute-values diff --git a/tests/models/onnxfns2.py b/tests/models/onnxfns2.py index 84ea9d53c..3ab5a64e3 100644 --- a/tests/models/onnxfns2.py +++ b/tests/models/onnxfns2.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript import script from onnxscript.onnx_opset import opset15 as op diff --git a/tests/models/renaming.py b/tests/models/renaming.py index 1bc28bbf9..4f99be8da 100644 --- a/tests/models/renaming.py +++ b/tests/models/renaming.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript.onnx_opset import opset15 as op from onnxscript.onnx_types import FLOAT diff --git a/tests/models/sequences.py b/tests/models/sequences.py index 8b41c7c63..4039add08 100644 --- a/tests/models/sequences.py +++ b/tests/models/sequences.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript import script from onnxscript.onnx_opset import opset15 as op diff --git a/tests/models/subfunction.py b/tests/models/subfunction.py index 2e30e8cde..b1e4bbe7b 100644 --- a/tests/models/subfunction.py +++ b/tests/models/subfunction.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnxscript import script from onnxscript.onnx_opset import opset15 as op diff --git a/tests/models/type_double.py b/tests/models/type_double.py index 6fd62e4d8..eee03b30b 100644 --- a/tests/models/type_double.py +++ b/tests/models/type_double.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- from onnx import TensorProto from onnx.helper import make_tensor diff --git a/tests/operator_test.py b/tests/operator_test.py index e88026a10..8ff193ce4 100644 --- a/tests/operator_test.py +++ b/tests/operator_test.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- import unittest diff --git a/tests/optimizer/test_models.py b/tests/optimizer/test_models.py index ce78a8ac3..679898ed0 100644 --- a/tests/optimizer/test_models.py +++ b/tests/optimizer/test_models.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. from __future__ import annotations import pathlib diff --git a/tools/diagnostics/gen_diagnostics.py b/tools/diagnostics/gen_diagnostics.py index b30b44d6e..d54449df4 100644 --- a/tools/diagnostics/gen_diagnostics.py +++ b/tools/diagnostics/gen_diagnostics.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Generates PyTorch ONNX Export Diagnostic rules for C++, Python and documentations. The rules are defined in torch/onnx/_internal/diagnostics/rules.yaml. diff --git a/tools/function_rewriter_testing/function_unittest_producer.py b/tools/function_rewriter_testing/function_unittest_producer.py index cf1b54cf6..fc94adaa0 100644 --- a/tools/function_rewriter_testing/function_unittest_producer.py +++ b/tools/function_rewriter_testing/function_unittest_producer.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Fuction fusion unittest producer. Takes in a full model, function keyword, and example inputs, produces unit model protos diff --git a/tools/ir/model_zoo_test/model_zoo_test.py b/tools/ir/model_zoo_test/model_zoo_test.py index de3410a49..d4d55310b 100644 --- a/tools/ir/model_zoo_test/model_zoo_test.py +++ b/tools/ir/model_zoo_test/model_zoo_test.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Test IR roundtrip with ONNX model zoo. Usage: diff --git a/tools/onnx2script.py b/tools/onnx2script.py index 24556e755..02b220799 100644 --- a/tools/onnx2script.py +++ b/tools/onnx2script.py @@ -1,7 +1,5 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -------------------------------------------------------------------------- """ onnx2script.py diff --git a/tools/ort_rewriter_profiling/bench_model.py b/tools/ort_rewriter_profiling/bench_model.py index 14402da31..082e95143 100644 --- a/tools/ort_rewriter_profiling/bench_model.py +++ b/tools/ort_rewriter_profiling/bench_model.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Lite benchmark script comparing perf between different onnx model of the same torch model. Folders are expected to be in the following format: diff --git a/tools/ort_rewriter_profiling/nsys_profile.py b/tools/ort_rewriter_profiling/nsys_profile.py index 98d463ed3..86b27726d 100644 --- a/tools/ort_rewriter_profiling/nsys_profile.py +++ b/tools/ort_rewriter_profiling/nsys_profile.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """This script is an e2e tool to start a model run and profile the run. It parses the analysis produced by onnxruntime/nsys profiling and prints out the result. diff --git a/tools/ort_rewriter_profiling/ort_rewrite.py b/tools/ort_rewriter_profiling/ort_rewrite.py index 3fe1e5424..b92681ecd 100644 --- a/tools/ort_rewriter_profiling/ort_rewrite.py +++ b/tools/ort_rewriter_profiling/ort_rewrite.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """Runs onnxruntime rewriter to optimize on the given onnx model. Input: diff --git a/tools/ort_rewriter_profiling/profile_analysis.py b/tools/ort_rewriter_profiling/profile_analysis.py index 47a9c3cb0..3c79a3414 100644 --- a/tools/ort_rewriter_profiling/profile_analysis.py +++ b/tools/ort_rewriter_profiling/profile_analysis.py @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. """This script analyzes the profile file generated by onnxruntime/nsys profiling. It creates an in memory report of the per operator duration profile and prints it out. @@ -135,7 +137,7 @@ def _construct_tabulate_dict( comp_compiler_perf_header: comp_perf, } - ## Every op type + # Every op type tabulate_data = sorted( [ _construct_tabulate_dict( @@ -230,10 +232,10 @@ def compare_node_reports( base_report: ModelProfile, comp_report: ModelProfile, ): - ## Every op type + # Every op type print(tabulate_diff(base_report, comp_report)) - ## Matmul family + Add + # Matmul family + Add matmul_core_op_types = { "MatMul", "Gemm",