WSL2 配置深度学习环境 大模型微调

WSL是在Windows上跑的Linux子系统,但是在Windows环境下,安装deepspeed和flash-attention有很大的坑(deepspeed确实能安装成功,但是flash-attention安了好久确实也没有成功)

准备工作

修改WSL的版本为2

在终端执行wsl -l -v显示wsl版本
WSL版本查看
执行wsl --set-version Ubuntu-22.04,即可将wsl版本转换为2。如果出现需要下载更新等提示,点击更新即可。

安装Cuda Toolkit

Nvidia的驱动在Windows和WSL平台是通用的,可使用nvidia-smi命令查看
nvidia-smi
NVIDIA Toolkit下载地址:https://developer.nvidia.com/cuda-downloads
NVIDIA Toolkit下载
在这里插入图片描述
在 wsl 命令行按照图示的指令运行就行。
安装完成后nvcc -V应该是显示不出来版本的。需要在~/.bashrc文件下做环境变量的配置。vim ~/.bashrc 在最下面添加这几行。

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PAT

刷新环境 source ~/.bashrc,运行nvcc -V会有 CUDA版本的输出

安装Conda

这里选择安装Miniconda
打开清华大学镜像站:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
在这里插入图片描述
选择相应的Linux版本右键复制链接,在终端使用wget命令进行下载

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh

赋执行权

chmod +x ./Miniconda3-py39_4.9.2-Linux-x86_64.sh

运行安装脚本

./Miniconda3-py39_4.9.2-Linux-x86_64.sh

跟着提示一步一步来就可以了
安装完成后,为conda添加清华源

conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main # 添加conda下载源,目的是它自动生成的一个配置文件,

为pip添加清华源

pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple # 修改pip下载源

Deepspeed

在Windows下,deepspeed安装好费劲,但是在Linux环境下,装好gpu版本torch后,直接pip install deepspeed即可

FlashAttention

flash-attn用于推理加速

github下载较慢,可使用gitee镜像

git clone https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .

下方安装可选,安装可能比较缓慢。

pip install csrc/layer_norm
pip install csrc/rotary

Git+LFS

sudo apt-get update
sudo apt-get install git-lfs
git lfs install

模型部署(Qwen-1.8B)

模型地址:https://www.modelscope.cn/models/qwen/Qwen-1_8B-Chat/summary
首先,我们使用Visual Studio Code进入到WSL环境,将其clone下来

git clone https://www.modelscope.cn/qwen/Qwen-1_8B-Chat.git

在这里插入图片描述
按照提示,安装依赖

pip install transformers==4.32.0 accelerate tiktoken einops scipy transformers_stream_generator==0.0.4 peft deepspeed

接着,新建chat.py,写入一下内容(注意,不要在Qwen-1_8B-Chat内创建):

from modelscope import AutoModelForCausalLM, AutoTokenizer, GenerationConfig

# Note: The default behavior now has injection attack prevention off.
tokenizer = AutoTokenizer.from_pretrained("./Qwen-1_8B-Chat", revision='master', trust_remote_code=True)

model = AutoModelForCausalLM.from_pretrained("./Qwen-1_8B-Chat", revision='master', device_map="auto", trust_remote_code=True).eval()

# 第一轮对话 1st dialogue turn
response, history = model.chat(tokenizer, "你好", history=None)
print(response)
# 你好!很高兴为你提供帮助。

# 第二轮对话 2nd dialogue turn
response, history = model.chat(tokenizer, "给我讲一个年轻人奋斗创业最终取得成功的故事。", history=history)
print(response)

# 第三轮对话 3rd dialogue turn
response, history = model.chat(tokenizer, "给这个故事起一个标题", history=history)
print(response)

response, _ = model.chat(tokenizer, "你好呀", history=None, system="请用二次元可爱语气和我说话")
print(response)

response, _ = model.chat(tokenizer, "My colleague works diligently", history=None, system="You will write beautiful compliments according to needs")
print(response)

模型微调

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
回答: 要在WSL中搭建深度学习系统,你可以按照以下步骤进行操作。首先,你需要在WSL中启用systemd。在单独的Linux系统中,可以使用systemctl对Docker进行自启动,但是WSL初始系统并不支持systemctl。因此,每次重新启动WSL,都需要使用sudo service docker start命令来启动Docker服务。\[1\] 其次,你需要启动WSL内部的Linux分发版本,并运行以下代码来启用systemd: ``` # 在/etc/wsl.conf中启用systemd { cat <<EOT \[boot\] systemd=true EOT } | sudo tee /etc/wsl.conf exit ``` 这将在WSL中启用systemd。\[2\] 最后,你需要重启WSL并测试systemctl命令。可以使用以下命令来完成这一步骤: ``` wsl --shutdown wsl --distribution Ubuntu ``` 其中,Ubuntu指的是你的镜像版本,你可以根据使用wsl -l -v命令输出的第一列来确定。\[3\] 完成以上步骤后,你就可以在WSL中搭建深度学习系统了。你可以根据自己的需求安装相应的深度学习框架和工具。 #### 引用[.reference_title] - *1* *2* *3* [2023最新WSL搭建深度学习平台教程(适用于Docker-gpu、tensorflow-gpu、pytorch-gpu)](https://blog.csdn.net/qq_33963320/article/details/130094774)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值