Lyra-326M-Instruct
Supervised fine-tune of Lyra-326M. Same 326M architecture, taught to answer instead of continue.
Trained from scratch (pretrain + SFT) on one RTX 3060 Ti by a 14-year-old. Full pipeline, data builder, trainer, and failure ledger at github.com/luka0x12/Lyra.
Quick Start
# 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
That's it. The chat interface loads the model, shows a context gauge, and lets you talk to Lyra interactively.
Python API
import json
import torch
from safetensors.torch import load_file
from model import GPT, GPTConfig
from lyra_tokenizer import Tokenizer
# Load model
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")
tok = Tokenizer("tok.model")
# Build a chat prompt
prompt = "<|user|>What is the capital of France?<|assistant|>"
ids = tok.encode(prompt)
idx = torch.tensor([ids], dtype=torch.long, device="cuda")
# Generate response
with torch.no_grad():
for _ in range(100):
logits, _ = model(idx[:, -1024:])
next_token = torch.argmax(logits[0, -1, :])
if next_token in (tok.eos_token_id, tok.user_token_id):
break
idx = torch.cat([idx, next_token.view(1, 1)], dim=1)
response = tok.decode(idx[0, len(ids):].tolist())
print(response) # "Paris."
Why trust_remote_code=True?
Lyra uses a custom architecture with features not in the standard transformers library:
- QK-Norm: Per-head RMSNorm on queries and keys
- Residual scaling:
1/sqrt(24)on every branch - Custom chat tokens:
<|user|>(id 3),<|assistant|>(id 4),<eos>(id 2)
You need the model.py and lyra_tokenizer.py files from this repository. When you clone the repo, they're included and everything works. If you're using a framework that supports trust_remote_code=True, it will fetch these files automatically.
Chat Format
Lyra expects prompts in this exact format:
<|user|>Your question here<|assistant|>
The model generates text after <|assistant|> and stops at <eos> (id 2) or when it sees another <|user|> token. Multi-turn conversations concatenate turns:
<|user|>Hi<|assistant|>Hello! How can I help?<eos><|user|>What is 2+2?<|assistant|>
The chat.py script handles this automatically, including context window management.
SFT Details
- Base model: Lyra-326M (pretrained on 6.4B tokens)
- Corpus: ~78k examples from:
- tulu-3-sft-mixture (30k, general instruction following)
- OpenOrca (18k, reasoning traces)
- SciQ (9k, science QA)
- DailyDialog (9k, conversational register)
- python_code_instructions_18k_alpaca (4k, code snippets)
- Custom Lyra persona set (1k, identity/limits/honesty)
- Loss masking: Assistant tokens only (system/user masked to weight 0)
- Optimizer: AdamW (Ξ²β=0.9, Ξ²β=0.95, weight_decay=0.0)
- Learning rate: 5e-5 peak, 3% warmup, cosine decay to 5e-6
- Batch size: ~2048 tokens per micro-batch, 4 accumulation steps
- Epochs: 3
- Context: Length-bucketed (128, 256, 384, 512, 768, 1024), one example per row
- Precision: bf16 autocast, fp32 master weights
- Checkpointing: Full activation checkpointing
- Duration: ~2-3 hours on RTX 3060 Ti
Final validation loss: ~1.5 nats on assistant tokens
Example Conversations
Greeting:
you > hello
lyra > Hi! How can I help you today?
Identity:
you > who are you?
lyra > I'm Lyra, a text language model with about 326 million parameters.
Factual question:
you > what is the capital of France?
lyra > Paris.
What This Model Is Bad At
- Factual reliability: It will confabulate entities, dates, and citations. Verify anything that matters.
- Complex reasoning: Multi-step math, logic puzzles, and nuanced analysis often (more likely always) fail. It's 326M parameters.
- Long context: 1,024 tokens is the hard limit. Longer inputs get truncated.
- Consistency: Ask the same question twice, get different answers. Temperature and top-k sampling introduce variance.
- Code execution: It can write code (poorly) but cannot run it. Treat all code as untested drafts.
- Non-English: English only. Other languages produce garbage.
- Memory: No persistence between sessions. Each conversation starts fresh.
Realistic use cases: Short Q&A, text rewriting, simple explanations, brainstorming, basic code snippets. Not a replacement for current LLMs.
Interactive Chat Features
The included chat.py provides:
- Live context gauge: Shows how many of the 1024 tokens are used
- Multi-turn history: Automatically manages conversation context
- Streaming output: Tokens appear as they're generated
- Sampling controls: Adjust temperature, top-k, repetition penalty
- Model switching:
/model path/to/other/releaseto compare checkpoints - Conversation export:
/save transcript.jsonto export chat history
Type /help in the chat for all commands.
File Structure
Lyra-326M-Instruct/
βββ 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
βββ chat.py # Interactive chat interface
βββ chat.json # Default chat settings
βββ README.md # This file
βββ LICENSE # CC-BY-NC-4.0
Comparison to Base Model
| Aspect | Lyra-326M (base) | Lyra-326M-Instruct |
|---|---|---|
| Training | Next-token prediction on 6.4B tokens | SFT on ~78k instruction examples |
| Behavior | Continues text | Answers questions |
| Prompt format | Raw text | <|user|>...<|assistant|> |
| Stopping | Runs until max_new or EOS | Stops at EOS or next user turn |
| Use case | Text completion, few-shot prompting | Chat, Q&A, instruction following |
Citation
@misc{lyra326m_instruct,
author = {Luka (luka0x12)},
title = {Lyra-326M-Instruct: Supervised fine-tuning of a from-scratch 326M transformer},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/luka0x12/Lyra-326M-Instruct}
}
License & Provenance
Weights: CC-BY-NC-4.0 (non-commercial use only)
Code: Apache-2.0 (see GitHub repo)
SFT data sources:
- tulu-3-sft-mixture (ODC-BY, some subsets NC)
- OpenOrca (MIT)
- SciQ (CC BY-SA 4.0)
- DailyDialog (CC BY-NC-SA 4.0) β non-commercial
- python_code_instructions_18k_alpaca (Apache-2.0)
- Custom persona set (created by Luka, all rights reserved)
The NC license on weights reflects DailyDialog's CC BY-NC-SA 4.0 license and non-commercial clauses in some tulu-3 subsets. Verify before any commercial use.
Acknowledgments
SFT pipeline inspired by the SmolLM and Tulu-3 training recipes. Chat interface design influenced by Ollama's UX. Built with extensive debugging help from open-source documentation and community resources.
- Downloads last month
- -