8000 [ONNX] Adjust and add deprecation messages (#146639) · pytorch/pytorch@63c2909 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63c2909

Browse files
justinchubypytorchmergebot
authored andcommitted
[ONNX] Adjust and add deprecation messages (#146639)
Adjust and add deprecation messages to torch.onnx utilities and verification methods because they are only related to torch script and are obsolete. Removed unused `_exporter_states.py` and removed the internal deprecation module in favor of the typing_extensions deprecated decorator. Pull Request resolved: #146639 Approved by: https://github.com/titaiwangms
1 parent 2328dcc commit 63c2909

File tree

7 files changed

+120
-151
lines changed

7 files changed

+120
-151
lines changed

torch/onnx/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
]
5050

5151
from typing import Any, Callable, TYPE_CHECKING
52+
from typing_extensions import deprecated
5253

5354
import torch
5455
from torch import _C
@@ -168,6 +169,19 @@ def export(
168169
) -> ONNXProgram | None:
169170
r"""Exports a model into ONNX format.
170171
172+
.. versionchanged:: 2.6
173+
*training* is now deprecated. Instead, set the training mode of the model before exporting.
174+
.. versionchanged:: 2.6
175+
*operator_export_type* is now deprecated. Only ONNX is supported.
176+
.. versionchanged:: 2.6
177+
*do_constant_folding* is now deprecated. It is always enabled.
178+
.. versionchanged:: 2.6
179+
*export_modules_as_functions* is now deprecated.
180+
.. versionchanged:: 2.6
181+
*autograd_inlining* is now deprecated.
182+
.. versionchanged:: 2.7
183+
*optimize* is now True by default.
184+
171185
Args:
172186
model: The model to be exported.
173187
args: Example positional inputs. Any non-Tensor arguments will be hard-coded into the
@@ -342,6 +356,9 @@ def forward(self, x):
342356
autograd_inlining: Deprecated.
343357
Flag used to control whether to inline autograd functions.
344358
Refer to https://github.com/pytorch/pytorch/pull/74765 for more details.
359+
360+
Returns:
361+
:class:`torch.onnx.ONNXProgram` if dynamo is True, otherwise None.
345362
"""
346363
if dynamo is True or isinstance(model, torch.export.ExportedProgram):
347364
from torch.onnx._internal.exporter import _compat
@@ -402,6 +419,9 @@ def forward(self, x):
402419
return None
403420

404421

422+
@deprecated(
423+
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead."
424+
)
405425
def dynamo_export(
406426
model: torch.nn.Module | Callable | torch.export.ExportedProgram, # type: ignore[name-defined]
407427
/,
@@ -411,6 +431,9 @@ def dynamo_export(
411431
) -> ONNXProgram:
412432
"""Export a torch.nn.Module to an ONNX graph.
413433
434+
.. deprecated:: 2.6
435+
Please use ``torch.onnx.export(..., dynamo=True)`` instead.
436+
414437
Args:
415438
model: The PyTorch model to be exported to ONNX.
416439
model_args: Positional inputs to ``model``.
@@ -452,7 +475,6 @@ def forward(self, x, bias=None):
452475
onnx_program.save("my_dynamic_model.onnx")
453476
"""
454477

455-
# NOTE: The new exporter is experimental and is not enabled by default.
456478
import warnings
457479

458480
from torch.onnx import _flags

torch/onnx/_deprecation.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

torch/onnx/_exporter_states.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

torch/onnx/_internal/_exporter_legacy.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ class ONNXFakeContext:
8181

8282

8383
@deprecated(
84-
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
85-
category=DeprecationWarning,
84+
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead."
8685
)
8786
class OnnxRegistry:
8887
"""Registry for ONNX functions.
8988
89+
.. deprecated:: 2.6
90+
Please use ``torch.onnx.export(..., dynamo=True)`` instead.
91+
9092
The registry maintains a mapping from qualified names to symbolic functions under a
9193
fixed opset version. It supports registering custom onnx-script functions and for
9294
dispatcher to dispatch calls to the appropriate function.
@@ -229,12 +231,14 @@ def _all_registered_ops(self) -> set[str]:
229231

230232

231233
@deprecated(
232-
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
233-
category=DeprecationWarning,
234+
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead."
234235
)
235236
class ExportOptions:
236237
"""Options to influence the TorchDynamo ONNX exporter.
237238
239+
.. deprecated:: 2.6
240+
Please use ``torch.onnx.export(..., dynamo=True)`` instead.
241+
238242
Attributes:
239243
dynamic_shapes: Shape information hint for input/output tensors.
240244
When ``None``, the exporter determines the most compatible setting.
@@ -385,8 +389,9 @@ def enable_fake_mode():
385389
It is highly recommended to initialize the model in fake mode when exporting models that
386390
are too large to fit into memory.
387391
388-
NOTE: This function does not support torch.onnx.export(..., dynamo=True, optimize=True), so
389-
please call ONNXProgram.optimize() outside of the function after the model is exported.
392+
.. note::
393+
This function does not support torch.onnx.export(..., dynamo=True, optimize=True).
394+
Please call ONNXProgram.optimize() outside of the function after the model is exported.
390395
391396
Example::
392397
@@ -443,12 +448,14 @@ def enable_fake_mode():
443448

444449

445450
@deprecated(
446-
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
447-
category=DeprecationWarning,
451+
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead."
448452
)
449453
class ONNXRuntimeOptions:
450454
"""Options to influence the execution of the ONNX model through ONNX Runtime.
451455
456+
.. deprecated:: 2.6
457+
Please use ``torch.onnx.export(..., dynamo=True)`` instead.
458+
452459
Attributes:
453460
session_options: ONNX Runtime session options.
454461
execution_providers: ONNX Runtime execution providers to use during model execution.
@@ -701,8 +708,7 @@ def missing_opset(package_name: str):
701708

702709

703710
@deprecated(
704-
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead.",
705-
category=DeprecationWarning,
711+
"torch.onnx.dynamo_export is deprecated since 2.6.0. Please use torch.onnx.export(..., dynamo=True) instead."
706712
)
707713
def dynamo_export(
708714
model: torch.nn.Module | Callable,
@@ -713,6 +719,9 @@ def dynamo_export(
713719
) -> _onnx_program.ONNXProgram:
714720
"""Export a torch.nn.Module to an ONNX graph.
715721
722+
.. deprecated:: 2.6
723+
Please use ``torch.onnx.export(..., dynamo=True)`` instead.
724+
716725
Args:
717726
model: The PyTorch model to be exported to ONNX.
718727
model_args: Positional inputs to ``model``.

torch/onnx/symbolic_opset9.py

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import warnings
1717
from typing import Callable, TYPE_CHECKING
18+
from typing_extensions import deprecated
1819

1920
import torch
2021
import torch._C._onnx as _C_onnx
@@ -23,7 +24,7 @@
2324
from torch import _C
2425

2526
# Monkey-patch graph manipulation methods on Graph, used for the ONNX symbolics
26-
from torch.onnx import _constants, _deprecation, _type_utils, errors, symbolic_helper
27+
from torch.onnx import _constants, _type_utils, errors, symbolic_helper
2728
from torch.onnx._globals import GLOBALS
2829
from torch.onnx._internal import jit_utils, registration
2930

@@ -3315,91 +3316,55 @@ def _unique2(g: jit_utils.GraphContext, input, sorted, return_inverse, return_co
33153316

33163317

33173318
@_onnx_symbolic("aten::_cast_Byte")
3318-
@_deprecation.deprecated(
3319-
"2.0",
3320-
"the future",
3321-
"Avoid using this function and create a Cast node instead",
3322-
)
3319+
@deprecated("Avoid using this function and create a Cast node instead")
33233320
def _cast_Byte(g: jit_utils.GraphContext, input, non_blocking):
33243321
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.UINT8)
33253322

33263323

33273324
@_onnx_symbolic("aten::_cast_Char")
3328-
@_deprecation.deprecated(
3329-
"2.0",
3330-
"the future",
3331-
"Avoid using this function and create a Cast node instead",
3332-
)
3325+
@deprecated("Avoid using this function and create a Cast node instead")
33333326
def _cast_Char(g: jit_utils.GraphContext, input, non_blocking):
33343327
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.INT8)
33353328

33363329

33373330
@_onnx_symbolic("aten::_cast_Short")
3338-
@_deprecation.deprecated(
3339-
"2.0",
3340-
"the future",
3341-
"Avoid using this function and create a Cast node instead",
3342-
)
3331+
@deprecated("Avoid using this function and create a Cast node instead")
33433332
def _cast_Short(g: jit_utils.GraphContext, input, non_blocking):
33443333
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.INT16)
33453334

