latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.onnx API
Functions 6
export
functionFull reference ↗- tensorplay.onnx.export(exported_program: ExportedProgram | Any, f: Any = None, *, input_names: Sequence[str] | None = None, output_names: Sequence[str] | None = None, opset_version: int | None = None, dynamic_axes: Mapping[str, Mapping[int, str] | Sequence[int]] | None = None, do_constant_folding: bool = True, verify: bool = False, rtol: float = 0.0001, atol: float = 1e-05, external_data: bool | None = None, external_data_location: str | None = None, check_model: bool = True) Any[source]
Export a TensorPlay model to ONNX.
- Parameters:
exported_program – an
ExportedProgram, or a(model, *args, kwargs)sequence captured on the fly.f – file path or writable binary file object. When omitted the
ModelProtois returned instead of being written.input_names – names for the graph inputs, in placeholder order.
output_names – names for the graph outputs.
opset_version – target ONNX opset (default 18, minimum 13).
dynamic_axes –
{value_name: {axis: axis_name}}(or a list of axis indices) marking dimensions that vary at runtime. Applies to both inputs and outputs.do_constant_folding – fold subgraphs whose inputs are all constants.
verify – run the exported model under onnxruntime and compare against eager execution of
exported_program.rtol/atol – tolerances used by
verify.external_data – store initializers in a side-car file.
Nonedecides from the model size (models at or above the 2 GiB protobuf limit).external_data_location – side-car file name for
external_data.check_model – run
onnx.checkerover the finished model.
- Returns:
The
onnx.ModelProtowhenfisNone, elseNone.
is_supported
functionFull reference ↗lookup_function_handler
functionFull reference ↗lookup_method_handler
functionFull reference ↗tp_export
functionFull reference ↗- tensorplay.onnx.tp_export(model: Callable[[...], Any], *args: Any, dynamic_shapes: Any = None, strict: bool = False, preserve_module_call_signature: Any = (), **kwargs: Any) ExportedProgram
Capture a callable and return an executable graph program.
- Parameters:
model – an
nn.Moduleor plain callable; child modules are inlined.args/kwargs – example inputs binding argument defaults.
dynamic_shapes – dimension specification per argument (dict, sequence,
ShapesCollection, orAdditionalInputs).strict – reserved for callers of the strict capture contract; capture validation is identical in both modes.
preserve_module_call_signature – submodule paths whose call metadata is recorded in
module_call_graphfor module-level tooling.
verify_model
functionFull reference ↗- tensorplay.onnx.verify_model(model: Any, *, expected: Any, input_names: Sequence[str], example_inputs: dict[str, Any], rtol: float = 0.0001, atol: float = 1e-05, raise_on_mismatch: bool = True) VerificationResult[source]
Compare
modelunder onnxruntime against the eager result.- Parameters:
model – the built
ModelProto.expected – what eager TensorPlay produced for
example_inputs— a tensor, or an arbitrarily nested tuple/list of them.input_names – ONNX graph input names, in placeholder order.
example_inputs – placeholder name -> example tensor.
rtol/atol – tolerances forwarded to
numpy.allclose().raise_on_mismatch – raise
VerificationErrorinstead of returning a failed result.
Classes 5
GraphBuilder
classFull reference ↗OpContext
classFull reference ↗- class tensorplay.onnx.OpContext(builder: GraphBuilder, node_name: str, params: Sequence[str], args: Sequence[Any], kwargs: dict[str, Any], out_shape: tuple | None = None, out_dtype: dtype | None = None)[source]
Argument access plus emission helpers handed to every handler.
- cast_like(value: Any, reference: Any, name_hint: str = 'const') str[source]
Name for
value, materialized withreference’s dtype.
- name(value: Any, name_hint: str = 'const') str[source]
ONNX value name for
value, materializing constants on demand.
- property x: Any
First declared argument (the input tensor for nearly every op).
TensorProto
classFull reference ↗- class tensorplay.onnx.TensorProto
- ByteSize()
Returns the size of the message in bytes.
- Clear()
Clears the message.
- ClearExtension()
Clears a message field.
- ClearField()
Clears a message field.
- CopyFrom()
Copies a protocol message into the current message.
- DiscardUnknownFields()
Discards the unknown fields.
- Extensions
Extension dict
- FindInitializationErrors()
Finds unset required fields.
- classmethod FromString()
Creates new method instance from given serialized data.
- HasExtension()
Checks if a message field is set.
- HasField()
Checks if a message field is set.
- IsInitialized()
Checks if all required fields of a protocol message are set.
- ListFields()
Lists all set fields of a message.
- MergeFrom()
Merges a protocol message into the current message.
- MergeFromString()
Merges a serialized message into the current message.
- ParseFromString()
Parses a serialized message into the current message.
- SerializePartialToString()
Serializes the message to a string, even if it isn’t initialized.
- SerializeToString()
Serializes the message to a string, only for initialized messages.
- SetInParent()
Sets the has bit of the given field in its parent message.
- UnknownFields()
Parse unknown field set
- WhichOneof()
Returns the name of the field set inside a oneof, or None if no field is set.
Value
classFull reference ↗VerificationResult
classFull reference ↗Exceptions 4
OnnxExporterError
exceptionFull reference ↗- exception tensorplay.onnx.OnnxExporterError[source]
Base class for errors raised by the ONNX exporter.
OnnxExporterWarning
exceptionFull reference ↗- exception tensorplay.onnx.OnnxExporterWarning[source]
Warnings raised during ONNX export.
UnsupportedOperatorError
exceptionFull reference ↗VerificationError
exceptionFull reference ↗- exception tensorplay.onnx.VerificationError[source]
Raised when the exported graph disagrees with eager execution.
Help improve this page
Found an error, an unclear step, or a missing example?

