目录
0 基础环境
操作系统:windows11
显卡:NVIDIA RTX 2060 6G显存
conda:已安装miniconda
上网:已具备科学上网
1 环境准备
1.1 CUDA环境准备
安装12.4版本CUDA,请参考以下链接:
1.2 conda项目环境准备
1.2.1创建conda项目环境
conda create -n LearnLangchain python=3.10
1.2.2 pycharm创建项目
1.2.3 安装unsloth环境
# 安装torch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
# 安装unsloth,版本:2025.2.15
pip install unsloth
# 安装triton
pip install .\triton-3.2.0-cp310-cp310-win_amd64.whl
triton下载链接:https://github.com/woct0rdho/triton-windows/releases/download/v3.2.0-windows.post10/triton-3.2.0-cp310-cp310-win_amd64.whl
1.3 模型准备
pip install modelscope
mkdir ./DeepSeek-R1-Distill-Llama-8B
modelscope download --model deepseek-ai/DeepSeek-R1-Distill-Llama-8B --local_dir
./DeepSeek-R1-Distill-Llama-8B
1.4 数据准备
https://huggingface.co/datasets/FreedomIntelligence/medica l-o1-reasoning-SFT
通过上面的链接下载数据文件。
2 逻辑实现
代码实现参考:DeepSeek R1 Distill高效微调入门实战 - 飞书云文档
2.1 引入环境变量,未引入会导致找不到c编译器和c标准库
import os
# os.environ["UNSLOTH_USE_TRITON"] = "False"
import sys
sys.stdout.reconfigure(encoding='ut