baichuan2_tgi baichuan2提供了高性能的推理服务的对话问答模型

Baichuan2

论文

模型结构

模型具体参数:

模型名称隐含层维度层数头数词表大小位置编码最大长
Baichuan 2-7B4,0963232125,696RoPE4096
Baichuan 2-13B5,1204040125,696ALiBi4096

算法原理

Baichuan整体模型基于标准的Transformer结构,采用了和LLaMA一样的模型设计。其中,Baichuan-7B在结构上采用Rotary Embedding位置编码方案、SwiGLU激活函数、基于RMSNorm的Pre-Normalization。Baichuan-13B使用了ALiBi线性偏置技术,相对于Rotary Embedding计算量更小,对推理性能有显著提升。

环境配置

Docker(方法一)

docker pull  image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.2-py3.10

docker run -it -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal:/opt/hyhal:ro --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash

  1. 安装Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. 安装Protoc
PROTOC_ZIP=protoc-21.12-linux-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v21.12/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
  1. 安装TGI Service
cd baichuan2_tgi
cd text-generation-inference
#安装exllama
cd server
make install-exllama #安装exllama kernels
make install-exllamav2 #安装exllmav2 kernels
cd .. #回到项目根目录
source $HOME/.cargo/env
BUILD_EXTENSIONS=True make install #安装text-generation服务
  1. 安装benchmark
cd text-generation-inference
make install-benchmark

注意:若安装过程过慢,可以通过如下命令修改默认源提速。

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

另外,cargo install 太慢也可以通过在~/.cargo/config中添加源来提速。

  1. 查看安装的版本号
text-generation-launcher -V  #版本号与官方版本同步

数据集

推理

模型下载

Baichuan2-7B-Base

Baichuan2-7B-Chat

部署TGI

使用前
export PYTORCH_TUNABLEOP_ENABLED=0
1. 启动TGI服务
HIP_VISIBLE_DEVICES=2 text-generation-launcher --dtype=float16 --model-id /models/baichuan2/Baichuan2-7B-Chat --trust-remote-code --port 3001

更多参数可使用如下方式查看

text-generation-launcher --help
2. 请求服务

curl命令方式:

curl 127.0.0.1:3001/generate \
    -X POST \
    -d '{"inputs":"What is deep learning?","parameters":{"max_new_tokens":100,"temperature":0.7}}' \
    -H 'Content-Type: application/json'

通过python调用的方式:

import requests

headers = {
    "Content-Type": "application/json",
}

data = {
    'inputs': 'What is Deep Learning?',
    'parameters': {
        'max_new_tokens': 20,
    },
}

response = requests.post('http://127.0.0.1:3001/generate', headers=headers, json=data)
print(response.json())
# {'generated_text': ' Deep Learning is a subset of machine learning where neural networks are trained deep within a hierarchy of layers instead'}

更多API查看,请参考 Text Generation Inference API

result

精度

应用场景

算法类别

对话问答

热点应用行业

金融,科研,教育

源码仓库及问题反馈

参考资料

  • TGI为baichuan2提供了高性能的推理服务
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

技术瘾君子1573

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

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

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

打赏作者

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

抵扣说明:

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

余额充值