Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for p-tuningv2 #104

Merged
merged 9 commits into from
Apr 15, 2023
Merged

Conversation

thaumstrial
Copy link
Contributor

添加对使用了p-tuning-v2微调的chatglm模型支持

@thaumstrial
Copy link
Contributor Author

#99

@imClumsyPanda imClumsyPanda merged commit e679136 into chatchat-space:dev Apr 15, 2023
@isaacsisi
Copy link

哈罗,我想请教一下,把微调结果中的config和pytorch_model放到了ptuning-v2里面后,需要改什么地方吗?背景:ptuning是别人做好然后把config和pytorch_model发我的。

@isaacsisi
Copy link

isaacsisi commented Apr 24, 2023

现在运行的时候控制台有显示:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b-int4 and are newly initialized: ['transformer.prefix_encoder.embedding.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

@LOGIC-10
Copy link
Contributor

我跟上面遇到了相同的控制台提示,并且给予ptuning微调的模型没有加载成功。我是直接在
llm_model_dict = {
"chatglm-6b-int4-qe": "THUDM/chatglm-6b-int4-qe",
"chatglm-6b-int4": "THUDM/chatglm-6b-int4",
"chatglm-6b": "/data/workspace/Summary_Test/ChatGLM-6B/ptuning/output/adgen-chatglm-6b-pt-2048-2e-2/checkpoint-3000",
"chatyuan": "ClueAI/ChatYuan-large-v2",
}
将chatglm-6b对应的地址改成微调模型checkpoint的地址。

请问这个报错是什么原因,微调模型在单独做推理的时候能正常运行。是否跟quantization设置为8(跟原本chatGLM)不匹配有关?
谢谢~

@thaumstrial
Copy link
Contributor Author

现在运行的时候控制台有显示:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b-int4 and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

这个是正常的,ChatGLM会先初始化一个PrefixEncoder头,然后再把ptuning得到的模型装进PrefixEncoder,这个警告就是在ChatGLM初始化PrefixEncoder部分产生的,可以忽略

@thaumstrial
Copy link
Contributor Author

我跟上面遇到了相同的控制台提示,并且给予ptuning微调的模型没有加载成功。我是直接在 llm_model_dict = { "chatglm-6b-int4-qe": "THUDM/chatglm-6b-int4-qe", "chatglm-6b-int4": "THUDM/chatglm-6b-int4", "chatglm-6b": "/data/workspace/Summary_Test/ChatGLM-6B/ptuning/output/adgen-chatglm-6b-pt-2048-2e-2/checkpoint-3000", "chatyuan": "ClueAI/ChatYuan-large-v2", } 将chatglm-6b对应的地址改成微调模型checkpoint的地址。

请问这个报错是什么原因,微调模型在单独做推理的时候能正常运行。是否跟quantization设置为8(跟原本chatGLM)不匹配有关? 谢谢~

跟quantization应该没有关系,我在测试的时候用了4bit没问题。

"chatglm-6b": "/data/workspace/Summary_Test/ChatGLM-6B/ptuning/output/adgen-chatglm-6b-pt-2048-2e-2/checkpoint-3000"
不是这样用的,"chatglm-6b"仍然是正常的chatglm-6b模型位置,在根目录下会有一个ptuning-v2文件夹,把使用ptuning微调得到的PrefixEncoder的_config.json_和_pytorch_model.bin_放进这个文件夹,再在网页端这勾选使用ptuning

@LOGIC-10
Copy link
Contributor

我跟上面遇到了相同的控制台提示,并且给予ptuning微调的模型没有加载成功。我是直接在 llm_model_dict = { "chatglm-6b-int4-qe": "THUDM/chatglm-6b-int4-qe", "chatglm-6b-int4": "THUDM/chatglm-6b-int4", "chatglm-6b": "/data/workspace/Summary_Test/ChatGLM-6B/ptuning/output/adgen-chatglm-6b-pt-2048-2e-2/checkpoint-3000", "chatyuan": "ClueAI/ChatYuan-large-v2", } 将chatglm-6b对应的地址改成微调模型checkpoint的地址。
请问这个报错是什么原因,微调模型在单独做推理的时候能正常运行。是否跟quantization设置为8(跟原本chatGLM)不匹配有关? 谢谢~

跟quantization应该没有关系,我在测试的时候用了4bit没问题。

"chatglm-6b": "/data/workspace/Summary_Test/ChatGLM-6B/ptuning/output/adgen-chatglm-6b-pt-2048-2e-2/checkpoint-3000" 不是这样用的,"chatglm-6b"仍然是正常的chatglm-6b模型位置,在根目录下会有一个ptuning-v2文件夹,把使用ptuning微调得到的PrefixEncoder的_config.json_和_pytorch_model.bin_放进这个文件夹,再在网页端这勾选使用ptuning

谢谢,是我漏掉了ptuning中的readme。我现在把config.json和PyTorch_model.bin放入了putning-v2的文件夹,路径也改回了。但是在使用putning-v2加载模型之后,会有打印提示:

'ChatGLMModel' object has no attribute 'prefix_encoder'
加载PrefixEncoder模型参数失败
No sentence-transformers model found with name /data/workspace/Summary_Test/text2vec-large-chinese. Creating a new one with MEAN pooling.
The dtype of attention mask (torch.int64) is not bool

在这个提示之后,模型网页能跑起来,也能进行问答,但是我不知道“加载PrefixEncoder模型参数失败”是否意味着没有使用我微调的模型运行?

@thaumstrial
Copy link
Contributor Author

thaumstrial commented Apr 26, 2023

谢谢,是我漏掉了ptuning中的readme。我现在把config.json和PyTorch_model.bin放入了putning-v2的文件夹,路径也改回了。但是在使用putning-v2加载模型之后,会有打印提示:

'ChatGLMModel' object has no attribute 'prefix_encoder' 加载PrefixEncoder模型参数失败 No sentence-transformers model found with name /data/workspace/Summary_Test/text2vec-large-chinese. Creating a new one with MEAN pooling. The dtype of attention mask (torch.int64) is not bool

在这个提示之后,模型网页能跑起来,也能进行问答,但是我不知道“加载PrefixEncoder模型参数失败”是否意味着没有使用我微调的模型运行?

"加载PrefixEncoder模型参数失败"的确意味着没有成功使用ptuning微调后的模型

根据报错来看是没有初始化PrefixEncoder头,控制台是否输出了“Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b-int4 and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.”

@LOGIC-10
Copy link
Contributor

谢谢,是我漏掉了ptuning中的readme。我现在把config.json和PyTorch_model.bin放入了putning-v2的文件夹,路径也改回了。但是在使用putning-v2加载模型之后,会有打印提示:
'ChatGLMModel' object has no attribute 'prefix_encoder' 加载PrefixEncoder模型参数失败 No sentence-transformers model found with name /data/workspace/Summary_Test/text2vec-large-chinese. Creating a new one with MEAN pooling. The dtype of attention mask (torch.int64) is not bool
在这个提示之后,模型网页能跑起来,也能进行问答,但是我不知道“加载PrefixEncoder模型参数失败”是否意味着没有使用我微调的模型运行?

"加载PrefixEncoder模型参数失败"的确意味着没有成功使用ptuning微调后的模型

根据报错来看是没有初始化PrefixEncoder头,控制台是否输出了“Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b-int4 and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.”

控制台没有输出Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint .....
控制台没有出现error信息,只有print出来的exception,全部输出截图如下:
image

如果截图不方便查看,我复制在下面:
$ python webui.py
Explicitly passing a revision is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a revision is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a revision is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a revision is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:10<00:00, 1.33s/it]
'ChatGLMModel' object has no attribute 'prefix_encoder'
加载PrefixEncoder模型参数失败
No sentence-transformers model found with name /data/workspace/Summary_Test/text2vec-large-chinese. Creating a new one with MEAN pooling.
The dtype of attention mask (torch.int64) is not bool
Running on local URL: http://0.0.0.0:7860/

