干净环境运行 trans_cli_demo.py 产生报错 TypeError: _pad() got an unexpected keyword argument 'padding_side'
System Info / 系統信息
python=3.9 CUDA Version: 12.4 GPU:4090 24G
新建的干净环境使用 pip install -r requirements.txt 安装的环境。安装版本与 requirements 相同
Who can help? / 谁可以帮助到您?
@wwewwt @cenyk1230
Information / 问题信息
- [X] The official example scripts / 官方的示例脚本
- [ ] My own modified scripts / 我自己修改的脚本和任务
Reproduction / 复现过程
$ python /home/ljh/git/GLM-4/basic_demo/trans_cli_demo.py Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00, 8.43it/s] Some parameters are on the meta device because they were offloaded to the cpu. Welcome to the GLM-4-9B CLI chat. Type your messages below.
You: 你好
Traceback (most recent call last):
File "/home/ljh/git/GLM-4/basic_demo/trans_cli_demo.py", line 82, in
尝试降低版本为 transformers==4.44.2
可以正常回答,但是有警告信息(The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's attention_mask to obtain reliable results.),且响应十分缓慢。
Welcome to the GLM-4-9B CLI chat. Type your messages below.
You: 你好
GLM-4:The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's attention_mask to obtain reliable results.
您好👋!我是人工智能助手,很高兴为您服务。有什么可以帮助您的吗?
Expected behavior / 期待表现
麻烦更新修改后的代码~~~
该问题已经在最新的模型文件中修复,请在huggingface下载最新的模型文件或参考修改https://huggingface.co/THUDM/LongWriter-glm4-9b/commit/778b5712634889f5123d6c463ca383bc6dd5c621
我用trans_cli_demo.py跑glm-4-9b-chat-1m的模型也报错了(只是报错行比你这要我先几行。我的是tokenization_utils_base.py的3500行)。应该和这问题一样,因为没法翻墙不知道这链接写的是什么内容,有没具体的改法
在模型文件中,tokenization_chatglm.py文件,ChatGLM4Tokenizer类的_pad函数的传入参数中加一条padding_side: Optional[str] = None,
def _pad(
self,
encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
max_length: Optional[int] = None,
padding_side: str = "left",
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
pad_to_multiple_of: Optional[int] = None,
return_attention_mask: Optional[bool] = None,
) -> dict:
该问题已经在最新的模型文件中修复,请在huggingface下载最新的模型文件或参考修改https://huggingface.co/THUDM/LongWriter-glm4-9b/commit/778b5712634889f5123d6c463ca383bc6dd5c621
你好,huggingface中THUDM/glm-4-9b/tokenization_chatglm.py文件中的_pad()函数目前还是无法接收padding_side参数。请您帮忙检查一下是否正确解决这个问题? @sixsixcoder
Please refer to this issue:https://github.com/THUDM/GLM-4/issues/578