GLM-4 icon indicating copy to clipboard operation
GLM-4 copied to clipboard

干净环境运行 trans_cli_demo.py 产生报错 TypeError: _pad() got an unexpected keyword argument 'padding_side'

Open jiahuiLeee opened this issue 1 year ago • 1 comments

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 model_inputs = tokenizer.apply_chat_template( File "/home/ljh/.conda/envs/GLM4/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1891, in apply_chat_template out = self( File "/home/ljh/.conda/envs/GLM4/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 3024, in call encodings = self._call_one(text=text, text_pair=text_pair, **all_kwargs) File "/home/ljh/.conda/envs/GLM4/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 3134, in _call_one return self.encode_plus( File "/home/ljh/.conda/envs/GLM4/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 3210, in encode_plus return self._encode_plus( File "/home/ljh/.conda/envs/GLM4/lib/python3.9/site-packages/transformers/tokenization_utils.py", line 801, in _encode_plus return self.prepare_for_model( File "/home/ljh/.conda/envs/GLM4/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 3706, in prepare_for_model encoded_inputs = self.pad( File "/home/ljh/.conda/envs/GLM4/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 3508, in pad encoded_inputs = self._pad( TypeError: _pad() got an unexpected keyword argument 'padding_side'


尝试降低版本为 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 / 期待表现

麻烦更新修改后的代码~~~

jiahuiLeee avatar Oct 06 '24 08:10 jiahuiLeee

该问题已经在最新的模型文件中修复,请在huggingface下载最新的模型文件或参考修改https://huggingface.co/THUDM/LongWriter-glm4-9b/commit/778b5712634889f5123d6c463ca383bc6dd5c621

sixsixcoder avatar Oct 11 '24 05:10 sixsixcoder

我用trans_cli_demo.py跑glm-4-9b-chat-1m的模型也报错了(只是报错行比你这要我先几行。我的是tokenization_utils_base.py的3500行)。应该和这问题一样,因为没法翻墙不知道这链接写的是什么内容,有没具体的改法

lizhao-8202 avatar Oct 16 '24 07:10 lizhao-8202

在模型文件中,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:

sixsixcoder avatar Oct 16 '24 08:10 sixsixcoder

该问题已经在最新的模型文件中修复,请在huggingface下载最新的模型文件或参考修改https://huggingface.co/THUDM/LongWriter-glm4-9b/commit/778b5712634889f5123d6c463ca383bc6dd5c621

你好,huggingface中THUDM/glm-4-9b/tokenization_chatglm.py文件中的_pad()函数目前还是无法接收padding_side参数。请您帮忙检查一下是否正确解决这个问题? @sixsixcoder

hbbOooO avatar Nov 17 '24 09:11 hbbOooO

Please refer to this issue:https://github.com/THUDM/GLM-4/issues/578

sixsixcoder avatar Nov 18 '24 02:11 sixsixcoder