A compact C engine running token-for-token identical LLMs.
Project details
Bytesized is a highly efficient C engine, only 2,946 bytes, designed to run the SmolLM2-135M model. Achieving exact token matching with Hugging Face transformers, it can be stored within a QR code. Perfect for developers looking for a lightweight solution without sacrificing performance.
bytesized: A Compact and Efficient C Engine for SmolLM2-135M
Overview
The bytesized project features a 2,946-byte C program capable of running SmolLM2-135M, an actual language model (LLM) that outputs tokens precisely matching those generated by Hugging Face transformers. The program directly utilizes the model.safetensors and tokenizer.json files without requiring any conversion. Its compact size allows it to fit within a single QR code, showcasing the potential of minimalistic programming.

The entire program encapsulated as a QR code.
Getting Started
To retrieve and execute the engine, make sure to follow the instructions below. Note that smol, an optional Python front-end, is available for running the binary and rendering the output, though it is not included within the minimal engine size:
zbarimg --raw --oneshot -Sbinary qr.png > final && chmod +x final
Usage
Running the engine is straightforward. The command format is as follows:
/path/to/bin/final "prompt" [n_tokens]
For example, using the prompt "The cat sat":
/path/to/final "The cat sat" 50
Below is a sample output:
$ ./final "The cat sat" 50
╭──────────────────────────────────────────────────────────╮
│ ✻ smol │
│ │
│ engine 2,946 bytes of C │
│ model SmolLM2-135M, unmodified safetensors │
│ decode greedy, matches HF transformers token for token │
╰──────────────────────────────────────────────────────────╯
Technical Specifications
Technical Process
The development process involved rigorous optimization, systematically reducing size while maintaining functionality:
Future Developments
Potential avenues for enhancement include:
Conclusion
The bytesized engine exemplifies the convergence of compact programming and powerful AI capabilities, providing users a remarkable tool for running LLMs with minimal resources while ensuring correctness and efficiency.
Comments
0Start the conversation
Share the first comment.