Generalizing Automatic Differentiation to Automatic Sparsity, Uncertainty, Stability, and Parallelism

Christopher Rackauckas · The Winnower · 2021

Automatic differentiation is a "compiler trick" whereby a code that calculates f(x) is transformed into a code that calculates f'(x).This trick and its two forms, forward and reverse mode automatic differentiation, have become the pervasive backbone behind all of the machine learning libraries.If you ask what PyTorch or Flux.jl is doing that's special, the answer is really that it's doing automatic differentiation over some functions.What I want to dig into in this blog post is a simple question: what is the trick behind automatic differentiation, why is it always differentiation, and are there other mathematical problems we can be focusing this trick towards?While very technical discussions on this can be found in our recent paper titled "ModelingToolkit: A Composable Graph Transformation System For Equation-Based Modeling" and descriptions of methods like intrusive uncertainty quantification, I want to give a high-level overview that really describes some of the intuition behind the technical thoughts.Let's dive in! WHAT IS THE TRICK BEHIND AUTOMATIC DIFFERENTIATION? NON-STANDARD INTERPRETATIONTo understand automatic differentiation in practice, you need to understand that it's at its core a code transformation process.While mathematically it comes down to being about Jacobian-vector products and Jacobian-transpose-vector products for forward and reverse mode respectively, I think sometimes that mathematical treatment glosses over the practical point that it's really about code. Take for example. If we want to take the derivative of this, then we could do , but this misses the information that we actually know analytically how to define the derivative!Using the principle that algorithm efficiency comes from problem information, we can improve this process by directly embedding that analytical solution into our process.So we come to the first principle of automatic differentiation:If you know the analytical solution to the derivative, then replace the function with its derivative So if you see and someone calls ``derivative(f,x)``, you can do a quick little lookup to a table of rules, known as primitives, and if it's in your table then boom you're done.Swap it in, call it a day.This already shows you that, with automatic differentiation, we cannot think of as just a function, just a thing that takes in values, but we have to know something about what it means semantically.We have to look at it and identify "this is sin" in order to know "replace it with cos".This is the fundamental limitation of automatic differentiation: it has to know something about your code, more information than it takes to call or run your code.This is why many automatic differentiation libraries are tied to specific

Read the paper · More papers on PaperTik