TorchLean IR to PyTorch #
Tutorial: TorchLean → IR (NN.IR.Graph) → emitted PyTorch code.
Run:
scripts/lake.sh exe torchlean torch_ir_pytorch --arch linear > exported_model.py
scripts/lake.sh exe torchlean torch_ir_pytorch --arch mlp > exported_model.py
scripts/lake.sh exe torchlean torch_ir_pytorch --arch sum > exported_model.py
scripts/lake.sh exe torchlean torch_ir_pytorch --arch autoencoder > exported_model.py
scripts/lake.sh exe torchlean torch_ir_pytorch --arch mha > exported_model.py
scripts/lake.sh exe torchlean torch_ir_pytorch --arch mha-mask > exported_model.py
scripts/lake.sh exe torchlean torch_ir_pytorch --arch transformer > exported_model.py
Then:
python3 exported_model.py
The command emits the selected architecture and initialized parameters; it does not train them. Python execution requires PyTorch. Exporting or running the file does not by itself prove TorchLean/PyTorch numerical parity.
Command name used in diagnostics and by the top-level example runner.
Instances For
Architectures #
Instances For
A 2 -> 3 -> 1 MLP with ReLU, the smallest architecture with a nonlinearity.
Instances For
A bare reduction, included because it exports to torch.sum rather than to a module.
Instances For
A 3 -> 2 -> 3 autoencoder with a tanh bottleneck.
Instances For
Two-head self-attention over a length-four sequence of width eight, with an optional mask.
For causal attention, pass some (Spec.causalMask 4); position i then attends only to j ≤ i.
Instances For
A full encoder block: attention, residual, LayerNorm, ReLU feed-forward, residual, LayerNorm.
Deliberately tiny (one head of width two) so the emitted Python stays readable. We choose ReLU explicitly because the verifier IR does not yet lower GELU faithfully.
Instances For
CLI parsing #
Export driver #
Lower a sequential model and its initial state, then write generated Python to stdout.