BaiChuan2容器构建指南

一、介绍

  • Baichuan 2 是百川智能推出的 新一代开源大语言模型 ,采用 2.6 万亿 Tokens 的高质量语料训练。
  • Baichuan 2 在一系列权威的中文、英文和多语言的通用、领域 benchmark 上达到了同尺寸最佳的效果。
  • 涵盖了 7B 、13B 的 Base 和 Chat 版本,并提供了 Chat 版本的 4bits 量化 。

更多详细信息见 Github仓库

二、容器构建说明

BaiChuan2 项目自带了 Web 交互界面,并在项目运行中自动下载所需的模型参数。因此,克隆项目后,安装好项目所需环境,然后直接运行即可,下面将以Baichuan2-13B-Chat模型进行部署,由于模型较大建议使用RTX3090及以上显卡

1. 安装 miniconda

进入 Anaconda 官网:

Miniconda — Anaconda 文档

找到快速命令行安装,选择 Linux 系统,复制代码进入终端进行安装。

image.png

image.png

等待安装完成。

2. 安装并更新基础命令,让后续使用更快捷: unzip、lsof、git、git-lfs

apt-get update
apt-get install -y unzip
apt-get install -y lsof
apt-get install -y git
apt-get install -y git-lfs

image.png

3. 克隆项目仓库,并打开文件

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

image.png

4. 创建python为3.11版本的虚拟环境,名称为Baichuan2

conda create -n Baichuan2 python=3.11

5. 激活虚拟环境Baichuan2

conda activate Baichuan2

6. 通过pip安装所需的torch环境(国内镜像源快一些,以下使用了清华源)

pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple

image.png

7. 安装项目依赖文件

为了安装速度更快可以将 pip 进行永久换源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements.txt

image.png

8. 指定端口,运行py文件(运行项目,首次运行会自动下载模型参数,需要保证网络通畅)

streamlit run --server.address 0.0.0.0 --server.port 8080 web_demo.py

出现以下页面即为运行成功(使用了RTX3090)

image.png

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

image.png

9. 注意

RTX3090在运行Baichuan2-13B-Chat模型时仅仅只是运行成功,文字生成的速度大概是一秒钟两个字左右,若想要速度更快,则需要更换更加轻量化的模型,可以使用在线量化,以下用Baichuan2-13B-Chat模型的4bits量化模型作为示例

打开web_demo.py文件,替换相应代码

model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan2-7B-Chat", torch_dtype=torch.float16, trust_remote_code=True)
model = model.quantize(4).cuda() 

image.png

image.png

重新运行后生成速度每秒可达到十多字!

三、网页演示

运行成功后获取访问链接,进入 webUI 界面后即可操作:

image.png

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值