docker容器搭建chatglm2-6b

服务器环境:

显卡驱动:Driver Version: 530.30.02

CUDA版本:CUDA Version: 12.1

显卡:NVIDIA GeForce RTX 3090共4张

注意:最好把显卡驱动升级到530,CUDA版本之前使用11.7有问题。

docker-compose.yml内容如下:

version: "3.2"
services:
  chatglm2-6b:
    container_name: chatglm2-6b
    environment:
      TZ: Asia/Shanghai
    image: woshikid/chatglm2-6b:int4
    ports:
      - "8001:8000"
    command:
      [
        "/bin/sh",
        "-c",
        "python openai_api.py",
      ]

    restart: always
    shm_size: "8g"

    networks:
      - general
    deploy:
      resources:
        reservations:
          devices:
            - device_ids: ['2','3']
              capabilities: ["gpu"]
              driver: "nvidia"
networks:
  general:
    external: true

使用的镜像说明地址为:

Docker Hubicon-default.png?t=N7T8https://hub.docker.com/r/woshikid/chatglm2-6b

用的是int4量化模型,实际对话过程中发现并没有使用显卡!

进入容器,修改openai_api.py文件,修改末尾的代码,将代码:

if __name__ == "__main__":
    tokenizer = AutoTokenizer.from_pretrained("/chatglm2-6b-int4", trust_remote_code=True)
    model = AutoModel.from_pretrained("/chatglm2-6b-int4", trust_remote_code=True).float()
    # 多显卡支持,使用下面两行代替上面一行,将num_gpus改为你实际的显卡数量
    #from utils import load_model_on_gpus
    #model = load_model_on_gpus("/chatglm2-6b-int4", num_gpus=2)
    model.eval()

 改为:

if __name__ == "__main__":
    tokenizer = AutoTokenizer.from_pretrained("/chatglm2-6b-int4", trust_remote_code=True)
    #model = AutoModel.from_pretrained("/chatglm2-6b-int4", trust_remote_code=True).float()
    # 多显卡支持,使用下面两行代替上面一行,将num_gpus改为你实际的显卡数量
    from utils import load_model_on_gpus
    model = load_model_on_gpus("/chatglm2-6b-int4", num_gpus=2)
    model.eval()

运行时出现错误,RuntimeError: Library cudart is not initialized。

这是因为CUDA库文件损坏或者没安装导致的,这是最大的坑,执行下面代码安装:

apt update
apt install nvidia-cuda-toolkit

默认安装了cuda11.8版本,所以宿主的CUDA版本一定要>=cuda11.8,否则安装后仍然提示错误:RuntimeError: Unexpected error from cudaGetDeviceCou。

把chatglm2-6b接入到fastgpt,秒级反应,效果不错。

参考:

LLM探索:环境搭建与模型本地部署-CSDN博客 

ChatGLM-6B-int4模型部署_本地部署chatglm-6b-int4模型-CSDN博客 

[BUG/Help] 加载模型时遇到 RuntimeError: Library cuda is not initialized 问题 · Issue #839 · THUDM/ChatGLM-6B (github.com)

[BUG/Help] <title> RuntimeError: Library cudart is not initialized · Issue #115 · THUDM/ChatGLM-6B (github.com) 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值