Skip to content

leauyn/Chatglm_lora_multi-gpu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chatglm_lora_multi-gpu

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

1.CSDN链接

2.知乎链接

语音学术助手理论部分

1.知乎链接

2.知乎链接

langchain keypoint理论部分

1.知乎链接

2.知乎链接

代码见APP_example/langchain_keypoint

C3893346-9075-4140-B7C2-0377ABCF8459

clip retrieval理论部分

1.知乎链接

代码见APP_example/clip_retrieval

1.图片库特征抽取代码:extract_embeddings.py 2.图片特征在faiss向量数据库建立索引:build_index.py 3.可视化应用界面:app.py

clip_search00

clip_searcg01

retrieval inage generator理论部分

1.知乎链接

代码见APP_example/retrieval_image_gen,如果直接启动需要24G左右显卡(没这么对显卡同学可以考虑api方式实现llm和image2image,clip检索显卡需求很低)

1.整合最终效果代码:app_gradio.py 2.图片image2image代码:upimage.py 3.openaistyle访问qwen大模型:先启动服务端openai_api.py;在启动可视化界面 chatbot_st.py
aigc-imag0 aigc-img01

以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强化学习Alignment部分(RLHF)

现在还比较naive,逐步会增加更实用更工业化的任务

新增stablediffusion lora训练能力

1.新增dreambooth lora训练方法 2.多lora合并生成效果 webwxgetmsgimg (3)

webwxgetmsgimg (1)

LLM_StableDiffusion_Studio

做了一个工具整合,后面会整合更多能力,相信我们不会只做工具罗列的人

https://github.com/liangwq/LLM_StableDiffusion_Studio

1620634258 webwxgetmsgimg (8) webwxgetmsgimg (9) webwxgetmsgimg (10) webwxgetmsgimg (11) webwxgetmsgimg (12)

新增chatglm实现agent的能力

增加chtglm构建agent代码 1.知乎链接 增加向量检索tool 1.知乎链接 image

About

chatglm多gpu用deepspeed和

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.7%
  • Other 0.3%