model (torch.nn.Module | torch.export.ExportedProgram | torch.jit.ScriptModule | torch.jit.ScriptFunction) – The model to be exported.
args (tuple[Any, ...]) – Example positional inputs. Any non-Tensor arguments will be hard-coded into the
exported model; any Tensor arguments will become inputs of the exported model,
in the order they occur in the tuple.
f (str | os.PathLike | None) – Path to the output ONNX model file. E.g. “model.onnx”. This argument is kept for
backward compatibility. It is recommended to leave unspecified (None)
and use the returned torch.onnx.ONNXProgram to serialize the model
to a file instead.
kwargs (dict[str, Any] | None) – Optional example keyword inputs.
verbose (bool | None) – Whether to enable verbose logging.
input_names (Sequence[str] | None) – names to assign to the input nodes of the graph, in order.
output_names (Sequence[str] | None) – names to assign to the output nodes of the graph, in order.
These are labels only and do not affect the order of outputs. If the model
returns a dictionary, outputs are flattened in the dictionary’s iteration
order regardless of the names specified here.
opset_version (int | None) – The version of the
default (ai.onnx) opset
to target. You should set opset_version according to the supported opset versions
of the runtime backend or compiler you want to run the exported model with.
Leave as default (None) to use the recommended version, or refer to
the ONNX operators documentation for more information.
dynamo (bool) – Whether to export the model with torch.export ExportedProgram instead of TorchScript.
external_data (bool) – Whether to save the model weights as an external data file.
This is required for models with large weights that exceed the ONNX file size limit (2GB).
When False, the weights are saved in the ONNX file with the model architecture.
dynamic_shapes (dict[str, Any] | tuple[Any, ...] | list[Any] | None) – A dictionary or a tuple of dynamic shapes for the model inputs. Refer to
torch.export.export() for more details. This is only used (and preferred) when dynamo is True.
Note that dynamic_shapes is designed to be used when the model is exported with dynamo=True, while
dynamic_axes is used when dynamo=False.
custom_translation_table (dict[Callable, Callable] | None) – A dictionary of custom decompositions for operators in the model.
The dictionary should have the callable target in the fx Node as the key (e.g. torch.ops.aten.stft.default),
and the value should be a function that builds that graph using ONNX Script. This option
is only valid when dynamo is True.
report (bool) – Whether to generate a markdown report for the export process. This option
is only valid when dynamo is True.
optimize (bool) – Whether to optimize the exported model. This option
is only valid when dynamo is True. Default is True.
verify (bool) – Whether to verify the exported model using ONNX Runtime. This option
is only valid when dynamo is True.
profile (bool) – Whether to profile the export process. This option
is only valid when dynamo is True.
dump_exported_program (bool) – Whether to dump the torch.export.ExportedProgram to a file.
This is useful for debugging the exporter. This option is only valid when dynamo is True.
artifacts_dir (str | os.PathLike) – The directory to save the debugging artifacts like the report and the serialized
exported program. This option is only valid when dynamo is True.
export_params (bool) –
When ``f`` is specified: If false, parameters (weights) will not be exported.
You can also leave it unspecified and use the returned torch.onnx.ONNXProgram
to control how initializers are treated when serializing the model.
keep_initializers_as_inputs (bool) –
When ``f`` is specified: If True, all the
initializers (typically corresponding to model weights) in the
exported graph will also be added as inputs to the graph. If False,
then initializers are not added as inputs to the graph, and only
the user inputs are added as inputs.
Set this to True if you intend to supply model weights at runtime.
Set it to False if the weights are static to allow for better optimizations
(e.g. constant folding) by backends/runtimes.
You can also leave it unspecified and use the returned torch.onnx.ONNXProgram
to control how initializers are treated when serializing the model.
dynamic_axes (Mapping[str, Mapping[int, str]] | Mapping[str, Sequence[int]] | None) –
Deprecated: Prefer specifying dynamic_shapes when dynamo=True.
By default the exported model will have the shapes of all input and output tensors
set to exactly match those given in . To specify axes of tensors as
dynamic (i.e. known only at run-time), set to a dict with schema:
training (_C_onnx.TrainingMode) – Deprecated option. Instead, set the training mode of the model before exporting.
operator_export_type (_C_onnx.OperatorExportTypes) – Deprecated option. Only ONNX is supported.
do_constant_folding (bool) – Deprecated option.
custom_opsets (Mapping[str, int] | None) – Deprecated option.
export_modules_as_functions (bool | Collection[type[torch.nn.Module]]) – Deprecated option.
autograd_inlining (bool) – Deprecated option.