Executor¶
Module that executes IR graphs with actual weights.
executor ¶
IR Executor for running IR graphs with actual weights.
ExecutionError ¶
Bases: Exception
Raised when IR execution fails.
TensorRegistry ¶
IRExecutor ¶
IRExecutor(ir: IR, weights: Optional[Dict[str, Tensor]] = None, constants: Optional[Dict[str, Tensor]] = None)
Executes an IR graph with actual weight tensors.
Typical usage::
executor = IRExecutor(ir)
executor.load_weights_from_state_dict(state_dict)
outputs = executor.execute((input_tensor,))
Initialize the executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ir
|
IR
|
The IR graph to execute. |
required |
weights
|
Optional[Dict[str, Tensor]]
|
Optional pre-loaded weights. If None, must call load_weights(). |
None
|
constants
|
Optional[Dict[str, Tensor]]
|
Optional lifted tensor constants. When provided, these
override |
None
|
Source code in torch_ir/executor.py
load_weights ¶
Load weights from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the weight file (.pt or .safetensors). |
required |
load_weights_from_state_dict ¶
Use an existing state dict as weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
Dict[str, Tensor]
|
The state dict to use. |
required |
execute ¶
Execute the IR graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Tuple[Tensor, ...]
|
Input tensors matching graph_inputs. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, ...]
|
Output tensors matching graph_outputs. |
Raises:
| Type | Description |
|---|---|
ExecutionError
|
If execution fails. |
Source code in torch_ir/executor.py
execute_ir ¶
execute_ir(ir: IR, inputs: Tuple[Tensor, ...], weights: Optional[Dict[str, Tensor]] = None, weights_path: Optional[Union[str, Path]] = None, constants: Optional[Dict[str, Tensor]] = None) -> Tuple[torch.Tensor, ...]
Execute an IR graph (convenience function).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ir
|
IR
|
The IR graph to execute. |
required |
inputs
|
Tuple[Tensor, ...]
|
Input tensors. |
required |
weights
|
Optional[Dict[str, Tensor]]
|
Pre-loaded weights dict. |
None
|
weights_path
|
Optional[Union[str, Path]]
|
Path to weight file (alternative to weights). |
None
|
constants
|
Optional[Dict[str, Tensor]]
|
Optional lifted tensor constants for meta-device-extracted IRs.
See :class: |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, ...]
|
Output tensors. |
Raises:
| Type | Description |
|---|---|
ExecutionError
|
If execution fails. |
ValueError
|
If neither weights nor weights_path is provided. |