安装 LLaMA Factory:
# 从源码安装
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e ".[torch,metrics]" --no-build-isolation
可选的额外依赖项:torch、torch-npu、metrics、deepspeed、liger-kernel、bitsandbytes、hqq、eetq、gptq、aqlm、vllm、sglang、galore、apollo、badam、adam-mini、qwen、minicpm_v、openmind、swanlab、dev
模型下载:
modelscope download --model Qwen/Qwen3-4B-Instruct-2507 --local_dir ./Qwen3-4B-Instruct-2507
测试模型推理:
CUDA_VISIBLE_DEVICES=0 GRADIO_SERVER_PORT=6006 llamafactory-cli webchat --model_name_or_path /data1/models/Qwen3-4B-Instruct-2507 --template qwen3
数据集:
数据集格式使用的是 Alpaca 格式的指令监督微调数据集,示例:
[
{
"instruction": "识别并解释给定列表中的两个科学理论:细胞理论和日心说。",
"input": "",
"output": "细胞理论是生物科学的一个理论..."
}
]
关于数据集文件的格式详细内容,可以参考:https://github.com/hiyouga/LLaMA-Factory/blob/main/data/README_zh.md
处理好数据后,将数据放在'LLaMA-Factory/data'路径下,并修改 LLaMA-Factory/data/dataset_info.json 文件,增加新数据集完成注册。
{
"xxx_train_data": {
"file_name": "xxx_train_data.json"
},

