Giter Site home page Giter Site logo

chatglm_lora_multi-gpu's Introduction

Chatglm_lora_multi-gpu

大模型prompt&delta理论部分知识

1.CSDN链接

2.知乎链接

以chatglm为引擎,逐步配置各种插件,拓展更多应用

初始化环境

pip install -r requirements.txt

包括3种方式多gpu运行:

0 最简单的多gpu运行,能跑通的单机脚本+deepspeed的配置文件就可以

单机执行命令 python finetune.py \ --dataset_path data/alpaca \ --lora_rank 8 \ --per_device_train_batch_size 2 \ --gradient_accumulation_steps 1 \ --max_steps 2000 \ --save_steps 1000 \ --save_total_limit 2 \ --learning_rate 2e-5 \ --fp16 \ --remove_unused_columns false \ --logging_steps 50 \ --report_to wandb --output_dir output
多Gpu执行命令 torchrun --nproc_per_node=2 multi_gpu_fintune_belle.py \ --dataset_path data/alpaca \ --lora_rank 8 \ --per_device_train_batch_size 1 \ --gradient_accumulation_steps 1 \ --save_steps 2000 \ --save_total_limit 2 \ --learning_rate 2e-5 \ --fp16 \ --num_train_epochs 2 \ --remove_unused_columns false \ --logging_steps 50 \ --report_to wandb --output_dir output \ --deepspeed ds_config_zero3.json

1.deepspeed

数据处理

给两份belle中文的self instruct数据
     1.0.5M版本:
      cd data 
      
      wget https://huggingface.co/datasets/BelleGroup/generated_train_0.5M_CN/resolve/main/Belle.train.json

     2.1M版本
     
     wget https://huggingface.co/datasets/BelleGroup/generated_train_1M_CN/resolve/main/belle_open_source_1M.train.json

     3.把两份数据合并成一份

     a.0.5M和1M数据字段有些不同,统一处理数据,用地下代码处理1M数据
     
     cd ..
     
     python process_belle_1M_data.py

     b.把两份文件合并成一份,命名为:Belle_0_1.train.json

     cd data & cat Belle.train.json Belle_1M.train.json>Belle_0_1.train.json

数据准备好后执行下面命令

torchrun --nproc_per_node=2 multi_gpu_fintune_belle.py \ --dataset_path data/alpaca \ --lora_rank 8 \ --per_device_train_batch_size 1 \ --gradient_accumulation_steps 1 \ --save_steps 1000 \ --save_total_limit 2 \ --learning_rate 2e-5 \ --fp16 \ --num_train_epochs 2 \ --remove_unused_columns false \ --logging_steps 50 \ --gradient_accumulation_steps 2 \ --output_dir output \ --deepspeed ds_config_zero3.json

2.accelerate+deepspeed

准备数据

下载数据

cd data

wget https://huggingface.co/datasets/BelleGroup/generated_train_0.5M_CN/resolve/main/Belle.train.json

python tokenize_dataset_rows_belle.py
--jsonl_path data/alpaca_data.jsonl
--save_path data/alpaca
--max_seq_length 200
--skip_overlength

数据准备好后执行下面命令

accelerate launch --config_file accelerate_ds_zero3_cpu_offload_config.yaml multi_gpu_fintune_belle.py \ --dataset_path data/alpaca \ --lora_rank 8 \ --per_device_train_batch_size 2 \ --gradient_accumulation_steps 1 \ --max_steps 10000 \ --save_steps 1000 \ --save_total_limit 2 \ --learning_rate 2e-5 \ --fp16 \ --remove_unused_columns false \ --logging_steps 50 \ --output_dir output

3.ddp方式还没试

batch inference

实际工作中常常会出现,需要批量不数据预测出来问题

往往我们有一台高性能的机器,但是如果做fintune,只能一张卡一个时间面对一个请求,造成显卡存资源浪费

batch inference成为必要

1.deepspeed --num_gpus 2 chatglm_deepspeed_inference.py

2.显卡资源不足以装下大模型,可以用accelerate.load_checkpoint_and_dispatch:

python chatglm_milti_gpu_inference.py

如果也想用deepspeed加速,把以下注释代码去掉:

# init deepspeed inference engine '''ds_model = deepspeed.init_inference( model=model, # Transformers models mp_size=8, # Number of GPU dtype=torch.float16, # dtype of the weights (fp16) replace_method="auto", # Lets DS autmatically identify the layer to replace replace_with_kernel_inject=True, # replace the model with the kernel injector ) print(f"model is loaded on device {ds_model.module.device}")'''
deepspeed --num_gpus 2 chatglm_milti_gpu_inference.py

webUI交互

进入webui文件夹,执行readme.txt命令即可 image

streamlit run web_feedback.py --server.port 6006

新增chatglm作图应用

生成图

进入APP——example应用

023106E2-912D-4999-A0A2-9971C36A0769

7762BA98-AE3C-4D28-8CFD-8531A1C9209A

利用自定义知识库约束,chatglm回复

进入APP——example应用 chat_langchain

pip install -r requirement.txt \n python knowledge_based_chatglm.py

不带知识库回复: Q:世界上最大河流 A:"世界上最大的河流是尼罗河。尼罗河是非洲大陆最长的河流,全长约6650公里,发源于东非高原,流经苏丹、乌干达、肯尼亚、坦桑尼亚、卢旺达、刚果**共和国、布隆迪和埃及,最终注入地中海。尼罗河流域是非洲最重要的农业地区之一,也是世界上最古老的文明之一埃及文明的发源地之一。"

带知识库回复 基于本地知识搜索没有找到答案 image

chatglm_lora_multi-gpu's People

Contributors

liangwq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.