TigerBot-70b-4k-v4 推理部署

TigerBot-70b-4k-v4 推理部署

模型本地部署

根据实际测试,加载模型需要约120G显存,最低需要6张3090显卡(流水线并行)

如果使用vllm进行加速推理(张量并行),考虑8张3090显卡或者4张A100-40G(模型分割要求)

模型下载

截至目前(2023.12.4),模型数据仅在huggingface上保存,在恒源云上的下载方式如下:

开启恒源云代理

export https_proxy=http://turbo.gpushare.com:30000 http_proxy=http://turbo.gpushare.com:30000

访问模型下载地址

在这里建议使用wget下载模型文件,优点是能够断点续传,下方是wget示例

wget https://huggingface.co/TigerResearch/tigerbot-70b-chat-v4-4k/resolve/main/pytorch_model-00001-of-00015.bin

关闭恒源云代理

unset http_proxy && unset https_proxy

依赖安装

克隆官方github仓库

git clone https://github.com/TigerResearch/TigerBot.git && cd Tigerbot

安装依赖库

pip install -r requirements.txt

模型推理

对于普通的多卡推理,示例推理代码如下

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python infer.py --model_path /path/to/your/model --max_input_length 1024 --max_generate_length 1024 --streaming True

相关参数说明

--model_path: 模型路径
--model_type=chat: base/chat
--max_input_length=1024: 最大输入长度
--max_generate_length=1024: 最大输出长度
--rope_scaling=None: 长度外推方法(dynamic/yarn supported now)
--rope_factor=8.0: 外推参数

量化

官方提供了在线量化与推理的方法

CUDA_VISIBLE_DEVICES=0,1,2,3 python other_infer/quant_infer.py --model_path /path/to/your/model --wbit 8

vllm 加速推理

安装vllm

pip install vllm

创建新的推理.py文件

import torch
from vllm import LLM, SamplingParams
 
# Set the number of GPUs you want to use
num_gpus = 8  # Change this to the number of GPUs you have
 
# Define your prompts and sampling parameters
prompts = """
### Instruction:
第一次指令

### Instruction:
第二次指令

### Response:
"""
sampling_params = SamplingParams(temperature=1, top_p=0.9, top_k=50, max_tokens=512, stop="</s>")
 
# Initialize the VLLM model
llm = LLM(model="/hy-tmp/tigerbot-70b-chat-v4-4k", tensor_parallel_size=8, trust_remote_code=True)
 
# Move the model to GPUs
llm = torch.nn.DataParallel(llm, device_ids=list(range(num_gpus)))
 
# Generate outputs
outputs = llm.module.generate(prompts, sampling_params)
 
# Print the outputs
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

需要注意的是这里的提示词格式与llama2不同,tigerbot的提示词遵循以下格式

### Instruction:
第一次指令

### Instruction:
第二次指令

### Response:

报错修复指引

安装过程中的报错大多是由于依赖库的版本问题,调整后可以解决。

flash-attn库安装报错
/home/user/miniconda3/envs/textgen/lib/python3.10/site-packages/flash_attn_2_cuda.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZNK3c106SymIntltEl

修复方法:重新构建 flash-attn库

pip uninstall flash-attn
FLASH_ATTENTION_FORCE_BUILD=TRUE pip install flash-attn
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用langchain和chatglm进行知识库的搭建,可以按照以下步骤进行操作: 1. 首先,确保你已经将langchain和chatglm这两个工具部署到本地。 2. 通过GitHub获取langchain-ChatGLM的源代码,可以在该项目的GitHub页面找到相关信息。 3. 在langchain-ChatGLM的代码仓库中,可以找到详细的使用说明文档。你可以在文档的StartOption.md文件中找到有关langchain和chatglm的具体使用方法。 4. 阅读文档中的说明,了解如何使用langchain和chatglm搭建本地的知识库。文档将提供一些关于配置选项和参数的指导,以便你能够正确地设置和启动langchain和chatglm。 5. 根据文档中的指示,配置langchain和chatglm的参数,确保它们能够协同工作。这可能涉及到设置语言模型、知识库的路径、启动选项等。 6. 启动langchain和chatglm,确保它们能够正常运行。 通过按照以上步骤操作,你就可以成功地使用langchain和chatglm搭建本地的知识库了。请确保在使用过程中,参考文档中的说明,以便正确地配置和启动这两个工具。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ModaHub魔搭社区:ChatGLM 集成进LangChain的教程](https://blog.csdn.net/qinglingye/article/details/131493038)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [利用langchain-ChatGLM、langchain-TigerBot实现基于本地知识库的问答应用](https://blog.csdn.net/u013171226/article/details/131554340)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值