I built a compiler that turns computation graphs into the weights of a vanilla transformer — no training anywhere [P]
Summary
A new compiler, "torchwright", has been developed to convert computation graphs defined in ordinary Python directly into the weights of a vanilla transformer model. This tool generates a standard Phi-3-architecture checkpoint that can be loaded by Hugging Face without any custom code or "trust_remote_code", entirely bypassing the traditional training process. The project aims to investigate the inherent algorithmic expressiveness of transformers, separate from their learning capabilities. Unlike previous approaches like RASP and Tracr, which also compile programs into transformer weights, "torchwright" prioritizes using standard Python for graph definition and targeting a stock transformer architecture for seamless integration. The repository includes twelve runnable examples demonstrating its functionality.
Key takeaway
For Machine Learning Engineers exploring model efficiency or interpretability, this compiler offers a novel approach to embed deterministic computations directly into transformer architectures. You can now define specific algorithms in Python and compile them into Phi-3 weights, potentially reducing training overhead for certain tasks or integrating operations that are difficult for neural networks to learn efficiently. Consider experimenting with "torchwright" to inject "frozen tools" or complex, non-learnable functions into your models, enhancing their capabilities without extensive retraining.
Key insights
A compiler directly generates vanilla transformer weights from Python computation graphs, demonstrating inherent algorithmic expressiveness without training.
Principles
- Transformers possess inherent algorithmic expressiveness.
- Manual design complements learned components in ML.
- Decoupling learned and deterministic ops aids analysis.
Method
Define a computation graph in ordinary Python, then compile it to generate weights for a standard Phi-3-architecture transformer, loadable directly via Hugging Face.
In practice
- Inject static, complex computations into networks.
- Integrate operations like square root directly into models.
- Hybridize custom-weight models with trained networks.
Topics
- Transformer Architecture
- Computation Graphs
- Model Compilation
- Phi-3 Model
- Hugging Face
- Untrained Models
Code references
Best for: Research Scientist, AI Scientist, Machine Learning Engineer, AI Architect
Related on AIssential
See Counsel's argued verdicts on the open AI decisions leaders are weighing →
Editorial summary, takeaway, and curation by AIssential. Original article published by Machine Learning.