Code Monkey home page Code Monkey logo

chatglm3's Introduction

ChatGLM3

🤗 HF Repo • 🤖 ModelScope • 🤖 WiseModel • 🧰 OpenXLab • 🐦 Twitter • 📃 [GLM@ACL 22] [GitHub] • 📃 [GLM-130B@ICLR 23] [GitHub]

👋 加入我们的 Slack微信

📍在 chatglm.cn 体验更大规模的 ChatGLM 模型。

Read this in English.

📔 关于ChatGLM3-6B 更为详细的使用信息,可以参考

GLM-4 介绍

我们已经发布最新的 GLM-4 模型,该模型在多个指标上有了新的突破,您可以在以下两个渠道体验我们的最新模型。

  • 智谱清言 体验最新版 GLM-4,包括 GLMs,All tools等功能,下载 智谱清言 APP 或者使用 网页端

  • API平台 新一代 API 平台已经上线,您可以直接在 API 平台上体验 GLM-4GLM-3-TurboCharacterGLM-3CogView-3 等新模型。 其中GLM-4GLM-3-Turbo两个模型支持了 System PromptFunction CallRetrievalWeb_Search等新功能,欢迎体验。

  • GLM4 API 开源教程 GLM-4 API教程和基础应用,欢迎尝试。 API相关问题可以在本开源教程疑问,或者使用GLM-4 API AI助手 来获得常见问题的帮助。


ChatGLM3 介绍

ChatGLM3 是智谱AI和清华大学 KEG 实验室联合发布的对话预训练模型。ChatGLM3-6B 是 ChatGLM3 系列中的开源模型,在保留了前两代模型对话流畅、部署门槛低等众多优秀特性的基础上,ChatGLM3-6B 引入了如下特性:

  1. 更强大的基础模型: ChatGLM3-6B 的基础模型 ChatGLM3-6B-Base 采用了更多样的训练数据、更充分的训练步数和更合理的训练策略。在语义、数学、推理、代码、知识等不同角度的数据集上测评显示,* ChatGLM3-6B-Base 具有在 10B 以下的基础模型中最强的性能*。
  2. 更完整的功能支持: ChatGLM3-6B 采用了全新设计的 Prompt 格式 ,除正常的多轮对话外。同时原生支持工具调用(Function Call)、代码执行(Code Interpreter)和 Agent 任务等复杂场景。
  3. 更全面的开源序列: 除了对话模型 ChatGLM3-6B 外,还开源了基础模型 ChatGLM3-6B-Base 、长文本对话模型 ChatGLM3-6B-32K 和进一步强化了对于长文本理解能力的 ChatGLM3-6B-128K。以上所有权重对学术研究完全开放 ,在填写 问卷 进行登记后亦允许免费商业使用

ChatGLM3 开源模型旨在与开源社区一起推动大模型技术发展,恳请开发者和大家遵守 开源协议 ,勿将开源模型和代码及基于开源项目产生的衍生物用于任何可能给国家和社会带来危害的用途以及用于任何未经过安全评估和备案的服务。目前,本项目团队未基于 ChatGLM3 开源模型开发任何应用,包括网页端、安卓、苹果 iOS 及 Windows App 等应用。

尽管模型在训练的各个阶段都尽力确保数据的合规性和准确性,但由于 ChatGLM3-6B 模型规模较小,且模型受概率随机性因素影响,无法保证输出内容的准确。同时模型的输出容易被用户的输入误导。* 本项目不承担开源模型和代码导致的数据安全、舆情风险或发生任何模型被误导、滥用、传播、不当利用而产生的风险和责任。*

模型列表

Model Seq Length Download
ChatGLM3-6B 8k HuggingFace | ModelScope | WiseModel | OpenXLab
ChatGLM3-6B-Base 8k HuggingFace | ModelScope | WiseModel | OpenXLabl
ChatGLM3-6B-32K 32k HuggingFace | ModelScope | WiseModel | OpenXLab
ChatGLM3-6B-128K 128k HuggingFaceModelScope| OpenXLab


