Repository: microsoft/onnxscript

Issue:
Test with tox
Test with tox


Discussion:

Resolving patch:
diff --git a/onnxscript/backend/onnx_export.py b/onnxscript/backend/onnx_export.py
--- a/onnxscript/backend/onnx_export.py
+++ b/onnxscript/backend/onnx_export.py
@@ -427,9 +427,6 @@ def export_template(
     Returns:
         python code
     """
-    # delayed import to avoid raising an exception if not installed.
-    import autopep8  # pylint: disable=import-outside-toplevel
-
     # unique_function_domain_version
     unique_function_domain_version = set()
     if hasattr(model_onnx, "functions"):
@@ -521,6 +518,9 @@ def rename_variable(name):
     if "\nreturn" in final:
         raise SyntaxError(f"The produced code is wrong.\n{final}")
     if clean_code:
+        # delayed import to avoid raising an exception if not installed.
+        import autopep8  # pylint: disable=import-outside-toplevel
+
         cleaned_code = autopep8.fix_code(final, options=autopep_options)
         if "\nreturn" in cleaned_code:
             raise SyntaxError(f"The cleaned code is wrong.\n{final}\n------{cleaned_code}")
diff --git a/onnxscript/function_libs/torch_aten/ops/core.py b/onnxscript/function_libs/torch_aten/ops/core.py
--- a/onnxscript/function_libs/torch_aten/ops/core.py
+++ b/onnxscript/function_libs/torch_aten/ops/core.py
@@ -735,6 +735,9 @@ def aten_cat(tensors: Sequence[TTensor], dim: int = 0) -> TTensor:
     num_of_input = len(tensors)  # len() function not support yet
     a = op.SequenceEmpty()
     for i in range(num_of_input):
+        if op.Size(tensors[i]) == 0 and dim != 0:
+            # Skip empty tensors when concatenating along non-zero dimension
+            continue
         a = op.SequenceInsert(a, tensors[i])
     return op.ConcatFromSequence(a, axis=dim)
 


Test patch:
diff --git a/onnxscript/test/function_libs/torch_aten/ops_correctness_test.py b/onnxscript/test/function_libs/torch_aten/ops_correctness_test.py
--- a/onnxscript/test/function_libs/torch_aten/ops_correctness_test.py
+++ b/onnxscript/test/function_libs/torch_aten/ops_correctness_test.py
@@ -9,6 +9,7 @@
 
 import numpy as np
 import onnx
+import packaging.version
 import torch
 from torch.testing._internal import common_device_type, common_methods_invocations
 from torch.testing._internal.opinfo import core as opinfo_core
@@ -148,9 +149,15 @@ def wrapped(fn):
 def duplicate_opinfo(opinfos: list[opinfo_core.OpInfo], name: str, new_names: tuple[str, ...]):
     """Duplicate an opinfo in the opinfo database and give it a new name."""
     duplicated = []
+    all_info_names = {opinfo.name for opinfo in opinfos}
     for opinfo in opinfos:
         if opinfo.name == name:
             for new_name in new_names:
+                if new_name in all_info_names:
+                    # NOTE: Avoid duplicating an opinfo that already exists in the database.
+                    # New opinfos are expected to be added in torch-nightly.
+                    warnings.warn(f"OpInfo {new_name} already exists in the database.")
+                    continue
                 new_opinfo = copy.deepcopy(opinfo)
                 new_opinfo.name = new_name
                 duplicated.append(new_opinfo)
@@ -187,7 +194,8 @@ def _full_input_wrangler(
     args: list[Any], kwargs: dict[str, Any]
 ) -> tuple[list[Any], dict[str, Any]]:
     # Remove the self argument
-    args.pop(0)
+    if packaging.version.parse(torch.__version__) <= packaging.version.parse("1.13.1"):
+        args.pop(0)
     return args, kwargs