赞
踩
Llama3-8B-Chinese-Chat
,用于中文指定领域的问答下游任务官网地址:https://huggingface.co/models
镜像网址:https://hf-mirror.com/
按照如下图所示搜索需要的基础模型
点击Files and versions
依次点击下载,将模型文件下载至指定的文件夹内
此方法官方网站下载速度可能很慢,建议时间紧的同学采用镜像网站下载
pip install transformers
HF_HOME
,配置模型下载地址huggingface-cli scan-cache
from transformers import AutoModel
model_name = "shenzhi-wang/Llama3-8B-Chinese-Chat"
model = AutoModel.from_pretrained(model_name)
# 下载所需的工具包
pip install -U huggingface_hub
pip install huggingface-cli
# 指定国内镜像源
# Linux
export HF_ENDPOINT=https://hf-mirror.com
# Windows
set HUGGINGFACE_HUB_ENDPOINT=https://hf-mirror.com
# 执行下载命令
# --resume-download 是下载中断恢复下载后继续从上次下载中断点继续下载
# shenzhi-wang/Llama3-8B-Chinese-Chat 是要下载模型的名称
# E:\LLM 是下载到本地的路径
huggingface-cli download --resume-download shenzhi-wang/Llama3-8B-Chinese-Chat --local-dir E:\LLM
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
# "[torch,metrics]"可以删除直接执行pip install -e .
pip install -e ".[torch,metrics]"
https://github.com/hiyouga/LLaMA-Factory/blob/main/README_zh.md
data
目录下新建fine_tuning_data
文件夹,用来存放微调所需的数据dataset_info.json
文件中将刚刚构建的微调数据进行路径配置,注意配置格式要与构建的数据格式一一对应# 新构建的节点
"fintech": {
"file_name": "fine_tuning_data/fintech.json",
"columns": {
"prompt": "instruction",
"query": "input",
"response": "output",
"history": "history"
}
},
# 默认自带的节点,注意修改路径
"identity": {
"file_name": "fine_tuning_data/identity.json"
},
llamafactory-cli webui
llamafactory-cli train \ --stage sft \ --do_train True \ --model_name_or_path E:\LLM\Llama3-8B-Chinese-Chat \ --preprocessing_num_workers 16 \ --finetuning_type lora \ --template llama3 \ --flash_attn auto \ --dataset_dir data \ --dataset fintech,identity \ --cutoff_len 1024 \ --learning_rate 0.0002 \ --num_train_epochs 10.0 \ --max_samples 1000 \ --per_device_train_batch_size 2 \ --gradient_accumulation_steps 8 \ --lr_scheduler_type cosine \ --max_grad_norm 1.0 \ --logging_steps 5 \ --save_steps 100 \ --warmup_steps 0 \ --optim adamw_torch \ --packing False \ --report_to none \ --output_dir saves\LLaMA3-8B-Chinese-Chat\lora\train_2024-06-20-19-55-32 \ --fp16 True \ --plot_loss True \ --ddp_timeout 180000000 \ --include_num_input_tokens_seen True \ --lora_rank 8 \ --lora_alpha 16 \ --lora_dropout 0 \ --lora_target all
开始
build/train_llama3_lora.yaml
配置文件,内容如下stage: sft do_train: True model_name_or_path: E:\LLM\LLMLlama3-8B-Chinese-Chat preprocessing_num_workers: 16 finetuning_type: lora template: llama3 flash_attn: auto dataset_dir: data dataset: fintech,identity cutoff_len: 1024 learning_rate: 0.0002 num_train_epochs: 10.0 max_samples: 1000 per_device_train_batch_size: 2 gradient_accumulation_steps: 8 lr_scheduler_type: cosine max_grad_norm: 1.0 logging_steps: 5 save_steps: 100 warmup_steps: 0 optim: adamw_torch packing: False report_to: none output_dir: saves\LLaMA3-8B-Chinese-Chat\lora\train_2024-06-20-19-55-32 fp16: True plot_loss: True ddp_timeout: 180000000 include_num_input_tokens_seen: True lora_rank: 8 lora_alpha: 16 lora_dropout: 0 lora_target: all
llamafactory-cli train build/train_llama3_lora.yaml
# Linux
watch -n 1 nvidia-smi
# windows
nvidia-smi.exe -l
jieba、nltk、rouge-chinese
这三个NLP常用的工具包,大家如果没有安装,可以在执行验证前进行安装pip install jieba nltk rouge-chinese
# Linux
pip install vllm
Llama3-8B-Chinese-Chat
Llama3-8B-Chinese-Chat
1、Web UI界面合并
2、命令行合并
build/merge_llama3_lora.yaml
配置文件,内容如下### Note: DO NOT use quantized model or quantization_bit when merging lora adapters
### model
model_name_or_path: E:\LLM\Llama3-8B-Chinese-Chat
adapter_name_or_path: E:\LLM\LLaMA-Factory\saves\LLaMA3-8B-Chinese-Chat\lora\train_2024-06-20-19-55-32
template: llama3
finetuning_type: lora
### export
export_dir: E:\LLM\LLaMA3-8B-Chinese-Chat-merged
export_size: 4
export_device: cuda
export_legacy_format: false
llamafactory-cli export build/merge_llama3_lora.yaml
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。