【问题标题】:Solve Speed Difference in ktrain Predictor vs. Learner prediction?解决 ktrain 预测器与学习器预测的速度差异?
【发布时间】:2021-05-26 14:45:35
【问题描述】:

我正在使用 ktrain huggingface 库来构建语言模型。我注意到,在将其用于生产时,“学习者预测”与“预测者预测”的速度存在巨大差异。 如何以及有什么方法可以加快预测器的预测速度?

%timeit test = learner.predict(val) # takes 10s
%timeit test = predictor.predict(x_val,return_proba = True) # takes 25s

【问题讨论】:

    标签: python language-model ktrain


    【解决方案1】:

    第二个调用对数据进行预处理(例如,标记化),而第一个调用对已经预处理的数据进行预测。因此,时间差异可能是由于预处理原始数据所花费的时间:

    %%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 predictionspredictions with ONNX

    【讨论】:

      猜你喜欢
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      • 2011-10-04
      • 2018-09-16
      相关资源
      最近更新 更多