大模型微调
环境准备
Python虚拟化环境
- Conda安装
$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ bash ~/Miniconda3-latest-Linux-x86_64.sh
- 配置Python
$ conda create -n llama_factory python=3.11
$ conda activate llama_factory
$ pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple
安装Python包
$ git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
$ cd LLaMA-Factory
$ pip install -e ".[torch,metrics,modelscope,vllm]"
模型下载
默认国内访问huggingface非常慢,可以使用 hf-mirror进行加速
$ pip install -U huggingface_hub
$ export HF_ENDPOINT=https://hf-mirror.com
下载模型
$ huggingface-cli download --resume-download deepseek-ai/DeepSeek-R1-Distill-Qwen-32B --local-dir deepseek-ai/DeepSeek-R1-Distill-Qwen-32B --local-dir-use-symlinks False
可以添加 –local-dir-use-symlinks False 参数禁用文件软链接,这样下载路径下所见即所得 , 或者可以使用modelscope工具从国内下载,参考
启动WebUI
$ GRADIO_SERVER_PORT=6006 llamafactory-cli webui
启动推理api
这里使用vllm框架进行推理,这里使用QwQ32b模型为示例,examples/inference/qwq.yaml
model_name_or_path: /data/home/tisteryu/.cache/modelscope/hub/models/Qwen/QwQ-32B
template: qwen
infer_backend: vllm # choices: [huggingface, vllm]
trust_remote_code: true
max_new_tokens: 8192
启动推理:
API_PORT=8000 llamafactory-cli api examples/inference/qwq.yaml