搭建清华ChatGLM2-6B

一、环境配置

  ChatGLM2-6B至少需要13G GPU(虽然官网说12G即可),int8需要8G,int4需要4G。

  Win10系统,GTX1060显卡6GB(只能用int4模型,亲测开启GLM2时占了5GB以上)

  1、git  

  2、conda 

  3、python 3.9

  4、pip

  5、CUDA 11.1 (GPU相关)

  6、torch 1.10.1  (跟CUDA版本对应)

  

二、安装工具

  conda安装(Anaconda工具

    方便进行环境隔离,不影响其他项目,且随时删除重新创建。

    官网下载:https://www.anaconda.com/download/success

    参考教程:https://blog.csdn.net/weixin_42081445/article/details/136928005

    这里创建了py39新环境,点击绿色按钮=》选择Open Terminal终端。会看到前面带有(py39)这个时候,可以尝试conda list查看包,然后python进入的也是3.9版本。

  

  CUDA 安装(GPU相关)

    官网下载:https://developer.nvidia.com/cuda-11.1.0-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal

    参考教程:https://blog.csdn.net/qq_46126258/article/details/112708781

    通过 NVIDIA-smi 命令查看CUDA的版本(v11.1)和内存6GB。

 

  Torch框架(PyTorch)的安装(机器学习库)

    官方下载:https://pytorch.org/get-started/previous-versions/#v1101

    torch的版本是1.10.1(对应CUDA 11.1)

# conda
(py39)~]# conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 -c pytorch

 

三、安装项目

  ChatGLM2-6B项目

    Github项目:https://github.com/THUDM/ChatGLM2-6B

~]# git clone https://github.com/THUDM/ChatGLM2-6B
~]# cd ChatGLM2-6B

    查看文件夹中的requirements.txt的列表,因为安装了torch库,所以这里删除torch的条目。 

     执行pip下载文件。(清华源镜像,在后面加:-i https://pypi.tuna.tsinghua.edu.cn/simple/ )

~]# pip install -r requirements.txt
~]# pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/

  模型数据 

    模型数据:https://cloud.tsinghua.edu.cn/d/674208019e314311ab5c/?p=%2F&mode=list

    模型数据项目:https://huggingface.co/THUDM/chatglm2-6b/tree/main

    显卡内存为6GB,所以符合int4的模型。模型量化会带来一定的性能损失,ChatGLM2-6B 在 4-bit 量化下仍然能够进行自然流畅的生成。

~]# git clone https://huggingface.co/THUDM/chatglm2-6b-int4

    

四、部署运行

  先修改对应文件的内容,将红色框框改成自定义的chatglm2-6b-int4的路径。

  运行模式:

    1.api方式部启动,执行命令: python api.py

    2.命令行方式启动,执行命令:python cli_demo.py

    3.网页方式启动,执行命令:python web_demo.py

    4. OpenAI 格式启动,执行命令:python openai_api.py

  这边试用网页方式启动。可以访问http://127.0.0.1:7860/

 

 

 
posted @ 2024-04-19 16:40  Auler  阅读(26)  评论(0编辑  收藏  举报