Skip to main content
QUICK REVIEW

[Paper Review] Differentiating a Tensor Language

Gilbert Bernstein, Michael W. Mara|arXiv (Cornell University)|Aug 25, 2020
Parallel Computing and Optimization TechniquesComputer Science29 references5 citations
TL;DR

This paper presents a purely functional, provably efficient method for computing reverse-mode derivatives of tensor programs by explicitly modeling sparsity using Iverson's indicator function. By leveraging a new 'Tensor SSA' normal form and a derivation of automatic differentiation based on inner products, the approach achieves the Cheap Gradients Principle without mutation, ensuring derivative code is asymptotically as efficient as the original function.

ABSTRACT

How does one compile derivatives of tensor programs, such that the resulting code is purely functional (hence easier to optimize and parallelize) and provably efficient relative to the original program? We show that naively differentiating tensor code---as done in popular systems like Tensorflow and PyTorch---can cause asymptotic slowdowns in pathological cases, violating the Cheap Gradients Principle. However, all existing automatic differentiation methods that guarantee this principle (for variable size data) do so by relying on += mutation through aliases/pointers---which complicates downstream optimization. We provide the first purely functional, provably efficient, adjoint/reverse-mode derivatives of array/tensor code by explicitly accounting for sparsity. We do this by focusing on the indicator function from Iverson's APL. We also introduce a new "Tensor SSA" normal form and a new derivation of reverse-mode automatic differentiation based on the universal property of inner-products.

Motivation & Objective

  • To address the inefficiency of naive automatic differentiation in tensor programs, which can lead to asymptotic slowdowns in gradient computation.
  • To preserve data-parallelism and enable downstream optimization by avoiding imperative side-effects like += mutation.
  • To formally guarantee the Cheap Gradients Principle in a purely functional setting for dense and sparse tensors.
  • To introduce a new normal form, 'Tensor SSA', that enables efficient and correct derivative compilation.
  • To provide a mathematically rigorous foundation for reverse-mode AD using the universal property of inner products.

Proposed method

  • The method uses Iverson's indicator function to represent boolean predicates and explicitly model sparsity in tensor operations.
  • It introduces a new 'Tensor SSA' normal form that enables static analysis and optimization of tensor programs.
  • Derivatives are derived using the universal property of inner products, ensuring correctness and efficiency.
  • The approach accounts for sparsity in adjoint computations, avoiding unnecessary memory writes.
  • It applies algebraic simplifications that preserve asymptotic efficiency, even in pathological cases.
  • The method avoids += mutation by treating sparsity as first-class, enabling purely functional compilation.

Experimental results

Research questions

  • RQ1Can we achieve the Cheap Gradients Principle in a purely functional tensor language without relying on imperative side-effects?
  • RQ2How can sparsity in tensor operations be formally modeled to ensure efficient derivative computation?
  • RQ3What normal form enables efficient and correct reverse-mode automatic differentiation in data-parallel tensor programs?
  • RQ4Can the universal property of inner products be used to derive a provably efficient AD system?
  • RQ5How can asymptotic inefficiencies in existing frameworks (e.g., PyTorch, TensorFlow) be systematically avoided?

Key findings

  • The proposed method achieves the Cheap Gradients Principle in a purely functional setting, ensuring derivative computation is at most a constant factor slower than the original program.
  • By modeling sparsity via Iverson’s indicator function, the method avoids unnecessary memory writes in adjoint computations, such as in diag and trace operations.
  • The method proves cost-equivalence between forward and reverse passes, even when accounting for inner-product and summation adjustments.
  • The Tensor SSA normal form enables static analysis and optimization, preserving data-parallelism and enabling efficient compilation.
  • The approach outperforms naive differentiation in pathological cases—e.g., gradient of trace(A) + ... + trace(A) is no longer O(kN²) but O(kN) when optimized.
  • The method avoids reliance on += mutation, thus preserving functional purity and enabling stronger compiler optimizations.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.