API Reference¶
Public API documentation for the IR extraction framework.
Main Entry Point¶
extract_ir ¶
extract_ir(model: Module, example_inputs: Tuple[Any, ...], *, model_name: Optional[str] = None, strict: bool = True) -> IR
Extract IR from a PyTorch model.
This is the main entry point for IR extraction. The model should be on meta device for weight-free extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The PyTorch model to extract IR from. Should be on meta device. |
required |
example_inputs
|
Tuple[Any, ...]
|
Example inputs for tracing. Should be on meta device. |
required |
model_name
|
Optional[str]
|
Optional name for the model. If None, uses class name. |
None
|
strict
|
bool
|
If True, validate meta device and raise errors for unsupported ops. |
True
|
Returns:
| Type | Description |
|---|---|
IR
|
The extracted IR. |
Raises:
| Type | Description |
|---|---|
ExportError
|
If model export fails. |
ConversionError
|
If IR conversion fails (in strict mode). |
Example
Source code in torch_ir/__init__.py
Module List¶
| Module | Description |
|---|---|
| IR Data Structures | TensorMeta, OpNode, IR |
| Exporter | export_model, ExportError |
| Converter | IRConverter, ConversionError, convert_exported_program |
| Executor | IRExecutor, execute_ir, ExecutionError |
| Serializer | serialize_ir, save_ir, load_ir, IRSerializer |
| Verifier | verify_ir, verify_ir_with_state_dict, IRVerifier |
| Weight Loader | load_weights, WeightLoader, WeightLoadError |
| Ops | register_op, register_executor |
| Visualize | ir_to_mermaid, generate_op_distribution_pie |