▲ 115 today347 starsJupyter NotebookNew · 4d old
Chinese tutorial lets you build a GPT from scratch
What is how-to-train-your-gpt-zh?
A 12-chapter Jupyter notebook walks you through tokenisation, attention, training and inference for a 151-million-parameter model, now with Chinese data and free domestic GPU support. Every line of code is commented in Chinese.
Who it is for
Anyone who wants to understand how modern language models work can follow the code line-by-line and even train a small GPT on Chinese text.
How how-to-train-your-gpt-zh works
The project implements a pure decoder transformer that follows the LLaMA 3 style architecture. It builds the model from a BPE tokenizer, then passes token ids through embedding layers, RoPE positional encoding, multi head attention with RMSNorm and SwiGLU feed forward blocks. Each transformer block uses pre norm, residual connections and shares the output embedding matrix with the language model head. Training is done with a hand written loop that applies cross entropy loss, AdamW optimizer, cosine warmup and mixed precision support.
What you can do with it
- Train a small 17 million parameter GPT on a CPU in a few minutes.
- Train a Chinese language model using Chinese Wikipedia data and a custom character tokenizer.
- Generate text with configurable temperature, top k or top p sampling and optional beam search.
Good to know
- Full size models (around 150 million parameters) require a GPU with enough memory.
- The code is released under the MIT license, which may restrict certain commercial uses.
- Only publicly documented components are implemented; proprietary techniques from newer models are not included.
Written from the project's own README.
Try it in 60 seconds
You need: Python, PyTorch and a GPU (optional)
git clone https://github.com/l0K1ngg/how-to-train-your-gpt-zh.gitcd how-to-tra
New projects are not vetted. Skim the code, and run it in a fresh folder or a container before giving it your files or keys.
The story so far
Early Signal first spotted l0K1ngg/how-to-train-your-gpt-zh on December 4, 2026, when it had 327 GitHub stars. It has since grown to 347. On its busiest day it gained 115 stars. The project is 4 days old and written mainly in Jupyter Notebook. Early Signal files it under LLMs, Inference.
Questions about how-to-train-your-gpt-zh
- How do I install how-to-train-your-gpt-zh?
- Use one of these, depending on your setup: git clone https://github.com/l0K1ngg/how-to-train-your-gpt-zh.git · cd how-to-tra
- What do I need to run how-to-train-your-gpt-zh?
- Python, PyTorch and a GPU (optional)