ml_switcheroo.compiler.ir¶
Intermediate Representation (IR).
This module defines the language-agnostic graph data structures used to represent Deep Learning models after ingestion from source code (e.g. Python/LibCST) or explicit definition.
It acts as the contract between the Frontend (Ingestion) and the Backend (Synthesis).
Classes¶
Represents a computation unit (Layer) in the graph. |
|
Represents data flow between two nodes. |
|
Language-agnostic representation of the neural network structure. |
Functions¶
|
Sorts graph nodes by dependency order. |
Module Contents¶
- class ml_switcheroo.compiler.ir.LogicalNode[source]¶
Represents a computation unit (Layer) in the graph.
- id: str¶
Unique identifier (e.g. ‘conv1’).
- kind: str¶
Operation type (e.g. ‘Conv2d’, ‘Input’, ‘Output’).
- metadata: Dict[str, str]¶
Dictionary of configuration parameters (e.g.
kernel_size=3).
- class ml_switcheroo.compiler.ir.LogicalEdge[source]¶
Represents data flow between two nodes.
- source: str¶
Source node ID.
- target: str¶
Target node ID.
- class ml_switcheroo.compiler.ir.LogicalGraph[source]¶
Language-agnostic representation of the neural network structure.
- name: str = 'Model'¶
Name of the graph model/class.
- nodes: List[LogicalNode] = []¶
Ordered list of nodes in the graph.
- edges: List[LogicalEdge] = []¶
List of directed edges between nodes.
- ml_switcheroo.compiler.ir.topological_sort(graph: LogicalGraph) List[LogicalNode][source]¶
Sorts graph nodes by dependency order.
Ensures that for every edge u -> v, u appears before v in the returned list. Handles disconnected components and cycles gracefully by appending unreachable nodes in their original definition order.
- Parameters:
graph – The logical graph to sort.
- Returns:
List of nodes in execution order.