赞
踩
注意:
默认模块应作为 --lora_target 参数的默认值,可使用 --lora_target all 参数指定全部模块以取得更好的效果。
对于所有“基座”(Base)模型,–template 参数可以是 default, alpaca, vicuna 等任意值。但“对话”(Instruct/Chat)模型请务必使用对应的模板。
请务必在训练和推理时使用完全一致的模板。
项目所支持模型的完整列表请参阅 constants.py。
您也可以在 template.py 中添加自己的对话模板。
# 创建新环境
conda create -n py310 python=3.10
#激活环境
conda activate py310
# 本次LLaMA-Factory版本 c1fdf81df6ade5da7be4eb66b715f0efd171d5aa
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e .[torch,metrics]
可选的额外依赖项:torch、metrics、deepspeed、bitsandbytes、vllm、galore、badam、gptq、awq、aqlm、qwen、modelscope、quality
如果要在 Windows 平台上开启量化 LoRA(QLoRA),需要安装预编译的 bitsandbytes 库, 支持 CUDA 11.1 到 12.2, 请根据您的 CUDA 版本情况选择适合的发布版本。
pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.2.post2-py3-none-win_amd64.whl
如果要在 Windows 平台上开启 FlashAttention-2,需要安装预编译的 flash-attn 库,支持 CUDA 12.1 到 12.2,请根据需求到 flash-attention 下载对应版本安装。
nvidia-smi
版本是12.2, 非常好
所以我安装的是:
pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.39.1-py3-none-win_amd64.whl
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --ignore-installed
可以在【2. 模型对比】中选择想微调的大模型,这里为了方便学习,选择Qwen1.5-0.5B大模型作为本次学习的大模型
!git lfs install
!git clone https://huggingface.co/Qwen/Qwen1.5-0.5B
哈哈哈哈,没下载下了,手动去网页一个个点击下载的
当前最新版本只有 api、webui、train三种模式,cli_demo 是之前的版本。(本次LLaMA-Factory版本c1fdf81df6ade5da7be4eb66b715f0efd171d5aa)
但是可以试用llamafactory-cli 推理
CUDA_VISIBLE_DEVICES=0 API_PORT=8000 python src/api.py
--model_name_or_path .\models\Qwen1.5-0.5B\
#--adapter_name_or_path path_to_checkpoint\
#--finetuning_type lora\
--template qwen
CUDA_VISIBLE_DEVICES=7 API_PORT=8030 llamafactory-cli api \
--model_name_or_path .\models\Qwen1.5-0.5B \
--template qwen
postman 试一下:
网页端自带请求测试:
# Request body Example Value
{
"model": "string",
"messages": [
{
"role": "user",
"content": "string",
"tool_calls": [
{
"id": "string",
"type": "function",
"function": {
"name": "string",
"arguments": "string"
}
}
]
}
],
"tools": [
{
"type": "function",
"function": {
"name": "string",
"description": "string",
"parameters": {}
}
}
],
"do_sample": true,
"temperature": 0,
"top_p": 0,
"n": 1,
"max_tokens": 0,
"stop": "string",
"stream": false
}
#Responses Successful Response Example Value
{
"id": "string",
"object": "chat.completion",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "user",
"content": "string",
"tool_calls": [
{
"id": "string",
"type": "function",
"function": {
"name": "string",
"arguments": "string"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}
# Responses Validation Error Example Value
{
"detail": [
{
"loc": [
"string",
0
],
"msg": "string",
"type": "string"
}
]
}
postman 试一下:
网页端自带请求测试:
{
"model": "string",
"messages": [
{
"role": "user",
"content": "tell me a story"
}
]
}
response:
{
"id": "chatcmpl-5a4587623b494f46b190ab363ac4260a",
"object": "chat.completion",
"created": 1717041519,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Sure, here's a story:\n\nOnce upon a time, there was a young girl named Lily. She loved to read and always wanted to learn more about the world around her. One day, while she was wandering through the woods, she stumbled upon a mysterious old book. The book was filled with stories and secrets that she had never heard before.\n\nAs she began to read, she found herself lost in the world of the book. She knew that the book was important, but she didn't know how to get it back. She searched for hours and hours, but she couldn't find it anywhere.\n\nJust when she thought she had lost hope, she saw a group of brave young men who were searching for treasure. They were looking for a lost treasure that had been hidden for centuries. Lily was excited to join them, but she was also scared.\n\nAs they searched the woods, they stumbled upon a secret passage that led to the treasure. But as they walked deeper into the forest, they realized that the passage was guarded by a group of trolls. The trolls were fierce and dangerous, and they knew that they couldn't leave without getting hurt.\n\nThe trolls were angry and territorial, and they wanted to take control of the treasure. They charged at Lily and her friends, but they were too late. They were outnumbered and outmatched, and they were all caught in the troll's trap.\n\nIn the end, Lily and her friends had to fight off the trolls and save the treasure. They had to work together to find a way out of the troll's trap, and they did it. They had a lot of fun and learned a lot about themselves and the world around them.",
"tool_calls": null
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 23,
"completion_tokens": 339,
"total_tokens": 362
}
}
服务终端log:
CUDA_VISIBLE_DEVICES=0 python src/webui.py\
--model_name_or_path ./models/Qwen1.5-0.5B\
#--adapter_name_or_path path_to_checkpoint\
#--finetuning_type lora\
--template qwen
最后两个参数在微调后使用,如果是原始模型的话可以不传这两个参数。
参考
非一般程序员第三季大模型PEFT(一)之大模型推理实践
LLaMA-Factory/README_zh.md
使用 LLaMA Factory 微调 Llama-3 中文对话模型
LLaMA-Factory QuickStart
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。