mymusise/ChatGLM-Tuning

Python

基于ChatGLM-6B + LoRA的Fintune方案

chatglmchatgptlorapeft
Star Growth
Stars
3.7k
Forks
432
Weekly Growth
+-1
Issues
177
2k3k
Mar 2023May 2024Jul 2025Sep 2026
ArtifactsPyPI
README

ChatGLM-Tuning

一种平价的chatgpt实现方案,基于清华的 ChatGLM-6B + LoRA 进行finetune.

数据集: alpaca

有colab的同学可以直接在colab上尝试: Build

官方ptuning代码

Demo

S1 Finetune

准备

  • 显卡: 显存 >= 16G (最好24G或者以上)
  • 环境:
    • python>=3.8
    • cuda>=11.6, cupti, cuDNN, TensorRT等深度学习环境
    • pip3 install -r requirements.txt 其中requirements.txt中的安装包bitsandbytes 建议安装0.41.2.post2这个版本,以前的版本可能会提示报错: bitsandbytes/libbitsandbytes_cpu.so: undefined symbol: cget_col_row_stats

数据预处理

转化alpaca数据集为jsonl

python cover_alpaca2jsonl.py \
    --data_path data/alpaca_data.json \
    --save_path data/alpaca_data.jsonl \
    

tokenization

python tokenize_dataset_rows.py \
    --jsonl_path data/alpaca_data.jsonl \
    --save_path data/alpaca \
    --max_seq_length 200 \ 
    --skip_overlength  False
    --chatglm_path model_path/chatglm
    --version v1                 
    
  • --jsonl_path 微调的数据路径, 格式jsonl, 对每行的['context']和['target']字段进行encode
  • --save_path 输出路径
  • --max_seq_length 样本的最大长度
  • --chatglm_path 导入模型的路径(可以选择chatglm或chatglm2的不同路径)
  • --version 模型的版本(v1指chatglm,v2指chatglm2)

训练

python finetune.py \
    --dataset_path data/alpaca \
    --lora_rank 8 \
    --per_device_train_batch_size 6 \
    --gradient_accumulation_steps 1 \
    --max_steps 52000 \
    --save_steps 1000 \
    --save_total_limit 2 \
    --learning_rate 1e-4 \
    --fp16 \
    --remove_unused_columns false \
    --logging_steps 50 \
    --output_dir output
    --chatglm_path model_path/chat_glm

推理

参考 infer.ipynb

Finetune前后对比

利用Alpaca数据集合对ChatGLM-6B Finetune后,在Alpaca数据集上表现得更好:

  • Answer: 是模型的输出
  • #### Answer: 是原答案

S2. Reward Model

S3. PPO

LoRA

LoRA Dataset
mymusise/chatglm-6b-alpaca-lora Alpaca
mymusise/chatglm-6b-alpaca-zh-en-lora Alpaca-zh-en
(on the way) Alpaca-zh

使用预训练好的LoRA

参考 examples/infer_pretrain.ipynb

TODO:

  • bs > 1 support
  • 使用中文数据
  • 加入RLHF
Related repositories
chatchat-space/Langchain-Chatchat

Langchain-Chatchat(原Langchain-ChatGLM)基于 Langchain 与 ChatGLM, Qwen 与 Llama 等语言模型的 RAG 与 Agent 应用 | Langchain-Chatchat (formerly langchain-ChatGLM), local knowledge based LLM (like ChatGLM, Qwen and Llama) RAG and Agent app with langchain

PythonPyPIApache License 2.0chatglmlangchain
38.6k6.3k
datawhalechina/self-llm

《开源大模型食用指南》针对中国宝宝量身打造的基于Linux环境快速微调(全参数/Lora)、部署国内外开源大模型(LLM)/多模态大模型(MLLM)教程

Jupyter NotebookApache License 2.0llmchatglm
32.1k3.1k
AiHubCN/Awesome-Chinese-LLM

整理开源的中文大语言模型,以规模较小、可私有化部署、训练成本较低的模型为主,包括底座模型,垂直领域微调及应用,数据集与教程等。

awesomellmnlp
22.8k2.1k
zai-org/ChatGLM2-6B

ChatGLM2-6B: An Open Bilingual Chat LLM | 开源双语对话语言模型

PythonPyPIOtherchatglmchatglm-6b
15.5k1.8k
GaiZhenbiao/ChuanhuChatGPT

GUI for ChatGPT API and many LLMs. Supports agents, file-based QA, GPT finetuning and query with web search. All with a neat UI.

PythonPyPIGNU General Public License v3.0chatbotchatgpt-api
huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT
15.3k2.2k
EmbraceAGI/awesome-chatgpt-zh

ChatGPT 中文指南🔥,ChatGPT 中文调教指南,指令指南,应用开发指南,精选资源清单,更好的使用 chatGPT 让你的生产力 up up up! 🚀

PythonPyPIawesomeMIT Licensechatgptgpt-4
11.7k958
zai-org/GLM-4

GLM-4 series: Open Multilingual Multimodal Chat LMs | 开源多语言多模态对话模型

PythonPyPIlibraryApache License 2.0chatglmchatglm-6b
7.1k612
lich0821/WeChatFerry

微信机器人,可接入DeepSeek、Gemini、ChatGPT、ChatGLM、讯飞星火、Tigerbot等大模型。微信 hook WeChat Robot Hook.

C++MIT Licensehookrobot
6.8k1.6k
yangjianxin1/Firefly

Firefly: 大模型训练工具,支持训练Qwen2.5、Qwen2、Yi1.5、Phi-3、Llama3、Gemma、MiniCPM、Yi、Deepseek、Orion、Xverse、Mixtral-8x7B、Zephyr、Mistral、Baichuan2、Llma2、Llama、Qwen、Baichuan、ChatGLM2、InternLM、Ziya2、Vicuna、Bloom等大模型

PythonPyPIgptalpaca
6.6k583
hiyouga/ChatGLM-Efficient-Tuning

Fine-tuning ChatGLM-6B with PEFT | 基于 PEFT 的高效 ChatGLM 微调

PythonPyPIApache License 2.0chatglmchatgpt
3.7k462
li-plus/chatglm.cpp

C++ implementation of ChatGLM-6B & ChatGLM2-6B & ChatGLM3 & GLM4(V)

C++MIT Licenselarge-language-modelschatglm
3k326
PhoebusSi/Alpaca-CoT

We unified the interfaces of instruction-tuning data (e.g., CoT data), multiple LLMs and parameter-efficient methods (e.g., lora, p-tuning) together for easy use. We welcome open-source enthusiasts to initiate any meaningful PR on this repo and integrate as many LLM related technologies as possible. 我们打造了方便研究人员上手和使用大模型等微调平台,我们欢迎开源爱好者发起任何有意义的pr!

Jupyter NotebookApache License 2.0chatglmllama
2.8k247