[Paper Review] Automatic differentiation in ML: Where we are and where we should be going
This paper proposes a novel graph-based intermediate representation (IR) for automatic differentiation (AD) in machine learning, enabling full support for higher-order functions, recursion, and closures—features often missing in existing frameworks. Using source transformation, Myia compiles Python code into an optimized, tape-free AD pipeline that enables ahead-of-time optimization and higher-order derivatives, achieving performance comparable to TensorFlow while retaining PyTorch’s flexibility.
We review the current state of automatic differentiation (AD) for array programming in machine learning (ML), including the different approaches such as operator overloading (OO) and source transformation (ST) used for AD, graph-based intermediate representations for programs, and source languages. Based on these insights, we introduce a new graph-based intermediate representation (IR) which specifically aims to efficiently support fully-general AD for array programming. Unlike existing dataflow programming representations in ML frameworks, our IR naturally supports function calls, higher-order functions and recursion, making ML models easier to implement. The ability to represent closures allows us to perform AD using ST without a tape, making the resulting derivative (adjoint) program amenable to ahead-of-time optimization using tools from functional language compilers, and enabling higher-order derivatives. Lastly, we introduce a proof of concept compiler toolchain called Myia which uses a subset of Python as a front end.
Motivation & Objective
- To address the limitations of existing ML frameworks in supporting general AD for array programming, especially regarding recursion and higher-order functions.
- To design a graph-based intermediate representation (IR) that natively supports closures and function composition, enabling more expressive and composable ML models.
- To enable tape-free, source transformation-based AD that supports higher-order derivatives and is amenable to optimization via functional language compiler techniques.
- To build a proof-of-concept compiler toolchain (Myia) that compiles a Python subset into efficient, optimized derivative code with full type and shape inference.
- To bridge the gap between ML frameworks and functional language compiler research by integrating advanced optimization and type inference techniques into AD pipelines.
Proposed method
- Design a graph-based intermediate representation (IR) that represents programs as first-class values, supporting function calls, closures, and recursion.
- Use source transformation (ST) to generate adjoint programs from the IR, avoiding the need for a runtime tape by leveraging closure representation.
- Implement a type and shape inference system using coroutines that infer types, values, and shapes without requiring type annotations.
- Apply standard functional language optimizations (e.g., inlining, constant folding) to the derivative program using tools from functional compiler toolchains.
- Compile the optimized derivative code into efficient machine code using a virtual machine and GPU backend, with specialization per input type.
- Parse Python functions into an abstract syntax tree (AST), convert to the IR, apply AD via source transformation, and optimize the resulting derivative graph.
Experimental results
Research questions
- RQ1How can automatic differentiation be efficiently and generically supported in array programming frameworks that support higher-order functions and recursion?
- RQ2Can a graph-based intermediate representation be designed to natively represent closures and function composition, enabling full AD without runtime tape overhead?
- RQ3To what extent can functional language compiler optimizations (e.g., A-normal form, persistent data structures) be applied to derivative programs in ML frameworks?
- RQ4Can a source transformation-based AD system achieve performance comparable to compiled frameworks like TensorFlow while retaining the flexibility of dynamic frameworks like PyTorch?
- RQ5How can type and shape inference be performed efficiently in a dynamically typed language like Python without requiring explicit type annotations?
Key findings
- The proposed graph-based IR natively supports higher-order functions, recursion, and closures, enabling more expressive and composable ML model implementations than current frameworks.
- By using source transformation with closure representation, the system avoids the need for a runtime tape, enabling efficient, optimized derivative code generation.
- The derivative programs generated by Myia are amenable to ahead-of-time optimization using functional language compiler techniques, improving performance and reducing overhead.
- Type and shape inference in Myia operates without requiring type annotations, enabling users to write dynamic Python code that is still efficiently compiled and type-checked.
- The Myia prototype demonstrates that it is possible to achieve performance comparable to TensorFlow while supporting features like recursion and higher-order functions that are absent in static computation graph frameworks.
- The system enables higher-order derivatives through a clean, composable representation, overcoming limitations of existing frameworks that restrict derivative computation to first-order or non-composable forms.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.