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

手动转换权重有问题 #23

Closed
TestNLP opened this issue Dec 30, 2021 · 13 comments
Closed

手动转换权重有问题 #23

TestNLP opened this issue Dec 30, 2021 · 13 comments

Comments

@TestNLP
Copy link

TestNLP commented Dec 30, 2021

python convert_roformer_original_tf_checkpoint_to_pytorch.py
--tf_checkpoint_path=xxxxxx/chinese_roformer_L-12_H-768_A-12/bert_model.ckpt
--roformer_config_file=pretrained_models/chinese_roformer_base/config.json
--pytorch_dump_path=pretrained_models/chinese_roformer_base/pytorch_model.bin

这个直接运行好像不行,按照错误提示修改以后,只生成了一个pb文件,没有对应的config文件,这个是为啥呢?

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

计算出来的结果和原本tensorflow的不一样

@JunnYu
Copy link
Owner

JunnYu commented Dec 30, 2021

贴个图?还有错误提示?pytorch的config文件需要自己进行修改,参考huggingface.co已有的例子进行修改

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

没有错误提示

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

转的过程都是ok的,没有任何报错,就是pytorch版本和tensorflow版本算出来的结果不一样

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

image

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

这个是转完以后,打印出来的config,我之前没看到,我刚才把这个拷贝到config文件中,是可以跑起来了,只是算的结果怎么不一样呢

@JunnYu
Copy link
Owner

JunnYu commented Dec 30, 2021

结果应该一样,我刚刚尝试了转换权重的代码。你的是char版本的模型还是word版本的模型,本仓库的tokenizer是word版本的。
image

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

我的是char,这个怎么改成char版本?

@JunnYu
Copy link
Owner

JunnYu commented Dec 30, 2021

权重转换是一样的,char版本的tokenizer直接调用BertTokenizer就可以了

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

是直接改convert_roformer_original_tf_checkpoint_to_pytorch.py里边的代码吗

@TestNLP
Copy link
Author

TestNLP commented Dec 30, 2021

具体在哪修改,能否贴一个图出来呢,感谢

@JunnYu
Copy link
Owner

JunnYu commented Dec 30, 2021

char和word转换权重的代码是一样的!主要区别是你使用的时候使用的tokenizer的区别。

char版本的模型调用

from roformer import RoFormerModel
from transformers import BertTokenizer
model = RoFormerModel.from_pretrained("模型权重文件夹")
tokenizer = BertTokenizer.from_pretrained("模型权重文件夹")

word版本的模型调用

from roformer import RoFormerModel, RoFormerTokenizer
model = RoFormerModel.from_pretrained("模型权重文件夹")
tokenizer = RoFormerTokenizer.from_pretrained("模型权重文件夹")

@TestNLP
Copy link
Author

TestNLP commented Dec 31, 2021

好的,感谢解答,您的工作非常棒,能否加一个微信,18392408198

@JunnYu JunnYu closed this as completed Dec 31, 2021
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

No branches or pull requests

2 participants