雁过留声 发表于 2025-3-11 17:57:58

LLaMA-Factory环境搭建与运行示例

一、LLaMA-Factory

LLaMA-Factory项目
二、LLaMA-Factory环境搭建

1.底子环境搭建

底子环境必要
环境推荐版本CUDA12.1Python3.11PyTorch2.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 "." -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为指定运行显卡号

[*]运行结果
https://i-blog.csdnimg.cn/direct/f2d9e6ca9899473886a2496fd3bd231e.png#pic_center
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为方位的端口

[*] 背景表现结果
https://i-blog.csdnimg.cn/direct/4d8727c84dea41c2a32f72ada4f85f79.png#pic_center
[*] 浏览器结果
浏览器输入ip:port,port更换为GRADIO_SERVER_PORT的端口
https://i-blog.csdnimg.cn/direct/de69af2222d1402eaa3db2cd68e0f477.png#pic_center
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为指定运行显卡号

[*]运行结果
https://i-blog.csdnimg.cn/direct/98c0507948cb48c1bcf6bc0ee8120000.png#pic_center

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: LLaMA-Factory环境搭建与运行示例