train-llm-from-scratch
Route train-llm-from-scratch workflows for from-scratch PyTorch LLM pretraining, SFT, reward modeling, DPO/ORPO/KTO, PPO, GRPO/RLVR, evaluation, chat, configs, UI, and data validation.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- train-llm-from-scratch
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Route train-llm-from-scratch workflows for from-scratch PyTorch LLM pretraining, SFT, reward modeling, DPO/ORPO/KTO, PPO, GRPO/RLVR, evaluation, chat, configs, UI, and data validation.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/installation.md4.2 KB
- 参考文档references/repo-provenance.md2.7 KB
- 参考文档references/repo-routing-metadata.json598 B
- 参考文档references/troubleshooting.md4.6 KB
- 脚本scripts/check_environment.py5.6 KB
- 脚本scripts/inspect_checkpoint.py4.5 KB
03 SKILL.md 正文
train-llm-from-scratch
Use this repo skill when a task involves the train-llm-from-scratch project: a
pure-PyTorch educational LLM stack covering raw text tokenization, decoder-only
Transformer pretraining, SFT, reward modeling, DPO/ORPO/KTO, PPO, GRPO/RLVR,
GSM8K evaluation, chat, JSON configs, and a Streamlit control panel.
Start Here
- If the task may depend on repo freshness, read
references/repo-provenance.md. - For setup, optional extras, backend expectations, and import checks, read
references/installation.md. - Run
scripts/check_environment.pywhen you need a safe import/backend smoke check in the user's environment. - If checkpoint contents or model dimensions are unclear, run
scripts/inspect_checkpoint.pybefore loading the model. - Route to the narrowest sub-skill below. Keep this root as the router; do not bury detailed stage work here.
Sub-Skill Routing
| User task | Read |
|---|---|
| Prepare or validate Pile HDF5, packed SFT HDF5, preference JSONL, RL prompt JSONL, arithmetic curriculum, tokenizer/mask/data-loader issues | sub-skills/data-preparation/SKILL.md |
| Inspect the custom Transformer, plan base pretraining, choose legacy vs modern pretraining, DDP/bf16, memory, checkpoint/resume, tiny model smoke | sub-skills/model-pretraining/SKILL.md |
| Run or debug SFT, reward model, DPO/ORPO/KTO, PPO, GRPO/RLVR, rollout/log-probs, KL/reward metrics, post-training pipeline sequencing | sub-skills/post-training-rlhf/SKILL.md |
| Evaluate on GSM8K, build stage tables, chat with checkpoints, choose raw vs chat mode, sampling controls, answer parsing/verifier behavior | sub-skills/evaluation-chat/SKILL.md |
| Edit JSON configs, use smoke configs, inspect CLI override precedence, operate the Streamlit UI, inspect metrics JSONL/job logs | sub-skills/configuration-ui/SKILL.md |
Install And Import Baseline
The package metadata exposes import roots config, data_loader, src, and
ui. A typical editable install from a compatible checkout is:
pip install -e .
pip install -e ".[train]" # datasets + optional wandb for data/post-training
pip install -e ".[ui]" # streamlit + pandas + altair for the control panel
pip install -e ".[docs]" # mkdocs tooling, only for docs-site work
For the selected training workflows, use a PyTorch build that matches the machine. Full training is CUDA-oriented; CPU smoke configs are useful for parser, config, and algorithm checks but do not verify large CUDA/bf16/DDP training.
Minimal import smoke:
python - <<'PY'
from src.models.transformer import Transformer
from src.post_training.chat_template import encode_chat, EOT_ID
ids, mask = encode_chat([
{"role": "user", "content": "What is 2+2?"},
{"role": "assistant", "content": "<answer>4</answer>"},
])
print(len(ids), len(mask), sum(mask), ids[-1] == EOT_ID)
print(Transformer(n_head=2, n_embed=16, context_length=8, vocab_size=64, N_BLOCKS=1).__class__.__name__)
PY
Common Operating Rules
- Start with smoke configs or dry-run command builders before launching long training, data downloads, or multi-GPU jobs.
- Validate data files before training. Mask/data errors silently corrupt SFT, preference optimization, and RL rewards.
- Treat
/ephemeral-style paths in examples as user-configurable storage roots, not mandatory constants. - Keep Weights & Biases optional. The repo writes local JSONL metrics even when W&B is disabled or unavailable.
- Use greedy decoding for comparable GSM8K stage tables; sampling is for chat.
- Do not claim CUDA coverage from CPU-only smoke tests. For CUDA claims, verify a torch CUDA allocation and at least a tiny model forward on the target host.
Troubleshooting
Read references/troubleshooting.md for
cross-cutting install/import/backend/checkpoint routing. Workflow-specific
failures live in each sub-skill's nearest references/troubleshooting.md.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).