Exporter¶
Module that wraps torch.export to export models.
exporter ¶
Model exporter using torch.export.
ExportError ¶
Bases: Exception
Raised when model export fails.
is_meta_tensor ¶
Check if a tensor is on the meta device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
The tensor to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
is_meta_module ¶
Check if a module has all parameters and buffers on meta device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
Module
|
The PyTorch module to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in torch_ir/exporter.py
validate_meta_device ¶
Validate that the model is on meta device.
Raises:
| Type | Description |
|---|---|
ExportError
|
If the model is not on meta device. |
Source code in torch_ir/exporter.py
validate_inputs_meta ¶
Validate that all tensor inputs are on meta device.
Raises:
| Type | Description |
|---|---|
ExportError
|
If any tensor input is not on meta device. |
Source code in torch_ir/exporter.py
export_model ¶
export_model(model: Module, example_inputs: Tuple[Any, ...], *, strict: bool = True) -> ExportedProgram
Export a model using torch.export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The PyTorch model to export (must be on meta device). |
required |
example_inputs
|
Tuple[Any, ...]
|
Example inputs for tracing (must be on meta device). |
required |
strict
|
bool
|
If True, validate meta device. Set False for testing with real tensors. |
True
|
Returns:
| Type | Description |
|---|---|
ExportedProgram
|
ExportedProgram containing the traced graph. |
Raises:
| Type | Description |
|---|---|
ExportError
|
If validation fails or export encounters an error. |