ml_switcheroo.compiler.backends.python¶
Python Source Code Backend.
This module implements a Compiler Backend that synthesizes Python source code from the Logical Graph Internal Representation via LibCST.
Classes¶
Transformer to swap __init__ and forward methods in a target class. |
|
Synthesizes a Python CST Module from a LogicalGraph. |
Module Contents¶
- class ml_switcheroo.compiler.backends.python.ClassBodyReplacer(target_class: str, new_init: libcst.FunctionDef, new_forward: libcst.FunctionDef)[source]¶
Bases:
libcst.CSTTransformerTransformer to swap __init__ and forward methods in a target class.
- target_class¶
- new_init¶
- new_forward¶
- found = False¶
- class ml_switcheroo.compiler.backends.python.PythonBackend(framework: str = 'torch', semantics: Any = None)[source]¶
Bases:
ml_switcheroo.compiler.backend.CompilerBackendSynthesizes a Python CST Module from a LogicalGraph.
- framework = 'torch'¶
- compile(graph: ml_switcheroo.compiler.ir.LogicalGraph) str[source]¶
Compiles the Logical Intermediate Representation (IR) into a target artifact.
- Parameters:
graph (LogicalGraph) – The intermediate representation of the model structure.
- Returns:
The compiled output (e.g., source code string, binary buffer, or AST).
- Return type:
Any
- generate(graph: ml_switcheroo.compiler.ir.LogicalGraph, class_name: str = 'SwitcherooNet', original_tree: libcst.Module | None = None) str[source]¶