Skip to content

Commit

Permalink
Remove proto2text | chore! (#1193)
Browse files Browse the repository at this point in the history
Remove proto2text because it is simply an alias of
`onnx.printer.to_text`.

---------

Co-authored-by: Ti-Tai Wang <titaiwang@microsoft.com>
  • Loading branch information
justinchuby and titaiwangms authored Nov 30, 2023
1 parent 82d2063 commit e35a179
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 44 deletions.
1 change: 0 additions & 1 deletion .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ include_patterns = [
'**/*.pyi',
]
exclude_patterns = [
'docs/**',
'onnxscript/tests/models/**',
]
command = [
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ pytest onnxscript
import onnx

# We use ONNX opset 15 to define the function below.
from onnxscript import FLOAT
from onnxscript import FLOAT, script
from onnxscript import opset15 as op
from onnxscript import script


# We use the script decorator to indicate that
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/01_plot_selu.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def Selu(X, alpha: float, gamma: float):

# %%
# Let's see what the translated function looks like:
from onnxscript import proto2text # noqa: E402
import onnx # noqa: E402

print(proto2text(onnx_fun))
print(onnx.printer.to_text(onnx_fun))
5 changes: 2 additions & 3 deletions docs/examples/02_plot_square_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import onnx
from onnxruntime import InferenceSession

from onnxscript import FLOAT
from onnxscript import FLOAT, script
from onnxscript import opset15 as op
from onnxscript import proto2text, script


@script()
Expand All @@ -32,7 +31,7 @@ def square_loss(X: FLOAT["N", 1], Y: FLOAT["N", 1]) -> FLOAT[1, 1]: # noqa: F82

# %%
# Let's see what the generated model looks like.
print(proto2text(model))
print(onnx.printer.to_text(model))

# %%
# We can run shape-inference and type-check the model using the standard ONNX API.
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/03_export_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
**This is preliminary. Proto extensions are required to fully support LibProto.**
"""

from onnxscript import export_onnx_lib
from onnxscript import export_onnx_lib, script
from onnxscript import opset15 as op
from onnxscript import script
from onnxscript.values import Opset

# %%
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/04_plot_eager_mode_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
"""
import numpy as np

from onnxscript import FLOAT
from onnxscript import FLOAT, script
from onnxscript import opset15 as op
from onnxscript import script


@script()
Expand Down
7 changes: 4 additions & 3 deletions docs/examples/05_plot_model_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# %%
# First, we define the implementation of a square-loss function in onnxscript.

from onnxscript import FLOAT
import onnx

from onnxscript import FLOAT, script
from onnxscript import opset15 as op
from onnxscript import proto2text, script


@script(ir_version=7, producer_name="OnnxScript", producer_version="0.1")
Expand All @@ -29,4 +30,4 @@ def square_loss(X: FLOAT["N"], Y: FLOAT["N"]) -> FLOAT[1]: # noqa: F821
# %%
# Let's see what the generated model looks like.
model = square_loss.to_model_proto()
print(proto2text(model))
print(onnx.printer.to_text(model))
11 changes: 6 additions & 5 deletions docs/examples/06_plot_model_local_funs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# %%
# First, let us define an ONNXScript function that calls other ONNXScript functions.

from onnxscript import FLOAT
import onnx

from onnxscript import FLOAT, script
from onnxscript import opset15 as op
from onnxscript import proto2text, script
from onnxscript.values import Opset

# A dummy opset used for model-local functions
Expand All @@ -43,17 +44,17 @@ def l2norm(x: FLOAT["N"], y: FLOAT["N"]) -> FLOAT[1]: # noqa: F821
# Let's see what the generated model looks like by default:

model = l2norm.to_model_proto()
print(proto2text(model))
print(onnx.printer.to_text(model))

# %%
# Let's now explicitly specify which functions to include.
# First, generate a model with no model-local functions:

model = l2norm.to_model_proto(functions=[])
print(proto2text(model))
print(onnx.printer.to_text(model))

# %%
# Now, generate a model with one model-local function:

model = l2norm.to_model_proto(functions=[sum])
print(proto2text(model))
print(onnx.printer.to_text(model))
2 changes: 1 addition & 1 deletion docs/tutorial/examples/forloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def sumprod(x, N):
sum = op.Identity(x)
prod = op.Identity(x)
for i in range(N):
for _ in range(N):
sum = sum + x
prod = prod * x
return sum, prod
2 changes: 1 addition & 1 deletion docs/tutorial/examples/forwhileloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def sumprod_break(x, N):
sum = op.Identity(x)
prod = op.Identity(x)
for i in range(N):
for _ in range(N):
sum = sum + x
prod = prod * x
cond = op.ReduceSum(prod) > 1e7
Expand Down
3 changes: 1 addition & 2 deletions docs/tutorial/examples/hardmax_end_to_end.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import onnx

# We use ONNX opset 15 to define the function below.
from onnxscript import FLOAT
from onnxscript import FLOAT, script
from onnxscript import opset15 as op
from onnxscript import script


# We use the script decorator to indicate that
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/examples/outerscope_redef_error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from onnxscript import graph, script
from onnxscript import opset15 as op
from onnxscript import script

try:

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/examples/scanloop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from onnxscript import graph, script
from onnxscript import opset15 as op
from onnxscript import script


@script()
Expand Down
3 changes: 1 addition & 2 deletions onnxscript/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

# isort: on

from ._internal.utils import external_tensor, proto2text
from ._internal.utils import external_tensor
from .values import OnnxFunction, TracedOnnxFunction

try:
Expand All @@ -73,7 +73,6 @@
"OnnxFunction",
"TracedOnnxFunction",
"proto2python",
"proto2text",
"external_tensor",
"graph",
"BFLOAT16",
Expand Down
10 changes: 0 additions & 10 deletions onnxscript/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@

from onnxscript import tensor

# print utility unavailable in ONNX 1.12 or earlier:
# pylint: disable=unused-import, ungrouped-imports
try:
from onnx.printer import to_text as proto2text
except ImportError:

def proto2text(_: Any) -> str: # type: ignore[misc]
return "<print utility unavailable>"


# pylint: enable=unused-import, ungrouped-imports


Expand Down
5 changes: 3 additions & 2 deletions onnxscript/backend/onnx_export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import unittest
from typing import Pattern

import onnx
import onnxruntime as ort
import parameterized
from onnxruntime.capi import onnxruntime_pybind11_state
Expand Down Expand Up @@ -273,7 +274,7 @@ def test_export2python_produces_correct_onnx_script_model(
except Exception as e:
raise AssertionError(
f"Unable to load onnx for test {backend_test.name!r}.\n"
f"{onnxscript.proto2text(proto)}\n"
f"{onnx.printer.to_text(proto)}\n"
f"-----\n"
f"{backend_test.onnx_model}"
) from e
Expand All @@ -298,7 +299,7 @@ def _run_function(obj, *inputs):
except Exception as e:
raise AssertionError(
f"Unable to run test {backend_test.name!r} after conversion.\n"
f"{onnxscript.proto2text(proto)}"
f"{onnx.printer.to_text(proto)}"
) from e

backend_test.run(_load_function, _run_function)
Expand Down
2 changes: 1 addition & 1 deletion onnxscript/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def _call_ort(
raise EagerModeError(
f"Unable to create onnxruntime InferenceSession "
f"for executing {schema.domain}.{schema.name} op "
f"with onnx model\n{utils.proto2text(model)}"
f"with onnx model\n{onnx.printer.to_text(model)}"
) from e

try:
Expand Down
2 changes: 1 addition & 1 deletion onnxscript/function_libs/torch_lib/graph_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def to_model_proto(
warnings.warn(f"ONNX model is invalid: {e}", stacklevel=1)
logging.debug(
"ONNX model:\n%s\n\nTorchScript graph:\n%s",
onnxscript.proto2text(onnx_model),
onnx.printer.to_text(onnx_model),
self.torch_graph,
)
return onnx_model
4 changes: 2 additions & 2 deletions onnxscript/tests/function_libs/torch_lib/ops_test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _format_model_and_input_information(onnx_model, inputs):
f"Inputs:\n"
f"{pprint.pformat(inputs)}\n"
f"Model:\n"
f"{onnxscript.proto2text(onnx_model)}"
f"{onnx.printer.to_text(onnx_model)}"
)


Expand Down Expand Up @@ -526,7 +526,7 @@ def _capture_graph_and_evaluate_torch_script_evaluator(function: Callable, args,
onnx.checker.check_model(onnx_model, full_check=True)
except (onnx.checker.ValidationError, onnx.shape_inference.InferenceError) as e:
raise AssertionError(
f"ONNX model is invalid. Model:\n{onnxscript.proto2text(onnx_model)}"
f"ONNX model is invalid. Model:\n{onnx.printer.to_text(onnx_model)}"
) from e

try:
Expand Down

0 comments on commit e35a179

Please sign in to comment.