Building a large language model from scratch, with notebooks for learning and a modular training package for repeatable experiments.
python -m venv .venv
source .venv/bin/activate
pip install -e .
rebuild-llm-train-tiny \
--text-file /absolute/or/relative/path/to/your_corpus.txt \
--tokenizer word \
--context-length 64 \
--emb-dim 128 \
--n-heads 4 \
--n-layers 4 \
--epochs 3src/rebuild_llm/config.py: typed experiment configssrc/rebuild_llm/data/: tokenization + sequence datasetssrc/rebuild_llm/model/: attention, transformer blocks, GPT modelsrc/rebuild_llm/engine/: training/evaluation + generationsrc/rebuild_llm/cli/train_tiny.py: runnable tiny experiment CLIProcess/: notebook-based learning and experimentation workflow
- Provide the dataset with
--text-file <path>. - Current pipeline expects UTF-8 plain text (typically
.txtfiles). - The text is read, tokenized, and then used for next-token training.
- Tokenizer choices:
--tokenizer char(default): character-level tokenizer--tokenizer word: Process-style regex/word tokenizer with<|unk|>support
- Add a tokenizer (e.g., BPE/tiktoken) in
src/rebuild_llm/data/tokenizer.py - Add new datasets/objectives in
src/rebuild_llm/data/andsrc/rebuild_llm/engine/ - Add model variants (RoPE, RMSNorm, MoE, etc.) in
src/rebuild_llm/model/ - Add extra CLI commands for pretrain, classify, instruct-finetune in
src/rebuild_llm/cli/