请注意,所有模型的最新更新都会在 Huggingface 率先发布。 ModelScope 和 WiseModel 由于没有与 Huggingface 同步,需要开发人员手动更新,可能会在 Huggingface 更新后一段时间内同步更新。

友情链接

以下优秀开源仓库已经对 ChatGLM3-6B 模型深度支持,欢迎大家扩展学习。

推理加速:

  • chatglm.cpp: 类似 llama.cpp 的量化加速推理方案,实现笔记本上实时对话
  • ChatGLM3-TPU: 采用TPU加速推理方案,在算能端侧芯片BM1684X(16T@FP16,内存16G)上实时运行约7.5 token/s
  • TensorRT-LLM: NVIDIA开发的高性能 GPU 加速推理方案,可以参考此 步骤 部署 ChatGLM3-6B 模型
  • OpenVINO: Intel 开发的高性能 CPU 和 GPU 加速推理方案,可以参考此 步骤 部署 ChatGLM3-6B 模型

高效微调:

应用框架:

  • LangChain-Chatchat: 基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的检索增强生成(RAG)大模型知识库项目。

  • BISHENG: 开源大模型应用开发平台,赋能和加速大模型应用开发落地,帮助用户以最佳体验进入下一代应用开发模式。

评测结果

典型任务

我们选取了 8 个中英文典型数据集,在 ChatGLM3-6B (base) 版本上进行了性能测试。

Model GSM8K MATH BBH MMLU C-Eval CMMLU MBPP AGIEval
ChatGLM2-6B-Base 32.4 6.5 33.7 47.9 51.7 50.0 - -
Best Baseline 52.1 13.1 45.0 60.1 63.5 62.2 47.5 45.8
ChatGLM3-6B-Base 72.3 25.7 66.1 61.4 69.0 67.5 52.4 53.7

Best Baseline 指的是截止 2023年10月27日、模型参数在 10B 以下、在对应数据集上表现最好的预训练模型,不包括只针对某一项任务训练而未保持通用能力的模型。

对 ChatGLM3-6B-Base 的测试中,BBH 采用 3-shot 测试,需要推理的 GSM8K、MATH 采用 0-shot CoT 测试,MBPP 采用 0-shot 生成后运行测例计算 Pass@1 ,其他选择题类型数据集均采用 0-shot 测试。

我们在多个长文本应用场景下对 ChatGLM3-6B-32K 进行了人工评估测试。与二代模型相比,其效果平均提升了超过 50%。在论文阅读、文档摘要和财报分析等应用中,这种提升尤为显著。此外,我们还在 LongBench 评测集上对模型进行了测试,具体结果如下表所示

Model 平均 Summary Single-Doc QA Multi-Doc QA Code Few-shot Synthetic
ChatGLM2-6B-32K 41.5 24.8 37.6 34.7 52.8 51.3 47.7
ChatGLM3-6B-32K 50.2 26.6 45.8 46.1 56.2 61.2 65

使用方式

环境安装

首先需要下载本仓库:

git clone https://github.com/THUDM/ChatGLM3
cd ChatGLM3

然后使用 pip 安装依赖:

pip install -r requirements.txt
  • 为了保证 torch 的版本正确,请严格按照 官方文档 的说明安装。

综合 Demo

我们提供了一个集成以下三种功能的综合 Demo,运行方法请参考综合 Demo

  • Chat: 对话模式,在此模式下可以与模型进行对话。
  • Tool: 工具模式,模型除了对话外,还可以通过工具进行其他操作。

  • Code Interpreter: 代码解释器模式,模型可以在一个 Jupyter 环境中执行代码并获取结果,以完成复杂任务。

代码调用

可以通过如下代码调用 ChatGLM 模型来生成对话:

>> > from transformers import AutoTokenizer, AutoModel
>> > tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True)
>> > model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True, device='cuda')
>> > model = model.eval()
>> > response, history = model.chat(tokenizer, "你好", history=[])
>> > print(response)
你好👋!我是人工智能助手
ChatGLM3 - 6
B, 很高兴见到你, 欢迎问我任何问题>> > response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
>> > print(response)
晚上睡不着可能会让你感到焦虑或不舒服, 但以下是一些可以帮助你入睡的方法:

