Skip to content

Commit ba01769

Browse files
Copilotgramalingamjustinchuby
authored
Move converter implementation files to _internal folder (#2738)
## Plan to Move Implementation Files to _internal - [x] Analyze current imports and dependencies - [x] Move implementation files to _internal: - [x] Move converter.py to _internal/converter.py - [x] Move evaluator.py to _internal/evaluator.py - [x] Move irbuilder.py to _internal/irbuilder.py - [x] Move main.py to _internal/main.py - [x] Move type_annotation.py to _internal/type_annotation.py - [x] Move values.py to _internal/values.py - [x] Move corresponding test files to _internal: - [x] Move converter_test.py to _internal/converter_test.py - [x] Move evaluator_test.py to _internal/evaluator_test.py - [x] Move type_annotation_test.py to _internal/type_annotation_test.py - [x] Move values_test.py to _internal/values_test.py - [x] Update __init__.py to import and re-export public API: - [x] Export script, graph, export_onnx_lib from main.py - [x] Export OnnxFunction, TracedOnnxFunction from values.py - [x] Create public API shim files: - [x] Create values.py shim - [x] Create evaluator.py shim (removed * import, added explicit exports) - [x] Update all internal imports in moved files to use _internal - [x] Update lintrunner configuration - [x] Run lintrunner to ensure code style compliance - [x] Run tests to verify everything works ## Summary Successfully moved all implementation files (converter.py, evaluator.py, irbuilder.py, main.py, type_annotation.py, values.py) and their corresponding test files to the `_internal` folder. ### Key Changes: 1. **Moved files to _internal**: All implementation files now reside in `onnxscript/_internal/` 2. **Created public API shims where needed**: Only `values.py` and `evaluator.py` shims remain in the main `onnxscript/` directory to re-export the public API from `_internal` 3. **Maintained backward compatibility**: All existing import patterns continue to work 4. **Updated internal cross-references**: All imports within moved files now reference `_internal` modules 5. **Updated lintrunner config**: Modified `.lintrunner.toml` to point to new file locations 6. **Removed * imports**: Replaced wildcard import with explicit exports in evaluator.py 7. **Simplified API surface**: Removed unnecessary `main.py` and `type_annotation.py` shims ### Public API Exports: - **onnxscript** (main module): script, graph, export_onnx_lib (imported directly from `_internal.main` via `__init__.py`) - **onnxscript.evaluator**: Evaluator, OnnxReferenceRuntimeEvaluator, ORTEvaluator, ORTMixedEvaluator, default, default_as - **onnxscript.values**: Opset, Op, OnnxFunction, TracedOnnxFunction, and other value types ### Import Patterns: Users should now import as follows: - `from onnxscript import script, graph, export_onnx_lib` (recommended) - `from onnxscript.values import Opset, Op` (still supported for backward compatibility) - `from onnxscript.evaluator import Evaluator, default_as` (still supported for backward compatibility) Internal code can access type_annotation utilities via `from onnxscript._internal import type_annotation`. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Make implementation files internal (private)</issue_title> > <issue_description>The implementation files for the onnxscript converter should be moved into the _internal folder to clarify that these are not public and that users should not take a dependence on the implementation details. > > This likely includes files such as converter.py, evaluator.py, irbuilder.py, main.py, type_annotation.py, and values.py, along with corresponding test files. > > The main types intended to be made public should be imported from these files and made public by the init.py file.</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #2737 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: gramalingam <[email protected]> Co-authored-by: justinchuby <[email protected]> Co-authored-by: Justin Chu <[email protected]>
1 parent 20a99d1 commit ba01769

18 files changed

+1613
-1540
lines changed

.lintrunner.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ exclude_patterns = [
4040
'tests/**', # Skip linting test files for speed
4141
# FIXME: Fix typing annotations in these files
4242
'examples/custom_op_expansion.py',
43-
'onnxscript/converter_test.py',
44-
'onnxscript/converter.py',
45-
'onnxscript/evaluator_test.py',
46-
'onnxscript/evaluator.py',
43+
'onnxscript/_internal/converter_test.py',
44+
'onnxscript/_internal/converter.py',
45+
'onnxscript/_internal/evaluator_test.py',
46+
'onnxscript/_internal/evaluator.py',
4747
'onnxscript/onnx_types.py',
4848
'onnxscript/**/*_test.py', # Skip linting test files for speed
4949
'onnxscript/function_libs/torch_lib/ops/**', # Operators typing do not play well with mypy
@@ -114,14 +114,14 @@ include_patterns = [
114114
'**/*.py',
115115
]
116116
exclude_patterns = [
117-
'examples/**',
118117
'docs/**',
119-
'onnxscript/converter_test.py',
118+
'examples/**',
119+
'onnxscript/_internal/converter_test.py',
120+
'onnxscript/optimizer/**', # FIXME
121+
'onnxscript/rewriter/**', # FIXME
120122
'tests/functions/**',
121123
'tests/models/**',
122124
'tests/onnx_backend_test_code/**',
123-
'onnxscript/optimizer/**', # FIXME
124-
'onnxscript/rewriter/**', # FIXME
125125
]
126126
command = [
127127
'python',

onnxscript/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666

6767
import importlib.metadata
6868

69+
from ._internal.main import export_onnx_lib, graph, script
6970
from .backend.onnx_export import export2python as proto2python
70-
from .main import export_onnx_lib, graph, script
7171

7272
# isort: off
7373
from .onnx_opset import (
@@ -128,7 +128,7 @@
128128

129129
from . import ir, optimizer, rewriter, version_converter
130130
from ._internal.utils import external_tensor
131-
from .values import OnnxFunction, TracedOnnxFunction
131+
from ._internal.values import OnnxFunction, TracedOnnxFunction
132132

133133
# Set DEBUG to True to enable additional debug checks
134134
DEBUG: bool = False

onnxscript/_internal/autocast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from onnxscript import ir, tensor
1414

1515
if TYPE_CHECKING:
16-
from onnxscript import converter
16+
from onnxscript._internal import converter
1717

1818
# Conversions from python values to ONNX are used by both the script converter as well
1919
# as the eager-mode runtime and both need to be consistent. The script converter converts
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020
import onnx_ir as ir
2121

2222
import onnxscript
23-
from onnxscript import irbuilder, onnx_types, sourceinfo, values
24-
from onnxscript import type_annotation as ta
25-
from onnxscript._internal import analysis, ast_utils, autocast, param_manipulation
23+
from onnxscript import onnx_types, sourceinfo
24+
from onnxscript._internal import (
25+
analysis,
26+
ast_utils,
27+
autocast,
28+
irbuilder,
29+
param_manipulation,
30+
values,
31+
)
32+
from onnxscript._internal import (
33+
type_annotation as ta,
34+
)
2635

2736
logger = logging.getLogger("onnxscript")
2837

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
import onnxscript
2525
import onnxscript.testing
26-
from onnxscript import BOOL, FLOAT, INT64, converter, graph, script, tensor
26+
from onnxscript import BOOL, FLOAT, INT64, graph, script, tensor
27+
from onnxscript._internal import converter
2728
from onnxscript.onnx_opset import opset11 as op11
2829
from onnxscript.onnx_opset import opset15 as op
2930
from tests.common import onnx_script_test_case, testutils

0 commit comments

Comments
 (0)