minimind
Train a small GPT model from scratch in 2 hours — understand LLM architecture by building one. Use when: learning how LLMs work internally, training custom small language models, educational AI projects, fine-tuning experiments.
What this skill does
# MiniMind
## Overview
Train a 64M parameter GPT language model from scratch in ~2 hours on a single GPU. Understand every component of LLM architecture by building one yourself — from tokenizer training to RLHF alignment. The architecture tracks Qwen3/Qwen3-MoE, so patterns you learn here apply directly to full-scale models.
> Source: [jingyaogong/minimind](https://github.com/jingyaogong/minimind) (45k+ stars)
## Instructions
### 1. Clone and install
```bash
git clone https://github.com/jingyaogong/minimind.git
cd minimind
pip install -r requirements.txt
python download_data.py
```
### 2. Pretrain on raw text
```bash
python train_pretrain.py \
--data_path ./data/pretrain_data.jsonl \
--model_config ./config/minimind-3.yaml \
--epochs 2 \
--batch_size 32 \
--learning_rate 5e-4
```
### 3. Supervised fine-tuning (SFT)
```bash
python train_sft.py \
--pretrained_model ./checkpoints/pretrain/best.pt \
--data_path ./data/sft_data.jsonl \
--epochs 3 \
--batch_size 16 \
--learning_rate 1e-5
```
### 4. RLHF alignment (optional)
```bash
python train_dpo.py \
--model_path ./checkpoints/sft/best.pt \
--preference_data ./data/dpo_pairs.jsonl
```
Multiple alignment methods: DPO (simplest), PPO (classic), GRPO (DeepSeek-style).
### 5. Run inference
```bash
python inference.py --model_path ./checkpoints/dpo/best.pt
```
Or start an OpenAI-compatible API server:
```bash
python api_server.py --model_path ./checkpoints/sft/best.pt --port 8000
```
## Examples
### Example 1: Full training pipeline on a single GPU
Train a 64M parameter model from scratch on an NVIDIA RTX 3090:
```bash
git clone https://github.com/jingyaogong/minimind.git && cd minimind
pip install -r requirements.txt
python download_data.py
python train_pretrain.py # ~1h — learns language patterns
python train_sft.py # ~30min — learns to follow instructions
python train_dpo.py # ~20min — aligns with human preferences
python inference.py --model_path ./checkpoints/dpo/best.pt
# > What is machine learning?
# Machine learning is a subset of artificial intelligence where systems
# learn patterns from data rather than being explicitly programmed...
```
Total cost: ~$3 in GPU rental or ~2 hours on your own hardware.
### Example 2: LoRA fine-tuning for a specific domain
Fine-tune the base model on medical Q&A data using LoRA (parameter-efficient):
```bash
python train_lora.py \
--base_model ./checkpoints/sft/best.pt \
--data_path ./data/medical_qa.jsonl \
--lora_rank 8 \
--lora_alpha 16
```
SFT data format:
```json
{
"conversations": [
{"role": "user", "content": "What are the symptoms of Type 2 diabetes?"},
{"role": "assistant", "content": "Common symptoms include increased thirst, frequent urination, blurred vision, slow-healing wounds, and unexplained weight loss..."}
]
}
```
### Example 3: Python API for programmatic inference
```python
from model import MiniMindModel
from tokenizer import MiniMindTokenizer
model = MiniMindModel.from_pretrained("./checkpoints/sft/best.pt")
tokenizer = MiniMindTokenizer("./tokenizer/tokenizer.model")
prompt = "Explain how attention works in transformers"
input_ids = tokenizer.encode(prompt)
output = model.generate(input_ids, max_new_tokens=256, temperature=0.7)
print(tokenizer.decode(output))
```
## Guidelines
- **GPU requirements:** 64M model needs ~4GB VRAM (RTX 3090 recommended); even a GTX 1660 works (slower)
- **MoE variant** available at 198M total / 64M active parameters — needs ~8GB VRAM
- **Pre-built datasets** on HuggingFace: pretrain corpus, SFT pairs, DPO preference pairs, tool-use examples
- **Multi-GPU** supported via DDP and DeepSpeed for larger variants
- **Not production-grade** — MiniMind is an educational tool. It won't match GPT-4, but teaches you every component: tokenizer, embeddings, attention, FFN, training dynamics, RLHF
- Architecture uses GQA attention, SwiGLU FFN, RMSNorm, and RoPE with YaRN — matching production model patterns
## References
- [GitHub: jingyaogong/minimind](https://github.com/jingyaogong/minimind)
- [HuggingFace Collection](https://huggingface.co/collections/jingyaogong/minimind)
- [MiniMind-V (Vision)](https://github.com/jingyaogong/minimind-v)
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.