一.我们需要从git hub上将langchain-chatchat-0.3.1这个项目给拉取下来,接着部署项目,我们试着根据官方提供的README将整个项目跑通。
1.本次基于autodl服务器实现部署,先租对应的服务器
(1).注册好autodl账户之后,开始租服务器,这里以glm4-9b-chat这个模型为例,地区我租的西北B区的,GPU我选择的是RTX4090(一张),基础镜像选择的是Pytorch-2.3.0-python-3.12(ubuntu22.04)- cuda版本12.1。
二. 部署langchain-chatchat-0.3.1项目
1.先从github上将新版本的项目拉取下来,指令如下
git clone https://github.com/chatchat-space/Langchain-Chatchat.git
2.需要新建两个不同的虚拟环境,一个为了运行模型,一个为了运行项目代码,第一个虚拟环境为了存储模型所需要的环境
conda create -n llm_tl python==3.11
3.对于一个全新的机子来说新建完虚拟环境无法做到直接激活,重新加载你的shell配置
输入以下指令,
source ~/.bashrc
conda init
4.开始激活新建好的环境
conda activate llm_tl
5.首先进行模型推理框架的运行,并加载所需使用的模型
如果你希望能够推理所有支持的模型,可以用以下命令安装所有需要的依赖:
pip install "langchain-chatchat[xinference]" -U
pip install "xinference[all]" -i https://pypi.tuna.tsinghua.edu.cn/simple
6.PyTorch(transformers) 引擎支持几乎有所的最新模型,这是 Pytorch 模型默认使用的引擎:
pip install "xinference[transformers]" -i https://pypi.tuna.tsinghua.edu.cn/simple
7.安装 xinference 和 vLLM:
pip install "xinference[vllm]"
8.Xinference 通过 llama-cpp-python
支持 gguf
和 ggml
格式的模型。建议根据当前使用的硬件手动安装依赖,从而获得最佳的加速效果。初始步骤:
pip install xinference -i https://pypi.tuna.tsinghua.edu.cn/simple
9.安装英伟达显卡:
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python -i https://pypi.tuna.tsinghua.edu.cn/simple
10.SGLang 具有基于 RadixAttention 的高性能推理运行时。它通过在多个调用之间自动重用KV缓存,显著加速了复杂 LLM 程序的执行。它还支持其他常见推理技术,如连续批处理和张量并行处理。
pip install 'xinference[sglang]' -i https://pypi.tuna.tsinghua.edu.cn/simple
11.本地运行Xinference,让我们以一个经典的大语言模型 glm4-9b-chat 来展示如何在本地用 Xinference 运行大模型,我这里自定义了一个存储日志文件和大模型,embidding模型的路径,如果不自定义一个路径将会下载到默认的一个路径下,这样很容易将我们的系统盘给撑爆,以魔塔社区下载模型为例。
XINFERENCE_HOME=/root/autodl-tmp/xinference XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port 9997
12.我们启动模型有两种方式一种是通过指令来下载模型,或者我们运行起9997端口号下的地址手动下载模型,
指令下载方式
xinference launch --model-engine vllm --model-name glm4-chat --size-in-billions 9 --model-format pytorch --quantization none