To create a public link, set share=True in launch().

@thaumstrial
Copy link
Contributor Author

@LOGIC-10 把ptuning-v2下的config.json发出来看一下

@LOGIC-10
Copy link
Contributor

@LOGIC-10 把ptuning-v2下的config.json发出来看一下

config.json文件内容如下:

{
"_name_or_path": "THUDM/chatglm-6b",
"architectures": [
"ChatGLMForConditionalGeneration"
],
"auto_map": {
"AutoConfig": "configuration_chatglm.ChatGLMConfig",
"AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration",
"AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration"
},
"bos_token_id": 130004,
"eos_token_id": 130005,
"gmask_token_id": 130001,
"hidden_size": 4096,
"inner_hidden_size": 16384,
"layernorm_epsilon": 1e-05,
"mask_token_id": 130000,
"max_sequence_length": 2048,
"model_type": "chatglm",
"num_attention_heads": 32,
"num_layers": 28,
"pad_token_id": 3,
"position_encoding_2d": true,
"pre_seq_len": 2048,
"prefix_projection": false,
"quantization_bit": 8,
"torch_dtype": "float16",
"transformers_version": "4.27.1",
"use_cache": true,
"vocab_size": 130528
}

@thaumstrial
Copy link
Contributor Author

@LOGIC-10 是不是使用了多卡部署,我看models/chatglm_llm.py Line 138里,当使用多卡部署时没有传入model_config。

