[BUG/Help] <title>在 colab 运行时,实例代码出现错误
作者: woshicqy创建于 2025年4月3日更新于 2025年10月3日
- In the colab, using the default setup with T4-GPU
- Follow the configuration file
!pip install protobuf
!pip install transformers==4.30.2
!pip install cpm_kernels
!pip install torch>=2.0
!pip install gradio
!pip install mdtex2html
!pip install sentencepiece
!pip install accelerate
!pip install sse-starlette
!pip install streamlit>=1.24.0- Run the following code to download the corresponding model
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b-int4", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm2-6b-int4", trust_remote_code=True).half().cuda()
model = model.eval()- Run the following code to try using the model, and get an error:
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
print(response)Environment
内容来源: zai-org/ChatGLM2-6B