🧬 Self-Comp: The Self-Evolving AI Compiler
Inspiration
We were fascinated by the idea of systems that could improve themselves without retraining or human intervention. Inspired by Karpathy’s concept of Context Engineering and biological evolution, we set out to build an AI that rewrites and optimizes its own code — safely, autonomously, and completely offline. We wanted to see if we could make code itself learn.
What We Learned
Through this project, we learned how to build self-referential, context-driven programs that evolve intelligently.
We explored:
- How rule-based code mutation and benchmarking can replace fine-tuning.
- How to engineer guarded self-improvement loops that balance creativity with safety.
- How to treat context as a living computational environment rather than static text.
How We Built It
Our system runs a continuous “self-compilation” cycle:
- Generate candidate diffs using domain-specific AST transformation rules (no APIs).
- Benchmark each candidate on deterministic workloads (like contiguous subarray optimization).
- Evaluate and accept candidates only if they pass correctness and improve performance.
- Visualize progress through a Streamlit dashboard showing score/runtime evolution and layer-by-layer improvement.
The project is fully offline and modular:
- 🧩
selfcomp/engine/evolve.py: orchestrates generations and benchmarking - ⚙️
selfcomp/editors/ruleset.py: domain-aware AST transforms for code mutation - 📊
bench/suite.yaml: defines workloads and scoring rules - 🌈
ui/viewer.py: interactive dashboard showing score, runtime, and strategy lineage
Challenges
- Exploration vs. Safety: letting code rewrite itself without breaking correctness required extensive guardrails and static checks.
- Offline Autonomy: achieving meaningful evolution without external APIs pushed us to design rule-based “cognitive loops.”
- Observability: understanding the improvement process led us to build a full visual analytics layer to interpret learning dynamics.
Result
After multiple overnight runs, our system began showing measurable performance improvements over successive generations — learning to optimize itself through structured evolution.
It’s not just “AI writing code,” it’s code learning to rewrite itself intelligently.
“The next frontier of AI isn’t larger models—it’s systems that can teach themselves to improve.”
Log in or sign up for Devpost to join the conversation.