Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

Lyra-326M

A 326M-parameter decoder-only Transformer trained from scratch on 6.4B tokens, on a single NVIDIA RTX 3060 Ti (8 GB VRAM), by a 14-year-old in Serbia.

This repository contains the complete pipeline: data streaming, pretraining, supervised fine-tuning (SFT), and the custom terminal chat interface.

Model Weights:

The Build

  • Pretraining (PTL-1): 195,312 steps on a mixture of FineWeb-Edu (70%), Cosmopedia v2 (20%), and Python-Edu (10%). Reached a validation loss of 2.32 nats (perplexity 10.19).
  • SFT (Second Voice): ~78k examples using length-bucketed batches and assistant-only loss masking. Taught the base model to answer questions, refuse gracefully, and stop rambling.
  • Hardware: One RTX 3060 Ti, 32 GB system RAM. Sustained ~10,000 tok/s during pretraining. Total wall-clock time: ~180 hours. Total energy: ~57 kWh.

Repository Structure

Lyra/
├── model.py              # Custom GPT architecture (RMSNorm, SwiGLU, QK-norm, residual scaling)
├── data.py               # Streaming pretraining data builder (crash-safe, zero-copy memmap)
├── train.py              # Pretraining loop with custom TUI dashboard and VRAM management
├── sft_data.py           # SFT corpus builder (normalizes schemas, applies loss masks)
├── instruct.py           # SFT training loop with bucketed batching
├── chat.py               # Ollama-style terminal chat interface with live context gauges
├── generate.py           # One-shot text continuation for the base model
├── pretrain_test.py      # 9-prompt sanity check for the base model
├── tools/
│   └── export_release.py # Strips optimizer states, dedupes tied weights, exports safetensors
├── docs/
│   ├── architecture.md   # Deep-dive technical writeup and failure ledger
│   ├── index.html        # Interactive documentation site
│   ├── style.css
│   └── main.js
└── data/
    └── sft/
        └── lyra_sft.jsonl # The custom 1,000-example persona/identity dataset

Running Locally

You do not need to train this from scratch to use it. Download the instruct weights from Hugging Face and run the chat interface.

# Clone the repository
git clone https://huggingface.co/luka0x12/Lyra-326M-Instruct
cd Lyra-326M-Instruct

# Install dependencies
pip install torch sentencepiece safetensors numpy

# Start chatting
python chat.py

The Failure Ledger

Building a training pipeline from scratch on constrained hardware means hitting every edge case in PyTorch. The docs/architecture.md file contains a detailed ledger of the 9 major bugs encountered during this project, including:

  1. The 8x Loss Illusion: The dashboard displayed a loss of 35.2 because the GPU accumulator summed micro-steps but the readout only divided by optimizer steps. The model was fine; the math in the UI was wrong.
  2. The Resume Rewind: best.pt only saved when validation improved. Restarting with --resume loaded a checkpoint from 20,000 steps ago, silently throwing away 10 hours of compute. Fixed by introducing a separate last.pt progress tracker.
  3. CUDAGraph Collisions: torch.compile(mode="max-autotune") enables CUDA graphs, which require static memory addresses. Combined with gradient accumulation and set_to_none=True, the backward pass allocated new gradient tensors inside the captured graph, causing instant OOM crashes.
  4. The "Drunk" Base Model: At 1.5B tokens, the base model output pure semantic drift (e.g., claiming the capital of France was Luxembourg). This wasn't a bug; it was the expected intermediate state of a model that had learned syntax but not yet bound sparse factual entities.

License

  • Code: Apache-2.0. Use it, fork it, build your own.
  • Weights: CC-BY-NC-4.0. The SFT mixture includes DailyDialog (CC BY-NC-SA 4.0) and non-commercial subsets of Tulu-3, so the final weights cannot be used for commercial products.
  • Custom SFT Data (lyra_sft.jsonl): CC0 (Public Domain). Do whatever you want with the identity dataset.

关于 About

A 326M-parameter decoder-only Transformer trained from scratch on 6.4B tokens using a single RTX 3060 Ti. Includes the full pretraining, SFT, and inference pipeline.

语言 Languages

Python100.0%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
12
Total Commits
峰值: 12次/周
Less
More

核心贡献者 Contributors