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

[Question] bert直接接bi-lstm+crf之后预测很慢,一条预测要耗时260ms,请问能优化速度吗 #78

Closed
wayneowen7 opened this issue Apr 25, 2019 · 13 comments
Assignees
Labels
question Further information is requested

Comments

@wayneowen7
Copy link

titan xp的GPU,应该能排除机器问题,,,想问问有没有解决办法

@wayneowen7 wayneowen7 added the question Further information is requested label Apr 25, 2019
@BrikerMan
Copy link
Owner

BERT 速度就这么慢,暂时没有办法优化。参考:http://eliyar.biz/nlp_chinese_bert_ner/

@wayneowen7
Copy link
Author

谢谢owener,我之前看过这个博客,但是因为我以为这个是CPU跑起来的预测模型,MacBook Pro 13, 2 GHz Intel Core i5, 8G RAM,所以我感觉是不是GPU有提升空间,并且我在别的博客里面看到有10ms的预测速度,但是我个人不是很相信(受限于个人自身知识面),但不知道您有没有了解过这个10ms,参考https://github.com/macanv/BERT-BiLSTM-CRF-NER/issues/40

@BrikerMan
Copy link
Owner

GPU 上可能会比较快,我这两天找时间测试一下。还有我们也在规划从 keras 转到 tf.keras #77 ,到时候保存模型,再用 serving 方式去预测,应该还能有所提升。

@wayneowen7
Copy link
Author

太好了,谢谢您的回复:smiley:持续关注

@Rainman242
Copy link

我也是predict特别慢啊,更加夸张的是1个sample需要1.3秒。(我的sequence length = 512)
其实我fit一个batch=32也只要4秒左右。
请问作者大大,有没有batch predict之类的方法可以调用?

@BrikerMan
Copy link
Owner

@Rainman242 predit 方法可以传数组,就会 batch predict。慢目前没有很好地解决办法。

@alexwwang
Copy link
Collaborator

alexwwang commented May 5, 2019 via email

@BrikerMan
Copy link
Owner

可以在 tf.keras 版本尝试看看,但是 crf 本身也会比较慢,如果对性能要求比较高,可以尝试不用 crf 层。

@SunYanCN
Copy link
Contributor

SunYanCN commented Jun 29, 2019

@BrikerMan
Copy link
Owner

@wayneowen7 @Rainman242 试试 tf.keras 分支的 tf-serving 部署

BiLSTM_CRF_Model, 100 sequence_length 测试结果如下:

1080Ti-GPU 50ms
CPU 200ms

@qiuwei
Copy link

qiuwei commented Dec 4, 2019

谢谢owener,我之前看过这个博客,但是因为我以为这个是CPU跑起来的预测模型,MacBook Pro 13, 2 GHz Intel Core i5, 8G RAM,所以我感觉是不是GPU有提升空间,并且我在别的博客里面看到有10ms的预测速度,但是我个人不是很相信(受限于个人自身知识面),但不知道您有没有了解过这个10ms,参考https://github.com/macanv/BERT-BiLSTM-CRF-NER/issues/40

我们能在cpu上优化到30ms,不过做了大量工作。

@BrikerMan
Copy link
Owner

@qiuwei 可以分享一下优化经验么?

@JianWenJun
Copy link

@qiuwei 望大佬分享一下经验~

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

No branches or pull requests

7 participants