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

请问这个pytorch模型可以作为模型路径参数传给huggingface么? #25

Open
probe2 opened this issue Aug 12, 2021 · 2 comments

Comments

@probe2
Copy link

probe2 commented Aug 12, 2021

因为我看你们的生成实现是用pipeline..我可以使用huggingface 的比如这份代码..把模型路径改成你们的模型 然后去生成么

from transformers import GPT2Tokenizer, GPT2LMHeadModel

tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = GPT2LMHeadModel.from_pretrained('gpt2')

inputs = tokenizer("Hello, my dog is cute and ", return_tensors="pt")
generation_output = model.generate(**inputs, return_dict_in_generate=True, output_scores=True)

@probe2
Copy link
Author

probe2 commented Aug 12, 2021

我版本更新后 比如transformer更新到4.9. 跟你们一样的generate..就生成乱码了 这正常么..另外可以对你们的generate 输入比如num_beam,top p等参数么..我看pipline官网写说可以输入模型的generate方法别的超参..

@ghosthamlet
Copy link
Owner

ghosthamlet commented Aug 13, 2021

这个pytorch模型是修改GPT2后训练的,不能直接调用huggingface的GPT2LMHeadModel,需要用本代码库提供的GPT2LMHeadModel。另外tokenizer也不是GPT2Tokenizer,需要用BertTokenizer,具体参见:https://github.com/ghosthamlet/gpt2-ml-torch/blob/master/gpt2_ml_torch/generate.py
不过本库的GPT2LMHeadModel和huggingface的接口基本完全一样,所以generate时可以输入一样的参数。

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