IR Data Structures¶
Core data structures that compose the IR graph.
ir ¶
IR data structures for compiler backends.
TensorMeta
dataclass
¶
TensorMeta(name: str, shape: Tuple[int, ...], dtype: str, producer_node: Optional[str] = None, producer_output_idx: int = 0)
Metadata for a tensor (shape and dtype only, no actual data).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique tensor name within the IR graph. |
shape |
Tuple[int, ...]
|
Static shape of the tensor (e.g., |
dtype |
str
|
String representation of the data type (e.g., |
producer_node |
Optional[str]
|
Name of the node that produced this tensor.
|
producer_output_idx |
int
|
Index into the producer node's output list. Used to resolve the correct tensor when a node produces multiple outputs. |
to_dict ¶
Serialize to a JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with |
Dict[str, Any]
|
Includes |
Source code in torch_ir/ir.py
from_dict
classmethod
¶
Deserialize from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary produced by |
required |
Returns:
| Type | Description |
|---|---|
TensorMeta
|
Reconstructed |
Source code in torch_ir/ir.py
OpNode
dataclass
¶
OpNode(name: str, op_type: str, inputs: List[TensorMeta], outputs: List[TensorMeta], attrs: Dict[str, Any] = dict())
A single operation node in the IR graph.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique node name (e.g., |
op_type |
str
|
ATen operation type string (e.g., |
inputs |
List[TensorMeta]
|
Input tensor metadata list. |
outputs |
List[TensorMeta]
|
Output tensor metadata list. |
attrs |
Dict[str, Any]
|
Operation attributes such as |
to_dict ¶
Serialize to a JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing all node fields. |
Source code in torch_ir/ir.py
from_dict
classmethod
¶
Deserialize from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary produced by |
required |
Returns:
| Type | Description |
|---|---|
OpNode
|
Reconstructed |
Source code in torch_ir/ir.py
IR
dataclass
¶
IR(nodes: List[OpNode], graph_inputs: List[TensorMeta], graph_outputs: List[TensorMeta], weights: List[TensorMeta], weight_name_mapping: Dict[str, str] = dict(), constants: Dict[str, Any] = dict(), model_name: str = '', pytorch_version: str = '')
Complete IR representation of a model.
Attributes:
| Name | Type | Description |
|---|---|---|
nodes |
List[OpNode]
|
Ordered list of operation nodes in the graph. |
graph_inputs |
List[TensorMeta]
|
Metadata for graph input tensors (user-provided activations). |
graph_outputs |
List[TensorMeta]
|
Metadata for graph output tensors. |
weights |
List[TensorMeta]
|
Metadata for weight/buffer tensors (shape and dtype only, no values). |
weight_name_mapping |
Dict[str, str]
|
Maps FX placeholder names (e.g., |
constants |
Dict[str, Any]
|
Lifted tensor constants from |
model_name |
str
|
Human-readable model name. |
pytorch_version |
str
|
PyTorch version used during IR extraction. |
to_dict ¶
Serialize to a JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary representation of the entire IR graph. |
Source code in torch_ir/ir.py
from_dict
classmethod
¶
Deserialize from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary produced by |
required |
Returns:
| Type | Description |
|---|---|
IR
|
Reconstructed |
Source code in torch_ir/ir.py
save ¶
Save IR to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Output file path. |
required |