可以尝试将Line 138修改为:

“model = AutoModel.from_pretrained(model_name_or_path, config=model_config, trust_remote_code=True, **kwargs).half()”

但我没测试在多卡环境下这样做能否正确加载。

@LOGIC-10
Copy link
Contributor

是的,我使用了4卡部署。
更改138行后出现了您最开始提到的报错信息:

Loading checkpoint shards: 100%
Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
'str' object has no attribute 'keys'
Running on local URL: http://0.0.0.0:7860

To create a public link, set share=True in launch().

这次虽然没有出现“加载PrefixEncoder模型参数失败”,但是网页上显示模型未加载成功,也确实无法使用。

我看代码中num_gpus会自动检测我的GPU数量。我在load_model里加入了device_map。但是也不起作用。

@thaumstrial
Copy link
Contributor Author

那么目前还不支持多卡使用ptuning后的模型。抱歉我没使用过多卡环境也不清楚怎么改,只能去找实现了多卡部署功能的人问问了。

@LOGIC-10
Copy link
Contributor

那么目前还不支持多卡使用ptuning后的模型。抱歉我没使用过多卡环境也不清楚怎么改,只能去找实现了多卡部署功能的人问问了。

好的~感谢您的帮助

@lovelucymuch
Copy link

那么目前还不支持多卡使用ptuning后的模型。抱歉我没使用过多卡环境也不清楚怎么改,只能去找实现了多卡部署功能的人问问了。

好的~感谢您的帮助

请问您现在多卡部署的ptuning能够加载成功吗

@lovelucymuch
Copy link

谢谢,是我漏掉了ptuning中的readme。我现在把config.json和PyTorch_model.bin放入了putning-v2的文件夹,路径也改回了。但是在使用putning-v2加载模型之后,会有打印提示:
'ChatGLMModel' object has no attribute 'prefix_encoder' 加载PrefixEncoder模型参数失败 No sentence-transformers model found with name /data/workspace/Summary_Test/text2vec-large-chinese. Creating a new one with MEAN pooling. The dtype of attention mask (torch.int64) is not bool
在这个提示之后,模型网页能跑起来,也能进行问答,但是我不知道“加载PrefixEncoder模型参数失败”是否意味着没有使用我微调的模型运行?

"加载PrefixEncoder模型参数失败"的确意味着没有成功使用ptuning微调后的模型

根据报错来看是没有初始化PrefixEncoder头,控制台是否输出了“Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b-int4 and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.”

请问控制台输出:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
ERROR 2023-05-21 19:07:19,084-1d: The device_map provided does not give any device for the following parameters: transformer.prefix_encoder.embedding.weight
如何解决这个问题呢,不甚感激!

@thaumstrial
Copy link
Contributor Author

那么目前还不支持多卡使用ptuning后的模型。抱歉我没使用过多卡环境也不清楚怎么改,只能去找实现了多卡部署功能的人问问了。

好的~感谢您的帮助

请问您现在多卡部署的ptuning能够加载成功吗

我没有多卡的环境所以没法研究这个,只能去找别人了。

@thaumstrial
Copy link
Contributor Author

请问控制台输出:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. ERROR 2023-05-21 19:07:19,084-1d: The device_map provided does not give any device for the following parameters: transformer.prefix_encoder.embedding.weight 如何解决这个问题呢,不甚感激!

仍然是多卡部署的问题,抱歉我不清楚这方面的该如何解决

@lovelucymuch
Copy link

那么目前还不支持多卡使用ptuning后的模型。抱歉我没使用过多卡环境也不清楚怎么改,只能去找实现了多卡部署功能的人问问了。

好的~感谢您的帮助

请问您现在多卡部署的ptuning能够加载成功吗

我没有多卡的环境所以没法研究这个,只能去找别人了。

已解决多卡部署的ptuning的模型加载的问题,谢谢啦

@lovelucymuch
Copy link

请问控制台输出:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. ERROR 2023-05-21 19:07:19,084-1d: The device_map provided does not give any device for the following parameters: transformer.prefix_encoder.embedding.weight 如何解决这个问题呢,不甚感激!

仍然是多卡部署的问题,抱歉我不清楚这方面的该如何解决

