Serializer¶
Module for JSON serialization/deserialization of IR.
serializer ¶
IR Serializer for JSON serialization/deserialization.
SerializationError ¶
Bases: Exception
Raised when serialization/deserialization fails.
serialize_ir ¶
Serialize IR to JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ir
|
IR
|
The IR to serialize. |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON string representation. |
deserialize_ir ¶
Deserialize IR from JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_str
|
str
|
JSON string representation. |
required |
Returns:
| Type | Description |
|---|---|
IR
|
The deserialized IR. |
Raises:
| Type | Description |
|---|---|
SerializationError
|
If deserialization fails. |
Source code in torch_ir/serializer.py
save_ir ¶
Save IR to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ir
|
IR
|
The IR to save. |
required |
path
|
Union[str, Path]
|
The file path to save to. |
required |
Source code in torch_ir/serializer.py
load_ir ¶
Load IR from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
The file path to load from. |
required |
Returns:
| Type | Description |
|---|---|
IR
|
The loaded IR. |
Raises:
| Type | Description |
|---|---|
SerializationError
|
If loading fails. |
FileNotFoundError
|
If the file doesn't exist. |
Source code in torch_ir/serializer.py
validate_ir ¶
Validate the IR structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ir
|
IR
|
The IR to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid, raises exception otherwise. |
Raises:
| Type | Description |
|---|---|
SerializationError
|
If validation fails. |