开源类似chatGPT项目ChatGLM-6B单显卡安装运行成功

项目git地址

https://github.com/THUDM/ChatGLM-6B

配置要求:

本机电脑显卡显存6G以上。只有cpu则需要32GB以上。

安装基础环境

1.安装python 3.10版本

https://www.python.org/ftp/python/3.10.10/python-3.10.10-amd64.exe

2.安装cuda(有显卡)

下载页面

https://developer.nvidia.com/cuda-downloads

3.根据ChatGLM-6B文档要求,修改cli_demo.py

import os
import platform
import torch

from transformers import AutoTokenizer, AutoModel
# 此处如果为false则证明torch的gpu版本没有安装好
print(torch.cuda.is_available()) 
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4-qe", trust_remote_code=True)
print("tokenizer")
# model = AutoModel.from_pretrained("/Users/zhengxiaodu/Downloads/chatglm-6b", trust_remote_code=True).half().to("mps")
model = AutoModel.from_pretrained("THUDM/chatglm-6b-int4-qe", trust_remote_code=True).half().cuda()
print("model")
model = model.eval()

os_name = platform.system()
clear_command = 'cls' if os_name == 'Windows' else 'clear'


def build_prompt(history):
    prompt = "欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序"
    for query, response in history:
        prompt += f"\n\n用户:{query}"
        prompt += f"\n\nChatGLM-6B:{response}"
    return prompt


def main():
    history = []
    print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
    while True:
        query = input("\n用户:")
        if query == "stop":
            break
        if query == "clear":
            history = []
            os.system(clear_command)
            print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
            continue
        count = 0
        for response, history in model.stream_chat(tokenizer, query, history=history):
            count += 1
            if count % 8 == 0:
                os.system(clear_command)
                print(build_prompt(history), flush=True)
        os.system(clear_command)
        print(build_prompt(history), flush=True)


if __name__ == "__main__":
    main()

4.下载项目

git clone https://github.com/THUDM/ChatGLM-6B
cd ChatGLM-6B

5.安装

pip install -r requirements.txt

6.运行

python cli_demo.py

报错信息如下:

 可能是bin文件下载到一半失败

手动下载

https://huggingface.co/THUDM/chatglm-6b-int4-qe/blob/main/pytorch_model.bin

或者下载我分享的夸克网盘地址:

链接:https://pan.quark.cn/s/aabf027bef92

文件列表中的
pytorch_model.bin

 删除目录中

C:\Users\lxr\.cache\huggingface\hub\models--THUDM--chatglm-6b-int4-qe\snapshots\437fc94474689e27adfcb29ef768bfaef9be5c45

的所有文件,并把bin文件复制过来。重新运行

python cli_demo.py

报错截图:

   这个报错也许是由于cuda未安装,或者是没有安装gcc,或者是torch版本不是gpu版本,下面尝试安装

下载安装cuDNN

  打开网址:https://developer.nvidia.com/cudnn,点击Download cuDNN,需要登陆Nvidia账号,没有可以用邮箱注册一下,填写基本信息就可以。

 安装pytorch的cuda版本

  安装前删除C:\Users\lxr\AppData\Local\Programs\Python\Python310\Lib\site-packages目录下的torch相关目录

  运行 pip uninstall torch 命令

  https://download.pytorch.org/whl/torch_stable.html

  下载:https://download.pytorch.org/whl/cu118/torch-2.0.0%2Bcu118-cp310-cp310-win_amd64.whl

  下载:https://download.pytorch.org/whl/cu118/torchvision-0.15.1%2Bcu118-cp310-cp310-win_amd64.whl

  其中cp310代表python版本是3.10,win_amd64是windows平台,cu118是cuda版本11.8

  pip install "torch-2.0.0+cu118-cp310-cp310-win_amd64.whl"

     pip install "torchvision-0.15.1+cu118-cp310-cp310-win_amd64.whl"

成功启动:

 

问题和回答案例:

系统性能消耗:

本电脑配置 16GB内存,RTX3060ti 8G ,AMD Ryzen 7 3700X 8-Core Processor 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

lxr1908

用钱砸我

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

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

打赏作者

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

抵扣说明:

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

余额充值