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

Efficient Differentiable Programming in a Functional Array-Processing Language

Amir Shaikhha, Andrew W Fitzgibbon, Dimitrios Vytiniotis, Simon Peyton Jones, Christoph Koch

TL;DR

This paper introduces "dF", a system for automatic differentiation (AD) built on a functional array-processing language. By integrating AD with powerful compiler optimizations like loop transformations, dF generates highly efficient code that outperforms existing state-of-the-art AD tools on various machine learning and computer vision benchmarks.

What Problem Does This Paper Address?

Manually computing derivatives for complex functions is tedious and error-prone, especially in fields like machine learning and computer vision where derivatives are crucial for optimization. While automatic differentiation (AD) tools exist, they often struggle with performance, particularly for array-heavy computations common in modern applications. Existing AD systems either rely on procedural languages with limited optimization capabilities or functional languages that don't efficiently handle array processing. This gap leads to slow execution times for critical tasks.

Methods

The core of dF is a functional array-processing language (F) that supports both AD and global compiler optimizations like loop transformations. This dual capability is key. dF uses source-to-source AD, transforming expressions into a "dual number" representation that carries both the original value and its derivative. Crucially, the compiler can then apply optimizations like loop-invariant code motion and loop fusion to these differentiated expressions, eliminating redundant computations and intermediate data structures. This allows dF to generate efficient C code with optimized memory management.

Datasets

Not discussed in the paper. The paper focuses on micro-benchmarks and real-world applications rather than specific datasets.

Key Insights and Ideas

  • AD + Compiler Optimizations = Performance: The most significant insight is that combining AD with advanced compiler optimizations (like loop fusion and invariant code motion) is not just beneficial but essential for achieving high performance in array-heavy computations.
  • Functional Language as a Foundation: Using a functional language as the base for AD allows for elegant expression of derivatives and provides a natural framework for applying transformations that are difficult in imperative languages.
  • Exposing Constructs to the Compiler: By making all constructs (including array operations and loops) visible to the compiler, dF can perform sophisticated optimizations that are missed by AD tools that operate at a higher level of abstraction or on less expressive languages.
  • Avoiding Perturbation Confusion: dF's approach to handling nested differentiation (e.g., computing Hessians) correctly avoids the "perturbation confusion" problem, a common pitfall in AD systems.

Key Results

  • dF consistently outperforms existing AD tools like Tapenade (both forward and reverse modes) on micro-benchmarks, often by orders of magnitude, especially when using optimizations like loop fusion and DPS.
  • For real-world applications like Non-Negative Matrix Factorization (NNMF) and Gaussian Mixture Models (GMM), dF achieves significant speedups (e.g., 2x-5x for NNMF, 2-4 orders of magnitude improvement for GMM gradient computation compared to Tapenade).
  • The generated C code using Destination-Passing Style (DPS) for memory management further enhances performance by reducing overhead.
  • dF can automatically derive complex matrix calculus identities, demonstrating its power in symbolic manipulation of derivatives.

Limitations and Future Work

  • Manual Rewrite Rule Sequencing: The authors acknowledge that the sequence of applying rewrite rules for optimization can be tricky and currently requires manual specification. They plan to investigate automated search strategies for this.
  • Hessian Matrix Support: While dF handles nested differentiation, explicit support for computing Hessian matrices is planned for future work.
  • Variable-Size Vectors: Similar to Stalingrad, dF currently has limitations with statically unknown-size vectors, which are unfolded using Scheme macros.
  • Parallel Code Generation: While dF generates efficient C code, parallel code generation and efficient machine code generation are orthogonal concepts that could be integrated in the future.

Summary updated

BibTeX
@inproceedings{shaikhha2019efficient,
  author = {Amir Shaikhha and Andrew W Fitzgibbon and Dimitrios Vytiniotis and Simon Peyton Jones and Christoph Koch},
  title = {{Efficient Differentiable Programming in a Functional Array-Processing Language}},
  booktitle = {Proc. ACM Program. Lang},
  year = {2019},
  url = {https://openreview.net/forum?id=iAfgFhbpvgK},
}
Figure