TensorPlay
API reference
latest (dev)
Copy
View Markdown

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 ModelProto is 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. None decides 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.checker over the finished model.

Returns:

The onnx.ModelProto when f is None, else None.

#

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.Module or plain callable; child modules are inlined.

  • args/kwargs – example inputs binding argument defaults.

  • dynamic_shapes – dimension specification per argument (dict, sequence, ShapesCollection, or AdditionalInputs).

  • 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_graph for 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 model under 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 VerificationError instead of returning a failed result.

Classes 5

#

GraphBuilder

classFull reference ↗
class tensorplay.onnx.GraphBuilder(opset: int, name: str = 'tensorplay_model')[source]

Accumulates ONNX nodes, initializers and unique value names.

constant(value: Any, dtype: Any = None, name_hint: str = 'const') → str[source]

Materialize a python/tensor constant as a cached initializer.

op(op_type: str, inputs: Sequence[str], *, num_outputs: int = 1, name_hint: str | None = None, outputs: Sequence[str] | None = None, **attrs: Any) → Any[source]

Emit one ONNX node and return its output name (or list of names).

#

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 with reference’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.

#

VerificationResult

classFull reference ↗
class tensorplay.onnx.VerificationResult(matched: bool, max_abs_diff: float = 0.0, max_rel_diff: float = 0.0, mismatches: list[str] = <factory>)[source]

Per-output comparison between eager TensorPlay and onnxruntime.

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 ↗
exception tensorplay.onnx.UnsupportedOperatorError(name: str, version: int | None = None, supported_version: int | None = None)[source]

Raised when a captured operation has no ONNX lowering.

#

VerificationError

exceptionFull reference ↗
exception tensorplay.onnx.VerificationError[source]

Raised when the exported graph disagrees with eager execution.

On this page

Ask DeepWiki