Skip to content

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

License

Notifications You must be signed in to change notification settings

RayJue/ChatGLM-Efficient-Tuning

Repository files navigation

ChatGLM Efficient Tuning

GitHub Repo stars GitHub Code License GitHub last commit

Fine-tuning 🤖ChatGLM-6B model with 🤗PEFT.

Datasets

Our script now supports the following datasets:

Please refer to config_data.py for details.

Fine-Tuning Methods

Our script now supports the following fine-tuning methods:

Requirement

  • Python 3.10 and PyTorch 2.0.0
  • 🤗Transformers, Datasets, and PEFT
  • protobuf, cpm_kernels, sentencepiece

And powerful GPUs!

Getting Started

Preparation

git clone https://github.com/hiyouga/ChatGLM-Efficient-Tuning.git
conda create -n cet python=3.10
conda activate cet
pip install -r requirements.txt

Fine-tuning

CUDA_VISIBLE_DEVICES=0 python finetune_chatglm.py \
    --do_train \
    --dataset guanaco \
    --output_dir output_guanaco \
    --overwrite_cache \
    --overwrite_output_dir \
    --per_device_train_batch_size 4 \
    --gradient_accumulation_steps 4 \
    --lr_scheduler_type cosine \
    --logging_steps 10 \
    --save_steps 1000 \
    --warmup_steps 100 \
    --max_train_samples 10000 \
    --learning_rate 5e-4 \
    --num_train_epochs 1.0 \
    --fp16

Inference

CUDA_VISIBLE_DEVICES=0 python infer_chatglm.py

Hardware Requirements

Batch size LoRA r Mode GRAM
8 8 FP16 24GB

Compared with Existing Implementations

  • THUDM/ChatGLM-6B
    • Official implementation of fine-tuning ChatGLM with P-Tuning v2 on the ADGEN dataset.
    • Our fine-tuning script is largely depend on it. We further implement the LoRA tuning method. Additionally, we dynamically pad the inputs to the longest sequence in the batch instead of the maximum length.
  • mymusise/ChatGLM-Tuning
    • An unoffical implementation of fine-tuning ChatGLM with LoRA on the Stanford Alpaca dataset.
    • We borrowed some ideas from it. Our fine-tuning script integrates the data pre-processing part into the training procedure, so we need not generate a pre-processed dataset before training.
  • ssbuild/chatglm_finetuning
  • lich99/ChatGLM-finetune-LoRA
  • liucongg/ChatGLM-Finetuning
    • An unofficial implementation of fine-tuning ChatGLM with several methods including Freeze, LoRA and P-Tuning on the industrial dataset.
    • We are aim to incorporate more instruction-following datasets for fine-tuning the ChatGLM model.
  • yanqiangmiffy/InstructGLM
    • An unofficial implementation of fine-tuning ChatGLM that explores the ChatGLM's ability on the instruction-following datasets.
    • Our fine-tuning script integrates the data pre-processing part in to the training procedure.

TODO

License

This repository is licensed under the Apache-2.0 License.

Citation

If this work is helpful, please cite as:

@Misc{chatglm-efficient-tuning,
  title = {ChatGLM Efficient Tuning},
  author = {hiyouga},
  howpublished = {\url{https://github.com/hiyouga/ChatGLM-Efficient-Tuning}},
  year = {2023}
}

Acknowledgement

This repo benefits from ChatGLM-6B, ChatGLM-Tuning and yuanzhoulvpi2017/zero_nlp. Thanks for their wonderful works.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.4%
  • Shell 1.6%