## 魔搭社区 注册后有免费的100小时的GPU资源
# qwen 微调法律大模型 ## 准备环境 # 下载qwen和模型 git clone https://github.com/QwenLM/Qwen.git git clone https://www.modelscope.cn/qwen/Qwen-1_8B-Chat.git # 安装依赖 pip install -r requirements.txt # 安装torch 方法1 下载地址:http://download.pytorch.org/whl/torch_stable.html wget http://download.pytorch.org/whl/cu121/torch-2.1.1%2Bcu121-cp310-cp310-linux_x86_64.whl pip install torch-2.1.1+cu121-cp310-cp310-linux_x86_64.whl 方法2 去这个网站上找好对应版本的指令:https://pytorch.org/get-started/previous-versions/ pip install torch==2.1.1+cu121 torchvision==0.15.2+cu121 torchaudio==2.1.1+cu121 torchtext==0.15.2 torchdata==0.6.10 --extra-index-url https://download.pytorch.org/whl/cu121 # 安装deepspeed pip install "peft<0.8.0" deepspeed
## 微调 准备模型:Qwen-1_8B-Chat 准备训练数据:trans_data.json(训练数据自己准备一个json的) ``` cd Qwen # 修改微调配置 vim finetune_lora_single_gpu.sh chmod +x finetune_lora_single_gpu.sh # 微调,根据需要修改 ./finetune_lora_single_gpu.sh -m /mnt/workspace/Qwen-1_8B-Chat -d /mnt/workspace/Qwen/trans_data.json ./finetune_lora_single_gpu.sh -m /mnt/workspace/Qwen/Qwen-1_8B-Chat -d /mnt/workspace/Qwen/new-DISC-Law.json # 合并模型,模型合并文件 qwen_lora_merge.py,上传到Qwen文件夹里,然后修改微调模型路径 lora_model_path="/mnt/workspace/Qwen/output_qwen/checkpoint-30" (路径根据自己文件的路径进行修改) # 合并模型 python qwen_lora_merge.py
## 测试 ### 交互式Demo ``` cd Qwen python cli_demo.py -c Qwen-1_8B-Chat_merge ``` ### Web Demo ``` # 启动服务 python web_demo.py --cpu-only -c=Qwen-1_8B-Chat # 查看web界面 http://127.0.0.1:8000/ ```