1.制定规律的睡眠时间表: 保持规律的睡眠时间表可以帮助你建立健康的睡眠习惯, 使你更容易入睡尽量在每天的相同时间上床, 并在同一时间起床2.创造一个舒适的睡眠环境: 确保睡眠环境舒适, 安静, 黑暗且温度适宜可以使用舒适的床上用品, 并保持房间通风3.放松身心: 在睡前做些放松的活动, 例如泡个热水澡, 听些轻柔的音乐, 阅读一些有趣的书籍等, 有助于缓解紧张和焦虑, 使你更容易入睡4.避免饮用含有咖啡因的饮料: 咖啡因是一种刺激性物质, 会影响你的睡眠质量尽量避免在睡前饮用含有咖啡因的饮料, 例如咖啡, 茶和可乐5.避免在床上做与睡眠无关的事情: 在床上做些与睡眠无关的事情, 例如看电影, 玩游戏或工作等, 可能会干扰你的睡眠6.尝试呼吸技巧: 深呼吸是一种放松技巧, 可以帮助你缓解紧张和焦虑, 使你更容易入睡试着慢慢吸气, 保持几秒钟, 然后缓慢呼气如果这些方法无法帮助你入睡, 你可以考虑咨询医生或睡眠专家, 寻求进一步的建议

从本地加载模型

以上代码会由 transformers 自动下载模型实现和参数。完整的模型实现在 Hugging Face Hub 。如果你的网络环境较差,下载模型参数可能会花费较长时间甚至失败。此时可以先将模型下载到本地,然后从本地加载。

从 Hugging Face Hub 下载模型需要先安装Git LFS ,然后运行

git clone https://huggingface.co/THUDM/chatglm3-6b

如果从你从 HuggingFace 下载比较慢,也可以从 ModelScope 中下载。

模型微调

我们提供了一个微调 ChatGLM3-6B 模型的基础套件,可以用来微调 ChatGLM3-6B 模型。微调套件的使用方法请参考 微调套件

网页版对话 Demo

web-demo 可以通过以下命令启动基于 Gradio 的网页版 demo:

python web_demo_gradio.py

web-demo

可以通过以下命令启动基于 Streamlit 的网页版 demo:

streamlit run web_demo_streamlit.py

网页版 demo 会运行一个 Web Server,并输出地址。在浏览器中打开输出的地址即可使用。 经测试,基于 Streamlit 的网页版 Demo 会更流畅。

命令行对话 Demo

cli-demo

运行仓库中 cli_demo.py

python cli_demo.py

程序会在命令行中进行交互式的对话,在命令行中输入指示并回车即可生成回复,输入 clear 可以清空对话历史,输入 stop 终止程序。

LangChain Demo

代码实现请参考 LangChain Demo

工具调用

关于工具调用的方法请参考 工具调用

OpenAI API / Zhipu API Demo

我们已经推出了 OpenAI / ZhipuAI 格式的 开源模型 API 部署代码,可以作为任意基于 ChatGPT 的应用的后端。 目前,可以通过运行仓库中的 api_server.py 进行部署

cd openai_api_demo
python api_server.py

同时,我们也书写了一个示例代码,用来测试API调用的性能。

curl -X POST "http://127.0.0.1:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-d "{\"model\": \"chatglm3-6b\", \"messages\": [{\"role\": \"system\", \"content\": \"You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.\"}, {\"role\": \"user\", \"content\": \"你好,给我讲一个故事,大概100字\"}], \"stream\": false, \"max_tokens\": 100, \"temperature\": 0.8, \"top_p\": 0.8}"
  • Standard openai interface agent-chat Curl 测试
curl -X POST "http://127.0.0.1:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-d "{\"model\": \"chatglm3-6b\", \"messages\": [{\"role\": \"user\", \"content\": \"37乘以8加7除2等于多少?\"}], "tools": [{"name": "track", "description": "追踪指定股票的实时价格",
          "parameters": {"type": "object", "properties": {"symbol": {"description": "需要追踪的股票代码"}},
                         "required": []}},
         {"name": "Calculator", "description": "数学计算器,计算数学问题",
          "parameters": {"type": "object", "properties": {"symbol": {"description": "要计算的数学公式"}},
                         "required": []}}
         ], \"stream\": true, \"max_tokens\": 100, \"temperature\": 0.8, \"top_p\": 0.8}"
  • Openai style custom interface agent-chat Curl 测试(你需要实现自定义的工具描述脚本openai_api_demo/tools/schema.py的内容,并且将api_server.py中AGENT_CONTROLLER指定为'true'):
