Skip to main content
QUICK REVIEW

[Paper Review] DiffSharp: An AD Library for .NET Languages

Atılım Güneş Baydin, Barak A. Pearlmutter|arXiv (Cornell University)|Nov 10, 2016
Parallel Computing and Optimization TechniquesComputer Science6 references11 citations
TL;DR

DiffSharp is a high-performance, functional programming-based algorithmic differentiation (AD) library for .NET languages, implemented in F# and targeting machine learning workloads. It provides a nested, higher-order functional API with forward and reverse AD, efficient BLAS/LAPACK-backed linear algebra, and supports extensibility via operator overloading and planned source transformation and GPU backends.

ABSTRACT

DiffSharp is an algorithmic differentiation or automatic differentiation (AD) library for the .NET ecosystem, which is targeted by the C# and F# languages, among others. The library has been designed with machine learning applications in mind, allowing very succinct implementations of models and optimization routines. DiffSharp is implemented in F# and exposes forward and reverse AD operators as general nestable higher-order functions, usable by any .NET language. It provides high-performance linear algebra primitives---scalars, vectors, and matrices, with a generalization to tensors underway---that are fully supported by all the AD operators, and which use a BLAS/LAPACK backend via the highly optimized OpenBLAS library. DiffSharp currently uses operator overloading, but we are developing a transformation-based version of the library using F#'s "code quotation" metaprogramming facility. Work on a CUDA-based GPU backend is also underway.

Motivation & Objective

  • To provide a high-performance, composable AD library for the .NET ecosystem, particularly for machine learning applications.
  • To enable seamless integration of algorithmic differentiation into functional and imperative .NET languages like F# and C#.
  • To support efficient computation of gradients, Jacobians, and Hessians using both forward and reverse modes.
  • To develop a modular, extensible AD infrastructure with support for future GPU and tensor extensions.

Proposed method

  • Uses higher-order functional programming in F# to expose AD as first-class, composable functions.
  • Employs a structure-of-arrays representation for vectors and matrices to enable efficient vectorized AD with BLAS/LAPACK backends.
  • Implements forward and reverse AD via curried, nestable operators such as jacobianTv’’ and hessian for modular derivative computation.
  • Supports operator overloading for immediate usability, with a planned transition to source transformation using F# code quotations for performance.
  • Provides a backend abstraction allowing integration of optimized backends, including OpenBLAS and a CUDA-based backend under development.
  • Uses value tagging to prevent perturbation confusion in nested AD operations.

Experimental results

Research questions

  • RQ1How can algorithmic differentiation be effectively and efficiently exposed as a composable, functional API in .NET languages?
  • RQ2What performance and correctness guarantees can be achieved in nested AD computations, especially in the presence of perturbation confusion?
  • RQ3To what extent can AD performance be improved through optimized linear algebra backends and vectorized operations?
  • RQ4Can a functional, higher-order AD library be both user-friendly and performant across both functional and imperative .NET languages?
  • RQ5How can AD infrastructure be extended to support modern machine learning workloads, including deep learning and GPU acceleration?

Key findings

  • DiffSharp provides a correct, high-performance AD implementation that avoids perturbation confusion through value tagging in nested derivative computations.
  • The structure-of-arrays representation for vectors and matrices enables efficient vectorization of AD, with performance dominated by external BLAS/LAPACK calls.
  • The library achieves high usability and modularity through a functional, higher-order API that supports currying and nesting of AD operators.
  • Benchmarking shows low AD runtime overhead, with performance highly dependent on optimized backends like OpenBLAS.
  • The planned migration to source transformation via F# code quotations is expected to further improve performance and simplify the API.
  • GPU backend development using CUDA and cuDNN is underway, with the goal of enabling high-performance deep learning workloads on GPU.

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.