NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Coarsening Optimization for Differentiable Programming

Xipeng Shen, Guoqiang Zhang, Irene Dea, Samantha Andow, Emilio Arroyo-Fang, Neal Gafter, Johann George, Melissa Grueter, Erik Meijer, Steffi Stumpos, Alanna Tempest, Christy Warden, Shannon Yang

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 coarsening optimization pipeline, illustrating the flow from source program to optimized output via symbolic elevation and differentiation.

The methodology relies on three key innovations:

  1. Coarsening: The system identifies SOIs, elevates them to symbolic representations, differentiates them mathematically, and reintegrates these optimized "shortcuts" into the standard AD flow.
  2. $\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.
  3. 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).

Illustration of the CartPole benchmark, showing the physical system, training pseudo-code, and the underlying computational graph used for differentiation.

Key results include:

  • Differentiation Speedup: In the Kotlin-based DiffKt tool, 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

BibTeX
@article{shen2021coarsening,
  author = {Xipeng Shen and Guoqiang Zhang and Irene Dea and Samantha Andow and Emilio Arroyo-Fang and Neal Gafter and Johann George and Melissa Grueter and Erik Meijer and Steffi Stumpos and Alanna Tempest and Christy Warden and Shannon Yang},
  title = {{Coarsening Optimization for Differentiable Programming}},
  journal = {Proc. ACM Program. Lang.},
  year = {2021},
  doi = {10.1145/3485507},
}
Figure