Lyra-326M (Base)
A 326M-parameter decoder-only Transformer trained from random initialization on 6.4B tokens, on a single NVIDIA RTX 3060 Ti (8 GB VRAM), by a 14-year-old in Serbia.
This is the base checkpoint. It continues text. For the assistant version, see Lyra-326M-Instruct.
Quick Start
# Clone the repository (includes model.py, tokenizer, and chat interface)
git clone https://huggingface.co/luka0x12/Lyra-326M-base
cd Lyra-326M-base
# Install dependencies
pip install torch sentencepiece safetensors numpy
# Generate text
python generate.py --prompt "The capital of France is"
Python API
import json
import torch
from safetensors.torch import load_file
from model import GPT, GPTConfig
from lyra_tokenizer import Tokenizer
# Load config and weights
config = json.load(open("config.json"))
tied = config.pop("tied_keys", [])
config.pop("torch_dtype", None)
model = GPT(GPTConfig(**config))
model.load_state_dict(load_file("model.safetensors"), strict=False)
model.eval().to("cuda")
# Load tokenizer
tok = Tokenizer("tok.model")
# Generate
prompt = "The capital of France is"
ids = tok.encode(prompt)
idx = torch.tensor([ids], dtype=torch.long, device="cuda")
with torch.no_grad():
for _ in range(50):
logits, _ = model(idx[:, -1024:])
next_token = torch.argmax(logits[0, -1, :])
if next_token == tok.eos_token_id:
break
idx = torch.cat([idx, next_token.view(1, 1)], dim=1)
print(tok.decode(idx[0].tolist()))
Why trust_remote_code=True?
Lyra uses a custom architecture not yet integrated into the Hugging Face transformers library:
- QK-Norm: Per-head RMSNorm on queries and keys before attention
- Residual scaling: Each residual update scaled by
1/sqrt(24) - Learned absolute positions: Not RoPE or ALiBi
This means you cannot load it with AutoModelForCausalLM.from_pretrained() without the custom model.py file included in this repository. When you clone this repo, the code is already present and works out of the box.
If you're integrating Lyra into a framework that supports remote code execution (like transformers with trust_remote_code=True), it will automatically pull model.py and lyra_tokenizer.py from this repository.
Architecture
| Component | Value |
|---|---|
| Parameters | 326,160,384 (tied output head) |
| Layers | 24 |
| Attention heads | 16 (head dim 64) |
| Hidden width | 1,024 |
| SwiGLU intermediate | 2,816 |
| Context window | 1,024 tokens (hard ceiling) |
| Vocabulary | 16,384 (SentencePiece BPE + byte fallback) |
| Position encoding | Learned absolute embeddings |
| Normalization | RMSNorm (pre-norm + QK-norm) |
| Residual scaling | 1/β24 on every branch update |
| Output head | Tied to token embeddings |
Training
- Corpus: 70% FineWeb-Edu, 20% Cosmopedia v2, 10% Python-Edu (6.4B tokens total)
- Optimizer: AdamW (Ξ²β=0.9, Ξ²β=0.95, weight_decay=0.1)
- Learning rate: 6e-4 peak, 2000-step warmup, cosine decay to 6e-5
- Batch size: 4 micro-batches Γ 8 accumulation steps = effective batch 32,768 tokens
- Precision: bf16 autocast, fp32 master weights
- Checkpointing: Full activation checkpointing (stride 1)
- Compilation:
torch.compile(mode="default") - Throughput: ~10,000 tok/s sustained on RTX 3060 Ti
- Wall clock: ~178 hours (7.4 days)
- Energy:
57 kWh (β¬8.50 at β¬0.15/kWh)
Final validation loss: 2.3213 nats (perplexity 10.19)
What This Model Is Bad At
Stated plainly, because honesty is the point:
- Factual accuracy: It will confabulate entities, dates, and citations with fluent grammar. "The capital of France is Paris" works; obscure facts do not.
- No instruction following: This is a base model. It continues text, it doesn't answer questions. Use Lyra-326M-Instruct for chat.
- 1,024 token hard limit: Learned positions mean no extrapolation. Inputs longer than 1024 tokens will error or truncate.
- English only: The corpus is English. Other languages will produce garbage.
- No memory: Weights are frozen. No learning from conversations.
- No tools: No browsing, no code execution, no file access, no live data.
This is a learning project, not a production model. The value is in the documented pipeline, not the weights.
File Structure
Lyra-326M/
βββ config.json # Architecture config
βββ model.safetensors # Weights (bf16, ~0.65 GB)
βββ tok.model # SentencePiece tokenizer
βββ tok.vocab # Tokenizer vocabulary
βββ model.py # Custom GPT architecture
βββ lyra_tokenizer.py # Tokenizer wrapper
βββ generate.py # Text generation script
βββ pretrain_test.py # Evaluation script
βββ README.md # This file
βββ LICENSE # CC-BY-NC-4.0
Citation
@misc{lyra326m,
author = {Luka (luka0x12)},
title = {Lyra-326M: From-scratch pretraining of a 326M transformer on one RTX 3060 Ti},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/luka0x12/Lyra-326M-base}
}
License & Provenance
Weights: CC-BY-NC-4.0 (non-commercial use only)
Code: Apache-2.0 (see GitHub repo)
Pretraining data:
- FineWeb-Edu (ODC-BY)
- Cosmopedia v2 (ODC-BY)
- Python-Edu (ODC-BY)
All pretraining sources are permissive. The NC license on weights reflects the inclusion of non-commercial SFT data in the instruct model (DailyDialog: CC BY-NC-SA 4.0, tulu-3 subsets with NC clauses).
Acknowledgments
Built with guidance from open-source documentation, the SmolLM training recipe, and countless debugging sessions. Special thanks to the Hugging Face datasets team for making high-quality pretraining corpora accessible.
- Downloads last month
- 561