โ† AI Tools
FrameworkIntermediate

NanoEuler

A GPT-2-level educational language model implemented in pure C/CUDA without using any frameworks.

NanoEuler is a GPT-2-level language model implementation released in 2026 by developer Vincenzo (JustVugg). It is an educational and research LLM that directly implements backpropagation, tokenizers, and attention entirely in pure C and CUDA, without relying on frameworks like PyTorch or TensorFlow. The project name is derived from interpreting the residual block x = x + f(x) using the forward-Euler method, reflecting the mathematical intuition that "depth is the integration time." The architecture consists of RMSNorm (pre-norm, bias-free), Rotary Position Embedding (RoPE), SwiGLU feedforward, Grouped-Query Attention (GQA), and a custom-written FlashAttention kernel, allowing a model with approximately 116M parameters to be trained on a single consumer-grade GPU. Most LLM training projects rely on PyTorch's autograd, which often leaves the backpropagation process as a black box. NanoEuler completely removes this black box and manually calculates gradients at the C level, performing double-precision validation (up to ~1e-6). Similar to assembling a car engine piece by piece to understand the principles of an internal combustion engine, NanoEuler allows one to understand all the operations of a Transformer at the bare-metal level. Inspired by Andrej Karpathy's llm.c, it differs in that it includes a byte-level BPE tokenizer implementation, multi-token prediction, and supervised fine-tuning (SFT) based on the Alpaca dataset, completing the entire pipeline from training to fine-tuning and inference in a single binary. In the field of biotechnology, the value of NanoEuler lies in the ability to completely control domain-specific small language models from the ground up. For example, by retraining the BPE tokenizer with domain-specific vocabulary such as protein sequences or SMILES chemical formulas, and pre-training with PubMed abstracts or UniProt sequence data instead of the base corpus (Project Gutenberg, FineWeb-Edu), a lab-specific small LM can be built. Because the CUDA kernel can be directly modified, it is also suitable for experimenting with custom attention patterns (e.g., a modified attention that gives weight to local interactions within a sequence). By directly controlling C/CUDA without framework overhead, it can serve as a starting point for lightweight inference optimization research on embedded devices or edge devices. However, the author explicitly states that the current generation quality is at the "fluent-ish English" level and is intended for educational and experimental purposes, not for production use.

๐Ÿ’ป System Requirements

๐Ÿง RAM

CPU-only builds are possible (for small models with ~1M parameters). For GPU models (116M), NVIDIA 8GB+ is recommended.

๐Ÿ’พStorage

Source code size in MB. The default slice of the FineWeb-Edu corpus is ~1GB, and Project Gutenberg is ~tens of MB.

โšก Installation

### 4-1. Quick Start (CPU)

```bash
git clone https://github.com/JustVugg/nanoeuler.git
cd nanoeuler
make check          # Gradient verification
make                # Build training binary
./nanoeuler train   # Train a small model (~1M parameters)
./nanoeuler chat    # Interactive REPL
```

### 4-2. GPU Build and Training

```bash
cd cuda
# Check the SM architecture in the Makefile (default sm_89 = Ada)
make
./nanoeuler_cuda t   # Pre-training (checkpoint every 5k steps)
./nanoeuler_cuda s   # Alpaca SFT
./nanoeuler_cuda c   # Interactive chat
./nanoeuler_cuda i   # Prompt-based generation
```

### 4-3. Data Preparation

```bash
# Download the corpus using the script in the data/ directory
# Project Gutenberg (~95 classic books), FineWeb-Edu (DuckDB CLI), Alpaca
cd data
bash download_gutenberg.sh   # Example (check the repository for the actual script name)
```

๐Ÿงฌ Bio Use Cases

๐Ÿ”ฌ

Building a Domain-Specific Small Language Model

By retraining the vocabulary of a BPE tokenizer with SMILES chemical formulas or protein 1-letter codes, and pre-training on 1 million PubMed abstracts, a domain-specific LM with approximately 116M parameters can be built on a single GPU within a few hours. By organizing domain Q&A data in the Alpaca format and applying SFT, it can be used as a prototype for specialized chatbots, such as those that answer questions about compound properties.

๐Ÿงฌ

Experimenting with Custom Attention Mechanisms

Since the CUDA kernel is directly exposed, it is possible to experiment with biologically-inspired variations of attention, such as modifying the FlashAttention logic to implement local windowed attention or position-specific weight biases. For example, a study could be conducted to implement attention decay proportional to the distance between residues in protein secondary structure prediction and measure the change in prediction accuracy compared to the existing Transformer.

๐Ÿ’Š

LLM Architecture Education and Replication Studies

In graduate courses or lab seminars, students can learn by tracing the forward/backward propagation of a Transformer line by line at the C level. The `make check` command compares and validates the numerical gradient of all parameters with the analytical gradient (~1e-6), so it is possible to empirically verify how the derivative of each RMSNorm, RoPE, SwiGLU, and GQA module is calculated.

๐Ÿ“„ Official Docs๐Ÿ™ GitHub

๐Ÿ“ Update Notes

No update notes yet.

๐Ÿงช Related Code of Life

No related Code of Life posts yet.