torch_to_nnef.torch_graph.ir_op
Abstractions used in torch_to_nnef internal graph Operations IR.
(decoupled from PyTorch and NNEF)
The goal is that these elements are: - extracted/parsed from PyTorch graph operations - translated to NNEF graph operations
Classes:
| Name | Description |
|---|---|
InputsAlignBetweenAtenAndTorch |
Mapping inputs between Python |
TorchOp |
|
InputsAlignBetweenAtenAndTorch
Mapping inputs between Python torch.$1 and cpp aten::$2.
Because function arguments are not 1 to 1
Methods:
| Name | Description |
|---|---|
aten_logspace |
|
aten_trilu_indices |
|
aten_vander |
|
aten_window_constant |
|
aten_logspace
staticmethod
aten::logspace(start, end, steps, base, *, dtype, ...).
First four are positional; the rest are keyword-only on the aten op.
aten_trilu_indices
staticmethod
aten::{tril,triu}_indices(row, col, offset, *, dtype, ...).
Only row / col / offset are positional; the rest are
keyword-only on the aten op. Trim the tail and lift dtype
(kept; layout / device / pin_memory are dropped since trace-
time evaluation doesn't need them).
aten_vander
staticmethod
aten::vander(self, N, increasing).
N may be None for the default (= len(self)); torch's
signature accepts None directly so we forward as-is.
TorchOp
dataclass
TorchOp(kind: str, module_path: str, inputs: List[Data], outputs: List[TtupleOrVar], scope: str, op_ref: Optional[Callable], call_name: Optional[str])
Methods:
| Name | Description |
|---|---|
call_op |
Produce operation output based on traced inputs with real torch call. |
output_aliases_constant_input |
Detect view-like results derived from constant inputs. |
realise_output_type_and_size |
Trace output and try to find type shape and constant realisation. |
update_call_op_arg_kwargs |
Custom adaptation to call aten fn with torch exposed py fn. |
call_op
Produce operation output based on traced inputs with real torch call.
This operation call is done via self.args arguments (for now). Which means that we need to have all args needed in parameters order, following at least 1 underling torch operation signature.
NOTE: we use a different approach than original torch.onnx which pass parameter by keyword arguments, this is due to the fact that we are not aware of argument name being provided in exported graph ( from what we understand torch.onnx solve this via explicit rerouting of all signatures, which might be a bit bulky in most case ).
output_aliases_constant_input
Detect view-like results derived from constant inputs.
These outputs should keep shape/dtype metadata, but should not be
recorded as new constants. Otherwise a graph like Granite MoE's packed
expert weight selects serializes every expert slice as an independent
tensor in addition to the original packed parameter.
realise_output_type_and_size
Trace output and try to find type shape and constant realisation.