yongzhuo / Pytorch-NLU

Pytorch-NLU,一个中文文本分类、序列标注工具包,支持中文长文本、短文本的多类、多标签分类任务,支持中文命名实体识别、词性标注、分词、抽取式文本摘要等序列标注任务。 Ptorch NLU, a Chinese text classification and sequence annotation toolkit, supports multi class and multi label classification tasks of Chinese long text and short text, and supports sequence annotation tasks such as Chinese named entity recognition, part of spee
https://blog.csdn.net/rensihui
Apache License 2.0
328 stars 52 forks source link

求回复:推理速度的问题 #13

Closed yuki7777777888 closed 1 week ago

yuki7777777888 commented 1 week ago

大佬求解,使用tc发送多条text来推理,可不可以调整batch_size用更多显存加速推理的速度,或者还有什么方法能增加推理速度

yongzhuo commented 1 week ago

可以改batch_size,只需要改tc.config里边的batch_size就好。 一般推理加速可以用 TensorRT吧,转为ONNX后就可以了。Pytorch → ONNX → TensorRT。 代码tc.Office.py中有个save_onnx(self, path_onnx_dir="")的函数,用那个就可以。 具体来说就是tcPredict.py加载模型后,使用类似下面的代码就可以了。

tcp = TextClassificationPredict(path_config)
tcp.office.save_onnx(path_onnx_dir="xxx")