arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2104.00254cs.LG
收藏

在深度学习中使用Python进行模型推理

Using Python for Model Inference in Deep Learning

Facebook AI Research(Facebook AI研究院)

Zachary DeVito, Jason Ansel, Will Constable, Michael Suo, Ailing Zhang, Kim Hazelwood

摘要:

Python已经成为训练深度神经网络的事实上的语言,它将大量的科学计算库与用于张量计算的高效库(如PyTorch或TensorFlow)相结合。然而,当模型用于推理时,它们通常从Python中提取为TensorFlow图或TorchScript程序,以满足性能和打包约束。提取过程可能很耗时,阻碍了快速原型制作。我们将展示如何在Python中执行推理时满足这些性能和打包约束。特别是,我们提出了一种在单个过程中使用多个Python解释器来实现可扩展推理的方法,并为包含原生Python代码和数据的模型描述了一种新的容器格式。这种方法通过消除模型提取步骤简化了模型部署过程,并且更容易集成现有的性能增强Python库。我们在Github上的一套流行的PyTorch模型上评估了我们的设计,展示了如何将它们打包到我们的推理格式中,并将它们的性能与TorchScript进行了比较。对于更大的模型,我们打包的Python模型与TorchScript执行相同,对于有一些Python开销的较小模型,我们的多解释器方法确保推理仍然是可扩展的。

英文摘要:

Python has become the de-facto language for training deep neural networks, coupling a large suite of scientific computing libraries with efficient libraries for tensor computation such as PyTorch or TensorFlow. However, when models are used for inference they are typically extracted from Python as TensorFlow graphs or TorchScript programs in order to meet performance and packaging constraints. The extraction process can be time consuming, impeding fast prototyping. We show how it is possible to meet these performance and packaging constraints while performing inference in Python. In particular, we present a way of using multiple Python interpreters within a single process to achieve scalable inference and describe a new container format for models that contains both native Python code and data. This approach simplifies the model deployment story by eliminating the model extraction step, and makes it easier to integrate existing performance-enhancing Python libraries. We evaluate our design on a suite of popular PyTorch models on Github, showing how they can be packaged in our inference format, and comparing their performance to TorchScript. For larger models, our packaged Python models perform the same as TorchScript, and for smaller models where there is some Python overhead, our multi-interpreter approach ensures inference is still scalable.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