官方链接: https://docs.unsloth.ai/get-started/installing-±updating。
本文使用 conda 分步骤安装
1. 创建虚拟环境
conda create --name unsloth_env python=3.11
2. pytorch 2.4 cuda 12.1
conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=12.1 -c pytorch -c nvidia
3. xformers
pip install xformers==0.0.27.post2
4. unsloth
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --no-deps trl peft accelerate bitsandbytes
注意事项
1. 也可以选择全部用 pip 命令安装, 但在虚拟环境里面可能会有其他问题 处理起来麻烦
2. torch 和 cuda 的版本号一定要对应上 如:pytorch 2.4 cuda 12.1
3. xformers 不要直接安装 可能会自动升级 torch 版本;先用dry run 看看 torch 有没有被升级
# 不推荐
pip install xformers
pip install xformers==0.0.27
# 推荐
pip install xformers==0.0.27.post2
4. unsloth 安装可能遇到443问题 届时需要设置 git 代理 记得改后查看一下
git config --global http.proxy http://127.0.0.1:你的端口
git config --global https.proxy http://127.0.0.1:你的端口
git config --global -l