LLaMA-Factory环境搭建与运行示例
一、LLaMA-Factory
二、LLaMA-Factory环境搭建
1.基础环境搭建
基础环境需要
| 环境 | 推荐版本 |
|---|---|
| CUDA | 12.1 |
| Python | 3.11 |
| PyTorch | 2.4.0 |
具体安装可参考我的另一篇文章fairseq-0.12.2多机训练环境搭建。
2.安装 LLaMA-Factory依赖
- 下载LLaMA-Factory项目:
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
- 安装torch版本
pip3 install -e ".[torch]" -i https://pypi.tuna.tsinghua.edu.cn/simple
- 修改不正确的环境
pip3 install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple
三、LLaMA-Factory运行示例
1.使用命令行接口
- 配置文件llama3.yaml
model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct
template: llama3
说明:
- model_name_or_path为模型路径
- 运行命令行接口
CUDA_VISIBLE_DEVICES=0 llamafactory-cli chat examples/inference/llama3.yaml
说明:
- CUDA_VISIBLE_DEVICES为指定运行显卡号
- 运行效果

2.使用浏览器界面
- 配置文件llama3.yaml
model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct
template: llama3
说明:
- model_name_or_path为模型路径
- 使用浏览器界面
CUDA_VISIBLE_DEVICES=0 GRADIO_SERVER_PORT=8123 llamafactory-cli chat examples/inference/llama3.yaml
说明:
- CUDA_VISIBLE_DEVICES为指定运行显卡号
- GRADIO_SERVER_PORT为方位的端口
-
后台显示效果

-
浏览器效果
浏览器输入ip:port,port替换为GRADIO_SERVER_PORT的端口

3.使用训练方式批量推理
- 配置文件llama3.yaml
### model
model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct
### method
stage: sft
do_predict: true
finetuning_type: full
### dataset
eval_dataset: test
template: llama3
cutoff_len: 4096
overwrite_cache: true
preprocessing_num_workers: 16
### output
output_dir: output
overwrite_output_dir: true
### eval
per_device_eval_batch_size: 1
predict_with_generate: true
do_sample: true
temperature: 0.6
top_p: 0.9
num_beams: 5
说明:
- model_name_or_path为模型路径
- eval_dataset为测试数据集名称
- output_dir为输出文件路径
- per_device_eval_batch_size为batch,一次批处理的数据数量
- do_sample为使用sample推理
- num_beams为beam大小
- 测试数据集准备
data/dataset_info.json
{
"test": {
"file_name": "test.json"
},
"test1": {
"file_name": "test1.json"
}
}
说明:
- key为数据名称,eval_dataset使用该字段
- file_name为数据文件路径
- 使用训练方式批量推理
CUDA_VISIBLE_DEVICES=0 llamafactory-cli train llama3.yaml
说明:
- CUDA_VISIBLE_DEVICES为指定运行显卡号
- 运行效果

141

被折叠的 条评论
为什么被折叠?



