There is a perceived trade-off between machine learning code that is easy to write, and machine learning code that is scalable or fast to execute. In machine learning, imperative style libraries like Autograd and PyTorch are easy to write, but suffer from high interpretive overhead and are not easily deployable in production or mobile settings. Graph-based libraries like TensorFlow and Theano benefit from whole-program optimization and can be deployed broadly, but make expressing complex models more cumbersome. We describe how the use of staged programming in Python, via source code transformation, offers a midpoint between these two library design patterns, capturing the benefits of both. A key insight is to delay all type-dependent decisions until runtime, via dynamic dispatch. We instantiate these principles in AutoGraph, a software system that improves the programming experience of the TensorFlow library, and demonstrate usability improvements with no loss in performance compared to native TensorFlow graphs. We also show that our system is backend agnostic, and demonstrate targeting an alternate IR with characteristics not found in TensorFlow graphs.
翻译:在机器学习中,人们会认为机器学习代码是容易写成的,而机器学习代码则是可以缩放或快速执行的。在机器学习中,像Autograd和PyTorrch这样的必修风格图书馆很容易写成,但受高判读管理,无法在生产或移动环境中轻易部署。TensorFlow和Theano这样的图表图书馆受益于全程序优化,可以广泛部署,但使表达复杂的模型更加繁琐。我们描述了在Python(通过源代码转换)中使用分阶段编程的方式如何在这两种图书馆设计模式之间提供一个中点,捕捉这两种模式的好处。一个关键的洞察力是将所有依赖类型的决定延迟到运行时,通过动态发送。我们在AutoGraph(一个软件系统,可以改进TensorFlow图书馆的编程经验,并显示与本地TensorFlow图形相比,在性能方面没有任何损失的可用性能改进。我们还展示了我们的系统是后端的,并展示了在TensorFlowglastops中以其他具有特性的IRs。