Skip to content

进行P-Tuning V2微调后推理时出现的问题:ValueError: not enough values to unpack (expected 2, got 1) #227

Closed

Description

@LittleGreenYuan
Traceback (most recent call last):
  File "end_finally_test.py", line 80, in <module>
    response, history = model.chat(tokenizer,MutilTalk_Prompt,history=[])
  File "/root/miniconda3/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-32k/modeling_chatglm.py", line 1042, in chat
    response, history = self.process_response(response, history)
  File "/root/.cache/huggingface/modules/transformers_modules/chatglm3-6b-32k/modeling_chatglm.py", line 1006, in process_response
    metadata, content = response.split("\n", maxsplit=1)
ValueError: not enough values to unpack (expected 2, got 1)

所使用的是官方的微调脚本,在使用带有<|assistant|>和不带的prompt模板微调,在最新的实验中为每一次的回复添加了<|assistant|>\n,但都会在之后推理中出现该问题。

Activity

  1. mzh1996 commented on Nov 9, 2023

    @mzh1996

    看到有人说 在代码里加一个检查 如果response里没有"\n",就 response = "\n" + response

  2. LittleGreenYuan commented on Nov 9, 2023

    @LittleGreenYuan
    Author

    非常感谢您的建议,我去尝试一些这种方法,同时也对微调的answer进行格式化处理~

  3. SherryGiii commented on Nov 9, 2023

    @SherryGiii

    请问你解决了吗?

  4. LittleGreenYuan commented on Nov 10, 2023

    @LittleGreenYuan
    Author

    请问你解决了吗?

    这种方法是可以的绕过这个错误的,
    将下载模型文件夹中的modeling_chatglm.py文件,大约1006行的位置如下操作

    for response in output.split("<|assistant|>"):
                metadata, content = response.split("\n", maxsplit=1)
    

    修改成

    for response in output.split("<|assistant|>"):
                if('\n' not in response):
                    response = '\n'+response
                metadata, content = response.split("\n", maxsplit=1)
    

    相当于对产生的结果进行安全判断一次,但是这种情况出现的原因仍然没办法在微调后解决,即便已经输出的文本前添加了'\n'。

  5. locked and limited conversation to collaborators on Nov 14, 2023
  6. converted this issue into a discussion #291 on Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions