北大代码大模型CodeShell-7B 本地部署记录

本文详细描述了如何在北大环境下使用CodeShell-7B模型进行本地Docker部署,包括服务器准备、容器创建、环境设置、依赖安装、模型测试以及远程访问的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境

显卡内存参考20G大小

服务器:创建部署目录

# 若有git则直接进入step1,没有进入step2

# step 1: 安装git
	apt-get update
	apt-get install git -y
	
# step2: 在/home/自定义目录(一般用户名)/,目录下载github示例文件,在下载的/home/自定义目录/codeshell/目录下载模型文件
	# github示例文件 (下载的git本地目录叫codeshell,故目录全路径为 "/home/自定义目录/codeshell/" )
		git clone https://github.com/WisdomShell/codeshell.git 
	# 模型文件,二选一。国外好处是可以找老板要科学上网,并多摸一会🐟
		cd ./codeshell
		git clone https://huggingface.co/WisdomShell/CodeShell-7B-Chat # 国外 需科学上网
		# or
		git clone https://www.modelscope.cn/WisdomShell/CodeShell-7B-Chat.git # 国内

至此,/home/自定义目录/codeshell/下存放示例文件,codeshell目录下有一个叫CodeShell-7B-Chat的目录存放模型。
目录示例

服务器:创建容器

docker run --gpus "device=0" -it --name 自定义容器名(这里我用的codeshell) -v /home/自定义目录/codeshell:/workspace/codeshell -p 7861:7861 -d pytorch/pytorch:2.1.0-cuda12.1-cudnn8-devel

创建容器的同时,做了目录挂载-v,方便后续操作文件,也做了端口映射,方便后续使用特定端口。
容器示例

服务器:启动容器

docker start codeshell

启动容器

服务器:进入容器

docker exec -it codeshell /bin/bash

进入容器

容器内:初次使用创建python环境

conda create -n codeshell python=3.10

按y
在这里插入图片描述

容器内:激活conda环境

#针对没激活activate的容器,初次使用激活activate
source activate 
conda activate codeshell

激活环境

容器内:更新pip源

python -m pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

更新pip

容器内:下载环境依赖库

# 默认进入容器后在workspace目录下,所以需要切换目录
cd ./codeshell
pip install -r requirement.txt
cd ./demos
pip install -r requirements_web_demo.txt

requirement
webrequirement

容器内:检测torch、gpu是否可用

python
import torch
print(torch.cuda.is_available()) # 期望输出为True
exit()

在这里插入图片描述

容器内:修改示例文件web_demo.py

# 修改模型目录
DEFAULT_CKPT_PATH = '/workspace/codeshell/CodeShell-7B-Chat'
# 修改web端口为7861,和创建容器时的映射端口一致
parser.add_argument("--server-port", type=int, default=7861, help="Demo server port.")
# 修改默认ip为0.0.0.0,方便远程映射时保留主机ip
parser.add_argument("--server-name", type=str, default="0.0.0.0", help="Demo server name.")

web_demo

容器内:运行web_demo.py

# 当前目录为/workspace/codeshell/demos,若为其他目录,运行时可cd目录,也可python /workspace/codeshell/demos/web_demo.py
python web_demo.py

运行

本地客户机:即与服务器非同一台电脑,远程连接服务器部署网页

unix服务器部署模型,自己的笔记本windows连接服务器~

ssh -L 7861:0.0.0.0:7861 用户名@服务器ip
#回车输入服务器用户密码

在这里插入图片描述

本地客户机:打开浏览器输入127.0.0.1:7861

显示codeshell主页
在这里插入图片描述

至此部署完毕,若要尝试自定义api接口,可在服务器查看示例文件demos下的api示例、cli示例,利用huggingface transformer接口加载模型使用。(记得切换模型路径等配置)

参考引用

[1] https://github.com/WisdomShell/codeshell

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我喝AD钙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值