Abstract
Modern differentiable programming frameworks primarily utilize Algorithmic Differentiation (AD) to handle complex code structures like loops and branches. However, AD's fine-grained approach often incurs significant runtime overhead due to operation tracking and memory allocation. This paper presents "coarsening optimization," a novel technique that integrates Symbolic Differentiation (SD) into the AD workflow. By leveraging a new mathematical framework, $\phi$-calculus, the system can symbolically represent and differentiate control flow. Evaluation across diverse benchmarks demonstrates substantial performance gains, with differentiation speedups reaching up to 27x in Kotlin and over 300x in JAX, while significantly reducing memory allocations.
Introduction
Modern machine learning and scientific computing rely heavily on Automatic Differentiation (AD). Frameworks like PyTorch, JAX, and TensorFlow use AD to decompose programs into elementary operations, applying the chain rule step-by-step. While flexible, this "fine-grained" approach necessitates tracking every operation and wrapping data in "Tensor" objects (boxing), leading to high overhead. Conversely, Symbolic Differentiation (SD) is mathematically efficient but traditionally struggles with control flow and "expression swell." This work bridges these paradigms by introducing coarsening optimization to achieve the efficiency of SD with the generality of AD.
Methods
The proposed system architecture centers on identifying and optimizing "Segments of Interest" (SOIs) within a program. As shown in Figure 1, the pipeline elevates these segments to a symbolic representation before applying differentiation and optimization.
The methodology relies on three key innovations:
- Coarsening: The system identifies SOIs, elevates them to symbolic representations, differentiates them mathematically, and reintegrates these optimized "shortcuts" into the standard AD flow.
- $\phi$-calculus: This framework represents control flow (branches and loops) as symbolic expressions. By utilizing Static Single Assignment (SSA) form, $\phi$-functions transform logic into differentiable mathematical expressions.
- Reuse-aware SOI Identification: To mitigate expression swell and preserve computation reuse, an algorithm traverses a "def-use region tree" to determine optimal SOI boundaries.
Evaluation and Results
The authors evaluated coarsening optimization using six benchmarks representing real-world applications, including meta-learning (BGDHyperOpt), physics simulations (Brachist, HookeanSpring), and reinforcement learning environments like CartPole (Figure 2).
Key results include:
- Differentiation Speedup: In the Kotlin-based
DiffKttool, differentiation became 1.03x to 27x faster. When applied to other popular tools, the gains were even more dramatic: JAX saw speedups up to 335x, and Zygote (Julia) saw up to 150x. - End-to-End Performance: Total application runtime improved by 1.08x to 11x.
- Memory Efficiency: For the meta-learning benchmark, coarsening reduced memory allocations by over 70% by eliminating the "boxing" tax associated with wrapping scalars in tensor objects.
- Primal Removal: In specific cases like the Brachistochrone problem, the system can skip original "primal" calculations and compute derivatives directly, further enhancing efficiency.
Discussion and Conclusion
Coarsening optimization demonstrates that control flow is not an inherent barrier to symbolic methods. By treating branches and loops as differentiable functions via $\phi$-calculus, the overhead of traditional AD can be largely eliminated. While currently most effective in static compilation, future work aims to extend these benefits to dynamic languages and handle more complex array indexing challenges. This hybrid approach marks a significant step toward high-performance differentiable programming for non-standard workloads.
Summary updated