Language Model Trained to Behave Like a Terminal
The author fine-tuned a 360-million-parameter language model based on Qwen2.5-Coder-0.5B to simulate terminal behavior without running an actual shell. Rather than executing commands, the model predicts how a terminal screen changes in response to each keypress. It demonstrated the ability to create files, run vim and tmux, play snake, and maintain state across multiple user interactions.
The training employed several technical innovations. The model treats terminals as grids of characters using a minimal 333-token vocabulary—256 byte values, 64 row tokens, and special operations. Training data consisted of 336,000 episodes from real terminal sessions recorded in Docker containers, amounting to roughly 2 billion tokens. A key optimization was a COPY operation that reduces scrolling costs by referencing previous row states rather than rewriting them, cutting per-row token usage from roughly 96 to 3 tokens.
To improve consistency over longer sessions, the author implemented a training approach inspired by DAgger where the model learned from its own prediction errors. When the model’s output diverged from recorded sessions, corrections were generated and used as training examples—about a third of sampled sessions produced useful corrections, which were applied across three rounds. This technique was among the more effective training improvements; combined with additional data, it contributed to reaching 38/47 on a PresetBench benchmark (from 24/47 initially) at 4-bit quantization. The browser demo (208 MB) runs best in Chrome or Edge with WebGPU.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.