我正在使用ktrain huggingface库来构建一个语言模型。在将其用于生产时,我注意到,“学习者预测”与“预测器预测”在速度上存在巨大差异。为什么?有没有什么方法可以加快预测速度?
%timeit test = learner.predict(val) # takes 10s
%timeit test = predictor.predict(x_val,return_proba = True) # takes 25s发布于 2021-03-10 06:13:51
第二个调用对数据进行预处理(例如,标记化),而第一个调用对已经预处理的数据进行预测。因此,时间差可能是由于预处理原始数据所用的时间:
%%time
tst = predictor.preproc.preprocess_test(x_test)
# Wall time: 5.65 s
%%time
preds = learner.predict(val)
# Wall time: 10.5 s
%%time
preds = predictor.predict(x_test)
# Wall time: 16.1 s在向predict提供文本列表时,您还可以使用更大的batch_size,这也有助于提高速度(默认值为32):
predictor.batch_size = 128
preds = predictor.predict(x_test)最后,如果您希望在部署场景中做出更快的预测,您可以查看ktrain常见问题解答,其中显示了how to make quantized predictions和predictions with ONNX。
https://stackoverflow.com/questions/66348221
复制相似问题