curl -X POST "http://127.0.0.1:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-d "{\"model\": \"chatglm3-6b\", \"messages\": [{\"role\": \"user\", \"content\": \"37乘以8加7除2等于多少?\"}], \"stream\": true, \"max_tokens\": 100, \"temperature\": 0.8, \"top_p\": 0.8}"

该接口用于openai风格的自定义工具箱的自主调度。具有调度异常的自处理回复能力,无需另外实现调度算法,用户无需api_key。

  • 使用Python进行测试
cd openai_api_demo
python openai_api_request.py

如果测试成功,则模型应该返回一段故事。

低成本部署

模型量化

默认情况下,模型以 FP16 精度加载,运行上述代码需要大概 13GB 显存。如果你的 GPU 显存有限,可以尝试以量化方式加载模型,使用方法如下:

model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True).quantize(4).cuda()

模型量化会带来一定的性能损失,经过测试,ChatGLM3-6B 在 4-bit 量化下仍然能够进行自然流畅的生成。

CPU 部署

如果你没有 GPU 硬件的话,也可以在 CPU 上进行推理,但是推理速度会更慢。使用方法如下(需要大概 32GB 内存)

model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True).float()

Mac 部署

对于搭载了 Apple Silicon 或者 AMD GPU 的 Mac,可以使用 MPS 后端来在 GPU 上运行 ChatGLM3-6B。需要参考 Apple 的 官方说明 安装 PyTorch-Nightly(正确的版本号应该是2.x.x.dev2023xxxx,而不是 2.x.x)。

目前在 MacOS 上只支持从本地加载模型。将代码中的模型加载改为从本地加载,并使用 mps 后端:

model = AutoModel.from_pretrained("your local path", trust_remote_code=True).to('mps')

加载半精度的 ChatGLM3-6B 模型需要大概 13GB 内存。内存较小的机器(比如 16GB 内存的 MacBook Pro),在空余内存不足的情况下会使用硬盘上的虚拟内存,导致推理速度严重变慢。

多卡部署

如果你有多张 GPU,但是每张 GPU 的显存大小都不足以容纳完整的模型,那么可以将模型切分在多张GPU上。首先安装 accelerate: pip install accelerate,然后即可正常加载模型。

OpenVINO Demo

ChatGLM3-6B 已经支持使用 OpenVINO 工具包进行加速推理,在英特尔的GPU和GPU设备上有较大推理速度提升。具体使用方法请参考 OpenVINO Demo

TensorRT-LLM Demo

ChatGLM3-6B已经支持使用 TensorRT-LLM 工具包进行加速推理,模型推理速度得到多倍的提升。具体使用方法请参考 TensorRT-LLM Demo 和 官方技术文档。

引用

如果你觉得我们的工作有帮助的话,请考虑引用下列论文。

