GPT中文GPT中文论坛社区AI工具软件大全 GPT.CC Claude Fable 5 · GPT-5.6 直连,不用连国际网 去看看 →
AI工具软件大全
首页 / 文章 / 智谱清言 快速上手教程(GitHub README 中文整理)
📖 教程 · 6 分钟读完 · 2026-07-24

智谱清言 快速上手教程(GitHub README 中文整理)

从 智谱清言 官方 GitHub README 翻译整理的快速上手指南。

ChatGLM-6B 快速上手教程

是什么

ChatGLM-6B 是由智谱AI与清华大学开源的中英双语对话语言模型,基于 General Language Model (GLM) 架构,拥有 62 亿参数。它采用了与 ChatGPT 相似的技术路线,针对中文问答和对话进行了深度优化。

该模型最大的亮点在于低门槛部署:通过模型量化技术,INT4 量化级别下最低仅需 6GB 显存即可在消费级显卡上运行。模型权重对学术研究完全开放,填写问卷登记后也允许免费商业使用。

能干什么

ChatGLM-6B 主要面向以下场景:

怎么装

环境要求

安装步骤

# 1. 克隆仓库
git clone https://github.com/THUDM/ChatGLM-6B.git
cd ChatGLM-6B

# 2. 安装依赖
pip install -r requirements.txt

# 3. 安装 PyTorch(根据 CUDA 版本选择)
# CUDA 11.6
pip install torch==1.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
# CUDA 11.7
pip install torch==1.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117

模型下载

模型权重会自动从 Hugging Face 下载,国内访问受限时可使用镜像站点:

# 设置镜像
export HF_ENDPOINT=https://hf-mirror.com

怎么用:第一个例子

命令行交互

创建 cli_demo.py

from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
model = model.eval()

# 多轮对话
history = []
while True:
    query = input("\n用户: ")
    if query == "exit":
        break
    response, history = model.chat(tokenizer, query, history=history)
    print(f"ChatGLM: {response}")

运行:

python cli_demo.py

Web 界面

# 启动 Gradio 界面
python web_demo.py

访问 http://localhost:7860 即可在浏览器中对话。

社区资源


注意事项


翻译整理自 GitHub README,原文:https://github.com/THUDM/ChatGLM-6B

01

本文涉及的工具

02

相关阅读