前提
GPU环境安装了NVIDIA Container Toolkit
一般情况下
apt-get update apt-get install -y nvidia-container-toolkit这个过程需要版本匹配等各种问题,需要大家自己耐心安装
开始
首先建立一个环境隔离,防止环境污染,具体参考
Unsloth 微调 构建自己的大模型 没有GPU也能微调-CSDN博客
sudo apt update sudo apt install python3-venv source .venv/bin/activate 激活环境 使用完毕后记得关闭 deactivate下载Unsloth镜像
docker pull unsloth/unsloth:latest这里面包括了所有 Unsloth 的示例 notebook和jupyter,涵盖模型微调和强化学习
如果只想使用基本功能,只需要下载核心内容,后面的标签变为
docker pull unsloth/unsloth:core启动Unsloth
启动GPU Unsloth
docker run -it --gpus all \ -p 8080:8080 \ --name unsloth \ -v home/workspace:/root/workspace \ unsloth/unsloth:latest启动CPU Unsloth
注意GPU参数改为-e UNSLOTH_ALLOW_CPU=1
docker run -it \ -p 8080:8080 \ -e UNSLOTH_ALLOW_CPU=1 \ --name unsloth \ -v home/work:/root/workspace \ unsloth/unsloth:core如果在CPU的环境下使用GPU启动,会出现以下提醒
WARN: UNSLOTH_ALLOW_CPU=1 and no GPU visible -- continuing on CPU. WARN: CPU mode covers Jupyter, GGUF tooling and llama.cpp (GGUF) Unsloth Studio chat. WARN: Training and loading Unsloth models (FastLanguageModel) still require an NVIDIA GPU.大概意思就是 只有GPU参与运算,Jupyter, GGUF, llama.cpp (GGUF) Unsloth Studio chat这几个模块运行没问题,但是如果使用FastLanguageModel这个模块,依然需要GPU
配置好环境后,可以进行微调模型
可以参考Unsloth 微调 构建自己的大模型 没有GPU也能微调-CSDN博客