SuperAPIAI Directory

tiny-llm-zh

github.com · AI developer platforms

tiny-llm-zh is an open-source project that implements a small-parameter Chinese large language model from scratch, with public data and code, covering the full pipeline of tokenization, pretraining, instruction fine-tuning, human alignment, evaluation, quantization, and deployment, intended for quickly getting started with learning about large models.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsLinux

About this tool

Purpose: For learners who want to quickly get started with large models, building a small-parameter Chinese language model from scratch, covering the complete chain of large model training and alignment.

Main capabilities: The architecture uses common components such as RMSNorm, RoPE, and MHA; it implements the pipeline of tokenization (Tokenizer) → pretraining (PTM) → instruction fine-tuning (SFT) → human alignment (RLHF, DPO) → evaluation → quantization → deployment; it publicly releases 42B tokens of pretraining data, 4 million SFT data entries, and 170k RL data entries, and provides pretraining data and tokenizer; the tokenizer is based on the ChatGLM3 vocabulary (size 64798), and it also provides a way to expand LLaMA2's 32K vocabulary to 50K; it uses Transformers and DeepSpeed for training, supporting multi-machine multi-GPU and optimizations such as Zero; the code is launched via Bash scripts, supporting scales such as 16m, 42m, 92m, 210m, and 440m; the tiny_llm_moe branch supports MoE architecture and techniques such as shared experts and balanced experts; it supports llama.cpp inference. The project has three branches: llama2_torch, main tiny_llm, and tiny_llm_moe.

Usage: The model is hosted on Huggingface and ModeScope, and running the code can download it automatically; it is recommended to load online with Huggingface, and if that does not work, try ModeScope; for local running, the model_id path needs to be changed to a local directory. Environment requirements are Python 3.8+, PyTorch 2.0+, transformers 4.37.2+, and training recommends CUDA 11.4+. Before running the local web Demo, you need to modify model_id in web_demo.py and then execute it. For Transformers deployment examples, see demo/infer_chat.py and demo/infer_func.py. vLLM requires CUDA 12+ and PyTorch 2.1+, copy vllm/tinyllm.py to the vllm/model_executor/models directory and add one line of code in its init.py (the model structure is custom and not officially implemented). llama.cpp deployment recommends a Linux environment; the effect on Windows is not good, and the modified version can be used llama.cpp.tinyllm.

Applicable scenarios: Full-pipeline learning of large models, small-scale Chinese model experiments, and teaching.

Limitations: Due to resource constraints, the project's primary goal is to get the pipeline working rather than tune performance, so evaluation scores are relatively low and some generations are erroneous; C-Eval and CMMLU evaluations use OpenCompass, the Base model uses ppl, and the Chat model uses the gen method; documentation for data processing and the training process is in the doc folder and is being organized.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools