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

模型推理 #65

Open
lichengyang666 opened this issue May 19, 2023 · 3 comments
Open

模型推理 #65

lichengyang666 opened this issue May 19, 2023 · 3 comments

Comments

@lichengyang666
Copy link

大佬 能不能分享一下推理文件呢 我加载完ckpt文件后推理的时候总是报错AttributeError: 'LightModel' object has no attribute 'generate',是我的加载方法有问题么,我直接使用LightModel.load_from_checkpoint加载的

@renmada
Copy link
Owner

renmada commented May 25, 2023

参考这个代码

def predict_batch(self, batch):
model_kwargs = dict(eos_token_id=self.tokenizer.eos_token_id,
decoder_start_token_id=self.tokenizer.bos_token_id,
num_beams=self.args.beams,
input_ids=batch['input_ids'],
attention_mask=batch['attention_mask'],
use_cache=True,
max_length=self.args.max_target_length,
)
if hasattr(self.model, 'generator'):
model_kwargs['src'] = batch['input_ids']
pred = self.model.generate(**model_kwargs)
pred = self.ids2text(pred)
return pred

@lichengyang666
Copy link
Author

感谢大佬

@Licq-101
Copy link

感谢大佬
@lichengyang666 大佬,能不能分享一下你的推理代码,我是纯小白

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

3 participants