当前位置:   article > 正文

记录 使用fastllm转换chatGLM并部署_chatglm2 fastllm

chatglm2 fastllm

使用fastllm转换chatGLM并部署

发这个文章记录我的使用过程。。。俺只是使用,记录一下,怕以后忘记~~~~

1. 下载 fastllm

github地址:

https://github.com/ztxz16/fastllm
  • 1

2. 安装fastllm

下面是官方md中的安装方法:

cd fastllm
mkdir build
cd build
cmake .. -DUSE_CUDA=ON # 如果不使用GPU编译,那么使用 cmake .. -DUSE_CUDA=OFF
make -j
cd tools && python setup.py install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3. 遇到的问题:

我在 cmake这一步持续报错,有两个:

  1. 执行 cmake … -DUSE_CUDA=ON遇到了如下错误:
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.

Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这个错误是因为Cmake没有找到C++编译器,需要你安装

  • 对于 Debian/Ubuntu 系统:

    sudo apt-get install g++
    
    • 1
  • 对于 CentOS/RHEL 系统:

    sudo yum install gcc-c++
    
    • 1
  1. 解决上面的问题后,又频繁报错:
c++: 错误:unrecognized command line option ‘--std=c++17’ :
  • 1

这是因为之前下载的c++编译器版本太旧引起的,需要更新。

我用的服务器系统是CentOS7,需要使用如下指令(Debian/Ubuntu 系统可以自行更新一下,这里我没验证过,就不列举了):

sudo yum install centos-release-scl
sudo yum install devtoolset-9-gcc-c++
scl enable devtoolset-9 bash
#验证版本
g++ --version
  • 1
  • 2
  • 3
  • 4
  • 5

到这步就可以重新安装了。

但是我好像就执行到make -j,没有执行后面的那一条

4. 转换模型

上述指令如果都执行成功以后,在你新建的build文件夹下会生成很多文件。需要找到chatglm_export.py文件,修改里面的模型位置,替换成你自己本地的。

脚本地址:

your_path_to/build/tools/chatglm_export.py
  • 1

脚本的内容

import sys
from transformers import AutoTokenizer, AutoModel
from fastllm_pytools import torch2flm

if __name__ == "__main__":
    tokenizer = AutoTokenizer.from_pretrained("/your_path_to/chatglm3-6b", trust_remote_code=True)#替换
    model = AutoModel.from_pretrained("/your_path_to/chatglm3-6b", trust_remote_code=True)#替换
    model = model.eval()

    dtype = sys.argv[2] if len(sys.argv) >= 3 else "float16"
    exportPath = sys.argv[1] if len(sys.argv) >= 2 else "chatglm-6b-" + dtype + ".flm" ##这个地方我修改了引号,官方的好像有点问题
    torch2flm.tofile(exportPath, model, tokenizer, dtype = dtype)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

然后使用python命令执行就好,执行成功后当前位置会生成一个.flm文件,就是转换的文件

然后可以使用官方给的方式执行(我验证了前两种):

# 命令行聊天程序, 支持打字机效果
./main -p model.flm 

# 简易webui, 使用流式输出 + 动态batch,可多路并发访问
./webui -p model.flm --port 1234 

# python版本的命令行聊天程序,使用了模型创建以及流式对话效果
python tools/cli_demo.py -p model.flm 

# python版本的简易webui,需要先安装streamlit-chat
streamlit run tools/web_demo.py model.flm 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

!!!!!!注意路径是不一致的,如果你没有mv过文件,main、webui文件和模型文件好像不在同一个目录下,结合自己的情况改一下!!!!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/260469
推荐阅读
相关标签
  

闽ICP备14008679号