unsloth环境配置
unsloth官方推荐conda配置docker环境,但conda源无法使用,环境配置费了很大力气,记录一下踩过的坑(报错不计其数,只记了一小部分)
此框架对硬件有要求,最低支持Pascal构架(P40,10系列显卡)参考此issue,更老的M40显卡没有找到可用的环境。
硬件条件:
GPU:RTX2080TI 系统:Ubuntu20.04
配好的dockerfile:
# 基础镜像 FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime # 设置工作目录,方便后续操作,这里设置为根目录下的app目录,可按需修改 WORKDIR /app # 更换apt源为阿里云 RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \ sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list # 安装Python包管理工具pip(如果镜像中没有预装的话)以及一些必要的构建工具和依赖库 RUN apt-get update && \ apt-get install -y python3-pip git wget zsh curl unzip aria2 && \ rm -rf /var/lib/apt/lists/* # 更换pip源为阿里云 RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple && \ pip config set global.trusted-host mirrors.aliyun.com # trl不能高于0.15 RUN pip install numpy==1.24.0 trl==0.14.0 ipykernel ipywidgets RUN pip install torch==2.3.0 RUN pip install xformers==0.0.26.post1 RUN pip install accelerate # bitsandbytes不低于0.45.3, triton不能是3.2.0 RUN pip install bitsandbytes==0.45.3 triton==3.1.0 RUN pip install "unsloth[cu121-torch230] @ git+https://github.com/unslothai/unsloth.git"
# 或者本地安装 # COPY unsloth-main.zip /app/ # RUN unzip unsloth-main.zip # RUN pip install ./unsloth-main[cu121-torch220]
# huggungface设置镜像源 RUN pip install -U huggingface_hub ENV HF_ENDPOINT=https://hf-mirror.com # unsloth_zoo>=2025.2.2 RUN pip install unsloth_zoo==2025.3.16 # transformers不能是4.50.0 RUN pip install transformers==4.49.0
中途遇见的小部分问题:
1、data did not match any variant of untagged enum ModelWrapper at line 757443 column 3
pip install -U transformers
2、AttributeError: 'AdamW' object has no attribute 'train'
Updating accelerate
to 0.34.2
solves this problem.
其他:
大部分问题可通过小范围升降级解决,可以尝试 pip install --no-depen xxxx 忽略依赖问题
google+github的issue可以解决大部分问题