LLaMA-Factory微调 lora 模型
工具依赖:llamafactory-0.8.2
llamafactory-cli webui 可视化微调、训练,预测启动命令0
Running on local URL: http://0.0.0.0:7860
定义名字
import hashlib
def calculate_sha1(file_path):
sha1 = hashlib.sha1()
try:
with open(file_path, 'rb') as file:
while True:
data = file.read(8192) # Read in chunks to handle large files
if not data:
break
sha1.update(data)
return sha1.hexdigest()
except FileNotFoundError:
return "File not found."
# 使用示例
file_path = r'/home/jm/data/LLaMA-Factory-main/data/train_data.json' # 替换为您的文件路径
sha1_hash = calculate_sha1(file_path)
print("SHA-1 Hash:", sha1_hash)
llamafactory-cli train \
--stage sft \
--do_train True \
--model_name_or_path /home/jm/data/model/qwen/Qwen2-7B-Instruct-GPTQ-Int4 \
--preprocessing_num_workers 16 \
--finetuning_type lora \
--quantization_method bitsandbytes \ # 注意这个参数,有些服务器上不支持
--template qwen \
--flash_attn auto \
--dataset_dir data \
--dataset identity \
--cutoff_len 1024 \
--learning_rate 1e-05 \
--num_train_epochs 3.0 \
--max_samples 10000 \
--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/Qwen2-7B-int4-Chat/lora/train_2024-07-08-08-48-52 \
--bf16 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 \
--deepspeed cache/ds_z3_config.json
llamafactory-cli train \
--stage sft \
--model_name_or_path /home/jm/data/model/qwen/Qwen2-7B-Instruct-GPTQ-Int4 \
--preprocessing_num_workers 16 \
--finetuning_type lora \
--quantization_method bitsandbytes \ # 注意这个参数,有些服务器上不支持
--template qwen \
--flash_attn fa2 \
--dataset_dir data \
--dataset identity \
--cutoff_len 1024 \
--max_samples 100000 \
--per_device_eval_batch_size 10 \
--predict_with_generate True \
--max_new_tokens 512 \
--top_p 0.7 \
--temperature 0.1 \
--output_dir saves/Qwen2-7B-int4-Chat/lora/eval_2024-07-08-10-48-52 \
--do_predict True \
--adapter_name_or_path saves/Qwen2-7B-int4-Chat/lora/train_2024-07-08-08-48-52
python -m vllm.entrypoints.openai.api_server \
--model /home/jm/data/model/qwen/Qwen2-7B-Instruct-GPTQ-Int4/ \
--enable-lora \
--lora-modules lora1=/home/jm/data/LLaMA-Factory-main/saves/Qwen2-7B-int4-Chat/lora/train_2024-07-09-14-50-10/ \
-tp 2 \
--enforce-eager
from openai import OpenAI
from openai import OpenAI
# Set OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://127.0.0.1:8000/v1"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
chat_response = client.chat.completions.create(
model="lora1",
messages=[
{"role": "system", "content": "你是一个文本分类领域的专家,你会收到一段文本和几个潜在的分类选项,请选择问题最接近的一个分类选项,潜在的分类选项:农业/租赁法律/交通运输仓储邮政/水利环境/采矿/信息软件/政府组织/国际组织/房地产/制造业/文体娱乐/金融/电力燃气水生产/教育/住宿餐饮/科学技术/卫生医疗/建筑。只输出结果不做任何的解释说明:"},
{"role": "user", "content": "白条乌鸡价格 北京新发地农副产品批发市场信息中心 ¥13.20 ¥13.40 ¥13.30 元/公斤 查找"},
]
)
print("Chat response:", chat_response.choices[0].message.content.strip())
llamafactory-cli