Skip to content

Commit

Permalink
Revert "[ONNX] Create deprecation warning on dynamo_export (pytorch#1…
Browse files Browse the repository at this point in the history
…46425)"

This reverts commit 41e6d18.

Reverted pytorch#146425 on behalf of https://github.com/atalman due to Broke internal tests ([comment](pytorch#146425 (comment)))
  • Loading branch information
pytorchmergebot committed Feb 10, 2025
1 parent 1557b7b commit 6aa924a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 37 deletions.
16 changes: 16 additions & 0 deletions test/onnx/test_pytorch_onnx_no_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,22 @@ def forward(self, x):
f = io.BytesIO()
torch.onnx.export(foo, (torch.zeros(1, 2, 3)), f)

def test_listconstruct_erasure(self):
class FooMod(torch.nn.Module):
def forward(self, x):
mask = x < 0.0
return x[mask]

f = io.BytesIO()
torch.onnx.export(
FooMod(),
(torch.rand(3, 4),),
f,
add_node_names=False,
do_constant_folding=False,
operator_export_type=torch.onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK,
)

def test_export_dynamic_slice(self):
class DynamicSliceExportMod(torch.jit.ScriptModule):
@torch.jit.script_method
Expand Down
3 changes: 2 additions & 1 deletion torch/onnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def export(
custom_opsets: Mapping[str, int] | None = None,
export_modules_as_functions: bool | Collection[type[torch.nn.Module]] = False,
autograd_inlining: bool = True,
**_: Any, # ignored options
) -> ONNXProgram | None:
r"""Exports a model into ONNX format.
Expand Down Expand Up @@ -476,7 +477,7 @@ def forward(self, x, bias=None):
"You are using an experimental ONNX export logic, which currently only supports dynamic shapes. "
"For a more comprehensive set of export options, including advanced features, please consider using "
"`torch.onnx.export(..., dynamo=True)`. ",
category=DeprecationWarning,
category=FutureWarning,
)

if export_options is not None and export_options.dynamic_shapes:
Expand Down
2 changes: 1 addition & 1 deletion torch/onnx/_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _T:
f"'{function.__module__}.{function.__name__}' "
f"is deprecated in version {since} and will be "
f"removed in {removed_in}. Please {instructions}.",
category=DeprecationWarning,
category=FutureWarning,
stacklevel=2,
)
return function(*args, **kwargs)
Expand Down
17 changes: 0 additions & 17 deletions torch/onnx/_internal/_exporter_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import warnings
from collections import defaultdict
from typing import Any, Callable, TYPE_CHECKING, TypeVar
from typing_extensions import deprecated

import torch
import torch._ops
Expand Down Expand Up @@ -80,10 +79,6 @@ class ONNXFakeContext:
"""List of paths of files that contain the model :meth:`state_dict`"""


@deprecated(
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
category=DeprecationWarning,
)
class OnnxRegistry:
"""Registry for ONNX functions.
Expand Down Expand Up @@ -228,10 +223,6 @@ def _all_registered_ops(self) -> set[str]:
}


@deprecated(
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
category=DeprecationWarning,
)
class ExportOptions:
"""Options to influence the TorchDynamo ONNX exporter.
Expand Down Expand Up @@ -442,10 +433,6 @@ def enable_fake_mode():
) # type: ignore[assignment]


@deprecated(
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
category=DeprecationWarning,
)
class ONNXRuntimeOptions:
"""Options to influence the execution of the ONNX model through ONNX Runtime.
Expand Down Expand Up @@ -700,10 +687,6 @@ def missing_opset(package_name: str):
raise missing_opset("onnxscript")


@deprecated(
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
category=DeprecationWarning,
)
def dynamo_export(
model: torch.nn.Module | Callable,
/,
Expand Down
1 change: 1 addition & 0 deletions torch/onnx/_internal/exporter/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def export_compat(
dump_exported_program: bool = False,
artifacts_dir: str | os.PathLike = ".",
fallback: bool = False,
**_,
) -> _onnx_program.ONNXProgram:
if opset_version is None:
opset_version = onnxscript_apis.torchlib_opset_version()
Expand Down
4 changes: 2 additions & 2 deletions torch/onnx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,14 @@ def forward(self, x):
warnings.warn(
"Setting `operator_export_type` to something other than default is deprecated. "
"The option will be removed in a future release.",
category=DeprecationWarning,
category=FutureWarning,
)
if training == _C_onnx.TrainingMode.TRAINING:
warnings.warn(
"Setting `training` to something other than default is deprecated. "
"The option will be removed in a future release. Please set the training mode "
"before exporting the model.",
category=DeprecationWarning,
category=FutureWarning,
)

args = (args,) if isinstance(args, torch.Tensor) else args
Expand Down
16 changes: 0 additions & 16 deletions torch/onnx/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import itertools
import os
import tempfile
import typing_extensions
import warnings
from collections.abc import Collection, Mapping, Sequence
from typing import Any, Callable, Union
Expand Down Expand Up @@ -772,11 +771,6 @@ def check_export_model_diff(
)


@typing_extensions.deprecated(
"torch.onnx.verification.* is deprecated. Consider using torch.onnx.export(..., dynamo=True) "
"and use ONNXProgram to test the ONNX model",
category=DeprecationWarning,
)
def verify(
model: _ModelType,
input_args: _InputArgsType,
Expand Down Expand Up @@ -864,11 +858,6 @@ def verify(
)


@typing_extensions.deprecated(
"torch.onnx.verification.* is deprecated. Consider using torch.onnx.export(..., dynamo=True) "
"and use ONNXProgram to test the ONNX model",
category=DeprecationWarning,
)
def verify_aten_graph(
graph: torch.Graph,
input_args: tuple[Any, ...],
Expand Down Expand Up @@ -1159,11 +1148,6 @@ def validate(self, options: VerificationOptions):
_compare_onnx_pytorch_outputs_in_np(run_outputs, expected_outs, options)


@typing_extensions.deprecated(
"torch.onnx.verification.* is deprecated. Consider using torch.onnx.export(..., dynamo=True) "
"and use ONNXProgram to test the ONNX model",
category=DeprecationWarning,
)
@dataclasses.dataclass
class GraphInfo:
"""GraphInfo contains validation information of a TorchScript graph and its converted ONNX graph."""
Expand Down

0 comments on commit 6aa924a

Please sign in to comment.