@article{zeng2022glm,
  title={Glm-130b: An open bilingual pre-trained model},
  author={Zeng, Aohan and Liu, Xiao and Du, Zhengxiao and Wang, Zihan and Lai, Hanyu and Ding, Ming and Yang, Zhuoyi and Xu, Yifan and Zheng, Wendi and Xia, Xiao and others},
  journal={arXiv preprint arXiv:2210.02414},
  year={2022}
}
@inproceedings{du2022glm,
  title={GLM: General Language Model Pretraining with Autoregressive Blank Infilling},
  author={Du, Zhengxiao and Qian, Yujie and Liu, Xiao and Ding, Ming and Qiu, Jiezhong and Yang, Zhilin and Tang, Jie},
  booktitle={Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
  pages={320--335},
  year={2022}
}

chatglm3's People

Contributors

abmfy avatar ai-liuys avatar btlmd avatar chatgpt-1 avatar dodobaba avatar duzx16 avatar eltociear avatar harmonyhu avatar hellopahe avatar jershi425 avatar jiawei243 avatar lilongxian avatar liu-steve avatar longerking avatar longin-yu avatar longmans avatar lr-tsinghua11 avatar minmie avatar openvino-dev-contest avatar prnake avatar samge0 avatar st01cs avatar timvan1596 avatar xusenlinzy avatar xxw1995 avatar yhr123 avatar yurunsoft avatar yyq avatar zhangch9 avatar zrzrzrzrzrzrzr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatglm3's Issues

model paths in web demos are pointing to local path

In both web_demo.py and web_demo2.py the paths to ChatGLM3 model are pointing to a local path "/mnt/vepfs/workspace/zxdu/chatglm3-6b"

eg.

tokenizer = AutoTokenizer.from_pretrained("/mnt/vepfs/workspace/zxdu/chatglm3-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("/mnt/vepfs/workspace/zxdu/chatglm3-6b", trust_remote_code=True).cuda()

They probably should be corrected to hugging face hub format, like "THUDM/chatglm3-6b"

openai api

之前的openai api脚本应该不能用了吧,有没有大佬写一个新的

Benchmark result reproducibility 关于 Benchmark 结果的复现的方法

感谢 release 了一个非常强大的模型,想问一下 readme 中的 benchmark result 如何进行复现呢?我尝试使用了和 huggingface leaderboard 或提供在原本论文/repo中类似的测试方加 greedy decoding 的方法进行测试。经过一些调试,可以复现 Llama2 文章中提到的大部分分数。但是在测试 ChatGLM3 时发现,除了 AGI_Eval 的分数较为接近外,大部分分数都有 10-20 分以上的差距,尤其是 GSM8K 的 exact match 只有 47.8 分,即使是检测 contains,也只有 51 分。是否可以分享下复现 benchmark 结果的方法?谢谢

使用composite_demo报错,请帮忙看下原因

💬 Chat

🛠️ Tool

🧑‍💻 Code Interpreter

Tools

查询巴黎天气

RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'
Traceback:
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
exec(code, module.dict)
File "/root/ChatGLM3-main/composite_demo/main.py", line 52, in
demo_tool.main(top_p, temperature, prompt_text)
File "/root/ChatGLM3-main/composite_demo/demo_tool.py", line 111, in main
for response in client.generate_stream(
File "/root/ChatGLM3-main/composite_demo/client.py", line 119, in generate_stream
for new_text, _ in stream_chat(self.model,
File "/root/ChatGLM3-main/composite_demo/client.py", line 69, in stream_chat
for outputs in self.stream_generate(**inputs, past_key_values=past_key_values,
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 35, in generator_context
response = gen.send(None)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_chatglm.py", line 1156, in stream_generate
outputs = self(
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_chatglm.py", line 937, in forward
transformer_outputs = self.transformer(
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_chatglm.py", line 830, in forward
hidden_states, presents, all_hidden_states, all_self_attentions = self.encoder(
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_chatglm.py", line 640, in forward
layer_ret = layer(
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_chatglm.py", line 544, in forward
attention_output, kv_cache = self.self_attention(
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/modeling_chatglm.py", line 376, in forward
mixed_x_layer = self.query_key_value(hidden_states)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/nn/modules/linear.py", line 114, in forward
return F.linear(input, self.weight, self.bias)

Function calling

I see that function calling is the format used by the Openai API, which may not be very user-friendly for some POST requests. Is there any solution to this?

长文本应用场景下prompt

您好,注意到此版模型prompt格式调整挺大。请问长本文下(如文档问答)prompt构建与普通问答一样吗,有没什么样例呢

缺少 jupyter_client 模块

安装依赖 pip install -r requirements.txt

然后 streamlit run main.py

然后报错下面信息:

2023-10-29 00:31:32.581 Uncaught app exception
Traceback (most recent call last):
  File "/home/xxx/.local/share/virtualenvs/ChatGLM3-uTamXjui/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "/home/xxx/code/github/ChatGLM3/composite_demo/main.py", line 11, in <module>
    import demo_chat, demo_ci, demo_tool
  File "/home/xxx/code/github/ChatGLM3/composite_demo/demo_ci.py", line 9, in <module>
    import jupyter_client
ModuleNotFoundError: No module named 'jupyter_client'

安装 pip install jupyter_client
之后正常

请问 RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'怎么解决

=== History:
[Conversation(role=<Role.USER: 2>, content='1', tool=None, image=None)]
2023-10-28 23:14:33.424 Uncaught app exception
Traceback (most recent call last):
File "E:\ChatGLM3\venv\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in _run_script
exec(code, module.dict)
File "E:\ChatGLM3\composite_demo\main.py", line 50, in
demo_chat.main(top_p, temperature, system_prompt, prompt_text)
File "E:\ChatGLM3\composite_demo\demo_chat.py", line 50, in main
for response in client.generate_stream(
File "E:\ChatGLM3\composite_demo\client.py", line 119, in generate_stream
for new_text, _ in stream_chat(self.model,
File "E:\ChatGLM3\composite_demo\client.py", line 69, in stream_chat
for outputs in self.stream_generate(**inputs, past_key_values=past_key_values,
File "E:\ChatGLM3\venv\lib\site-packages\torch\utils_contextlib.py", line 35, in generator_context
response = gen.send(None)
File "C:\Users\zhuya/.cache\huggingface\modules\transformers_modules\THUDM\chatglm3-6b\fc3235f807ef5527af598c05f04f2ffd17f48bab\modeling_chatglm.py", line 1156, in stream_generate
outputs = self(
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\zhuya/.cache\huggingface\modules\transformers_modules\THUDM\chatglm3-6b\fc3235f807ef5527af598c05f04f2ffd17f48bab\modeling_chatglm.py", line 937, in forward
transformer_outputs = self.transformer(
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\zhuya/.cache\huggingface\modules\transformers_modules\THUDM\chatglm3-6b\fc3235f807ef5527af598c05f04f2ffd17f48bab\modeling_chatglm.py", line 830, in forward
hidden_states, presents, all_hidden_states, all_self_attentions = self.encoder(
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\zhuya/.cache\huggingface\modules\transformers_modules\THUDM\chatglm3-6b\fc3235f807ef5527af598c05f04f2ffd17f48bab\modeling_chatglm.py", line 640, in forward
layer_ret = layer(
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\zhuya/.cache\huggingface\modules\transformers_modules\THUDM\chatglm3-6b\fc3235f807ef5527af598c05f04f2ffd17f48bab\modeling_chatglm.py", line 544, in forward
attention_output, kv_cache = self.self_attention(
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\zhuya/.cache\huggingface\modules\transformers_modules\THUDM\chatglm3-6b\fc3235f807ef5527af598c05f04f2ffd17f48bab\modeling_chatglm.py", line 376, in forward
mixed_x_layer = self.query_key_value(hidden_states)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in call_impl
return forward_call(*args, **kwargs)
File "E:\ChatGLM3\venv\lib\site-packages\torch\nn\modules\linear.py", line 114, in forward
return F.linear(input, self.weight, self.bias)
RuntimeError: "addmm_impl_cpu
" not implemented for 'Half'

是否和我想象的工具调用一样?

首先,3比2在cpu运行的体验上提升了一大截,明显感觉快了很多,比1和2的体验明显,超赞。

工具调用是 向AI 提供一套 api调用接口 或 应用程序的启动参数说明,然后让AI根据我的需要去调用api和程序。
是这样的吗?

但我不会......,然后我问了chatglm3-6b,它好像也不知道,还是我提问的没有问道关键词?

微信图片_20231027171422

输出图像的Prompt格式

我有观察到Prompt文档显示如何生成图像,如下所示。请问【image】是随意写个占位符就行了是吗?

...
plt.axis('equal')
plt.axis('off')
plt.show()

<|observation|>
```result
【image】

<|assistant|>
这是一个爱心形状。我使用了参数方程来描述这个形状,并使用matplotlib进行了绘制。如果您有任何其他需求或问题,请随时告诉我。
<|user|> # End

RuntimeError: CUDA error: device-side assert triggered

模型部署后调用了几百次没问题 但再调用就报了这个错误
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call
return await self.app(scope, receive, send)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/fastapi/applications.py", line 276, in call
await super().call(scope, receive, send)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/applications.py", line 122, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/middleware/errors.py", line 184, in call
raise exc
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/middleware/errors.py", line 162, in call
await self.app(scope, receive, _send)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 79, in call
raise exc
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 68, in call
await self.app(scope, receive, sender)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call
raise e
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/routing.py", line 718, in call
await route.handle(scope, receive, send)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/routing.py", line 276, in handle
await self.app(scope, receive, send)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/starlette/routing.py", line 66, in app
response = await func(request)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/fastapi/routing.py", line 237, in app
raw_response = await run_endpoint_function(
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
return await dependant.call(**values)
File "get_api_cuda1.py", line 66, in create_item
response, history = model.chat(tokenizer,
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/chatglm3-6b/modeling_chatglm.py", line 1032, in chat
inputs = inputs.to(self.device)
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 758, in to
self.data = {k: v.to(device=device) for k, v in self.data.items()}
File "/usr/local/anaconda3/envs/chatglm/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 758, in
self.data = {k: v.to(device=device) for k, v in self.data.items()}
RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.

运行webdemo2的时候出现ModuleNotFoundError: No module named 'transformers_modules.'

File "G:\ai\ChatGLM\ChatGLM3\web_demo2.py", line 23, in
tokenizer, model = get_model()
File "G:\ai\ChatGLM\ChatGLM3\venv\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 212, in wrapper
return cached_func(*args, **kwargs)
File "G:\ai\ChatGLM\ChatGLM3\venv\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 241, in call
return self._get_or_create_cached_value(args, kwargs)
File "G:\ai\ChatGLM\ChatGLM3\venv\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 267, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
File "G:\ai\ChatGLM\ChatGLM3\venv\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 321, in _handle_cache_miss
computed_value = self.info.func(*func_args, **func_kwargs)
File "G:\ai\ChatGLM\ChatGLM3\web_demo2.py", line 14, in get_model
tokenizer = AutoTokenizer.from_pretrained("./models/chatglm3-6b", trust_remote_code=True)
File "G:\ai\ChatGLM\ChatGLM3\venv\lib\site-packages\transformers\models\auto\tokenization_auto.py", line 676, in from_pretrained
tokenizer_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, **kwargs)
File "G:\ai\ChatGLM\ChatGLM3\venv\lib\site-packages\transformers\dynamic_module_utils.py", line 443, in get_class_from_dynamic_module
return get_class_in_module(class_name, final_module.replace(".py", ""))
File "G:\ai\ChatGLM\ChatGLM3\venv\lib\site-packages\transformers\dynamic_module_utils.py", line 164, in get_class_in_module
module = importlib.import_module(module_path)
File "D:\Program Files\python\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 992, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 992, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'transformers_modules.'
但实际transformers已经安装也是4.30.2

端侧

如何部署到手机端呢?

tokenizer 相关问题

非常感谢开源,很棒的工作
ChatGLM3 的 tokenizer 对特殊字符(如<|user|>)不允许注入,微调时应如何构造对齐模版的数据呢?具体而言,encode 时无法将 <|user|> 等 special tokens 编码到对应 id,而只是当成普通文本处理。这种情况在垂类微调时,数据应该怎么构造、处理,才能保证模板一致?
FYI:QWen 在发布初期也进行了防注入,后续社区反馈影响很大,做出了一定的调整 QWen的处理方式

同时,tokenizer 的类命名(ChatGLMTokenizer)与 ChatGLM2 的 tokenizer 类命名一致,但在细节上完全不同,这可能会使得一些下游仓库在适配时遇到问题,请问是否考虑给 ChatGLM3 的 tokenizer 起一个新的类名字?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.