onnx_ir.tensor_adapters

Compatible adapters implementing the TensorProtocol interface for various framework tensor types.

This module provides public classes that implement the onnx_ir.TensorProtocol interface for various tensor types from popular deep learning frameworks.

You can use these classes to create tensors and use them in the IR graph like any other tensor.

Example::

import torch import onnx_ir as ir

# Create a PyTorch tensor torch_tensor = torch.tensor([1, 2, 3])

# Wrap the PyTorch tensor in a TorchTensor object ir_tensor = ir.tensor_adapters.TorchTensor(torch_tensor)

# Use the IR tensor in the graph attr = ir.AttrTensor(“x”, ir_tensor) print(attr)

Adapters for PyTorch

onnx_ir.tensor_adapters.from_torch_dtype(dtype)[source]

Convert a PyTorch dtype to an ONNX IR DataType.

Parameters:

dtype (torch.dtype)

Return type:

ir.DataType

onnx_ir.tensor_adapters.to_torch_dtype(dtype)[source]

Convert an ONNX IR DataType to a PyTorch dtype.

Parameters:

dtype (ir.DataType)

Return type:

torch.dtype