33463335

33473336
@_onnx_symbolic("aten::_cast_Int")
3348-
@_deprecation.deprecated(
3349-
"2.0",
3350-
"the future",
3351-
"Avoid using this function and create a Cast node instead",
3352-
)
3337+
@deprecated("Avoid using this function and create a Cast node instead")
33533338
def _cast_Int(g: jit_utils.GraphContext, input, non_blocking):
33543339
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.INT32)
33553340

33563341

33573342
@_onnx_symbolic("aten::_cast_Long")
3358-
@_deprecation.deprecated(
3359-
"2.0",
3360-
"the future",
3361-
"Avoid using this function and create a Cast node instead",
3362-
)
3343+
@deprecated("Avoid using this function and create a Cast node instead")
33633344
def _cast_Long(g: jit_utils.GraphContext, input, non_blocking):
33643345
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.INT64)
33653346

33663347

33673348
@_onnx_symbolic("aten::_cast_Half")
3368-
@_deprecation.deprecated(
3369-
"2.0",
3370-
"the future",
3371-
"Avoid using this function and create a Cast node instead",
3372-
)
3349+
@deprecated("Avoid using this function and create a Cast node instead")
33733350
def _cast_Half(g: jit_utils.GraphContext, input, non_blocking):
33743351 return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.FLOAT16)
33753352

33763353

33773354
@_onnx_symbolic("aten::_cast_Float")
3378-
@_deprecation.deprecated(
3379-
"2.0",
3380-
"the future",
3381-
"Avoid using this function and create a Cast node instead",
3382-
)
3355+
@deprecated("Avoid using this function and create a Cast node instead")
33833356
def _cast_Float(g: jit_utils.GraphContext, input, non_blocking):
33843357
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.FLOAT)
33853358

33863359

33873360
@_onnx_symbolic("aten::_cast_Double")
3388-
@_deprecation.deprecated(
3389-
"2.0",
3390-
"the future",
3391-
"Avoid using this function and create a Cast node instead",
3392-
)
3361+
@deprecated("Avoid using this function and create a Cast node instead")
33933362
def _cast_Double(g: jit_utils.GraphContext, input, non_blocking):
33943363
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.DOUBLE)
33953364

33963365

33973366
@_onnx_symbolic("aten::_cast_Bool")
3398-
@_deprecation.deprecated(
3399-
"2.0",
3400-
"the future",
3401-
"Avoid using this function and create a Cast node instead",
3402-
)
3367+
@deprecated("Avoid using this function and create a Cast node instead")
34033368
def _cast_Bool(g: jit_utils.GraphContext, input, non_blocking):
34043369
return g.op("Cast", input, to_i=_C_onnx.TensorProtoDataType.BOOL)
34053370

0 commit comments

Comments
 (0)
0