diff --git a/test/onnx/test_pytorch_onnx_no_runtime.py b/test/onnx/test_pytorch_onnx_no_runtime.py index cb4f72e5aa205..62daae73b4768 100644 --- a/test/onnx/test_pytorch_onnx_no_runtime.py +++ b/test/onnx/test_pytorch_onnx_no_runtime.py @@ -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 diff --git a/torch/onnx/__init__.py b/torch/onnx/__init__.py index b7ab2e6cf727b..f0bd3c0815cf4 100644 --- a/torch/onnx/__init__.py +++ b/torch/onnx/__init__.py @@ -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. @@ -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: diff --git a/torch/onnx/_deprecation.py b/torch/onnx/_deprecation.py index 61d9bb264fa72..24fe4ccc54fcd 100644 --- a/torch/onnx/_deprecation.py +++ b/torch/onnx/_deprecation.py @@ -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) diff --git a/torch/onnx/_internal/_exporter_legacy.py b/torch/onnx/_internal/_exporter_legacy.py index e0c9b0995740e..d4c21bf48c8c6 100644 --- a/torch/onnx/_internal/_exporter_legacy.py +++ b/torch/onnx/_internal/_exporter_legacy.py @@ -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 @@ -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. @@ -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. @@ -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. @@ -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, /, diff --git a/torch/onnx/_internal/exporter/_compat.py b/torch/onnx/_internal/exporter/_compat.py index 17123f95562b8..86522b66a9413 100644 --- a/torch/onnx/_internal/exporter/_compat.py +++ b/torch/onnx/_internal/exporter/_compat.py @@ -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() diff --git a/torch/onnx/utils.py b/torch/onnx/utils.py index 39d33cb93b6db..daa451447eae1 100644 --- a/torch/onnx/utils.py +++ b/torch/onnx/utils.py @@ -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 diff --git a/torch/onnx/verification.py b/torch/onnx/verification.py index a4277d9af37f5..5563f67304c1d 100644 --- a/torch/onnx/verification.py +++ b/torch/onnx/verification.py @@ -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 @@ -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, @@ -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, ...], @@ -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."""