已经解决,谢谢!

@liu459977653
Copy link

请问控制台输出:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. ERROR 2023-05-21 19:07:19,084-1d: The device_map provided does not give any device for the following parameters: transformer.prefix_encoder.embedding.weight 如何解决这个问题呢,不甚感激!

仍然是多卡部署的问题,抱歉我不清楚这方面的该如何解决

已经解决,谢谢!

您好,请问下是如何解决的,可以分享下吗? 万分感谢

@darkSuperman
Copy link

@lovelucymuch 您好,你这个问题是咋解决的呢?我也碰到这样的错误输出,感谢!

@darkSuperman
Copy link

@liu459977653 这个问题你解决了吗?

@includepanda
Copy link

我按照官方提供的微调之后,并没有生成PrefixEncoder这个文件夹呀,只有三个checkpoint包和几个训练完成的txt和json,求助

@thaumstrial
Copy link
Contributor Author

我按照官方提供的微调之后,并没有生成PrefixEncoder这个文件夹呀,只有三个checkpoint包和几个训练完成的txt和json,求助

@includepanda 训练参数中设置的输出文件夹目录不一定是PrefixEncoder,所以不会有这个文件夹。检查训练参数里设置的最总输出的文件夹目录。也有可能是训练完后没有保存模型,所以只有检查点,使用checkpoint里的模型也是可以的

@includepanda
Copy link

我按照官方提供的微调之后,并没有生成PrefixEncoder这个文件夹呀,只有三个checkpoint包和几个训练完成的txt和json,求助

@includepanda 训练参数中设置的输出文件夹目录不一定是PrefixEncoder,所以不会有这个文件夹。检查训练参数里设置的最总输出的文件夹目录。也有可能是训练完后没有保存模型,所以只有检查点,使用checkpoint里的模型也是可以的

您指的是官方包中ptuning文件夹下train.sh中的参数output_dir参数吗,此参数生成的文件夹就是readme中所指的prefixEncoding吗

@thaumstrial
Copy link
Contributor Author

@includepanda output_dir参数指定的文件夹内就是训练完成的模型保存路径,里面应该包含config.json和pytorch_model.bin文件,即PrefixEncoder的模型参数。

@includepanda
Copy link

请问控制台输出:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. ERROR 2023-05-21 19:07:19,084-1d: The device_map provided does not give any device for the following parameters: transformer.prefix_encoder.embedding.weight 如何解决这个问题呢,不甚感激!

仍然是多卡部署的问题,抱歉我不清楚这方面的该如何解决

已经解决,谢谢!

老哥是如何解决的,方便发个教程吗

@includepanda
Copy link

我按照官方提供的微调之后,并没有生成PrefixEncoder这个文件夹呀,只有三个checkpoint包和几个训练完成的txt和json,求助

@includepanda 训练参数中设置的输出文件夹目录不一定是PrefixEncoder,所以不会有这个文件夹。检查训练参数里设置的最总输出的文件夹目录。也有可能是训练完后没有保存模型,所以只有检查点,使用checkpoint里的模型也是可以的
老哥,我重新训练了模型,我想问您上文提到的使用checkpoint里的模型也是可以的,这个checkpoint是如何具体使用的喔

@thaumstrial
Copy link
Contributor Author

@includepanda checkpoint文件夹中也有config.json和pytorch_model.bin文件,即PrefixEncoder的模型参数,其他的是训练时参数,可以不用管。将这两个文件放入根目录下的ptuning-v2

@MyGitHubPigStar
Copy link

请问控制台输出:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. ERROR 2023-05-21 19:07:19,084-1d: The device_map provided does not give any device for the following parameters: transformer.prefix_encoder.embedding.weight 如何解决这个问题呢,不甚感激!

仍然是多卡部署的问题,抱歉我不清楚这方面的该如何解决

已经解决,谢谢!

老哥,请问如何解决的呀,兄弟们都在等你回复~

@MyGitHubPigStar
Copy link

请问控制台输出:Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at THUDM/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. ERROR 2023-05-21 19:07:19,084-1d: The device_map provided does not give any device for the following parameters: transformer.prefix_encoder.embedding.weight 如何解决这个问题呢,不甚感激!

仍然是多卡部署的问题,抱歉我不清楚这方面的该如何解决

已经解决,谢谢!

老哥是如何解决的,方便发个教程吗

好像暂时不支持多卡部署,改成单卡就可以使用了。在modles/loader/loader.py ==>num_gpus = torch.cuda.device_count()改为 num_gpus=1 重新启动就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants