BaiChuan2 模型部署教程更多详细信息见 Github仓库
BaiChuan2 项目自带了 Web 交互界面,并在项目运行中自动下载所需的模型参数。因此,克隆项目后,安装好项目所需环境,然后直接运行即可,下面将以Baichuan2-13B-Chat模型进行部署,由于模型较大建议使用RTX3090及以上显卡。
进入 Anaconda 官网:
找到快速命令行安装,选择 Linux 系统,复制代码进入终端进行安装。


等待安装完成。
apt-get update
apt-get install -y unzip
apt-get install -y lsof
apt-get install -y git
apt-get install -y git-lfs

git clone https://github.com/baichuan-inc/Baichuan2.git
cd Baichuan2

conda create -n Baichuan2 python=3.11
conda activate Baichuan2
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple

为了安装速度更快可以将 pip 进行永久换源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements.txt

streamlit run --server.address 0.0.0.0 --server.port 8080 web_demo.py
出现以下页面即为运行成功(使用了RTX3090)

若使用RTX3060则会出现以下运行不成功页面

RTX3090在运行Baichuan2-13B-Chat模型时仅仅只是运行成功,文字生成的速度大概是一秒钟两个字左右,若想要速度更快,则需要更换更加轻量化的模型,可以使用在线量化,以下用Baichuan2-13B-Chat模型的4bits量化模型作为示例
打开web_demo.py文件,替换相应代码
model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan2-13B-Chat", torch_dtype=torch.float16, trust_remote_code=True)
model = model.quantize(4).cuda()


重新运行后生成速度每秒可达到十多字!
运行成功后获取访问链接,进入 webUI 界面后即可操作:

点击此处,立即体验BaiChuan2!
