Abstract
Neural Tangents is a library designed to enable research into infinite-width neural networks. It provides a high-level API for specifying complex and hierarchical neural network architectures. These networks can then be trained and evaluated either at finite-width as usual or in their infinite-width limit. Infinite-width networks can be trained analytically using exact Bayesian inference or using gradient descent via the Neural Tangent Kernel. Additionally, Neural Tangents provides tools to study gradient descent training dynamics of wide but finite networks in either function space or weight space. The entire library runs out-of-the-box on CPU, GPU, or TPU. All computations can be automatically distributed over multiple accelerators with near-linear scaling in the number of devices. Neural Tangents is available at www.github.com/google/neural-tangents. We also provide an accompanying interactive Colab notebook.
Introduction
In the theoretical study of deep learning, a major breakthrough was the discovery that as neural networks become infinitely wide, they simplify into well-understood mathematical objects called Gaussian Processes (GPs). Specifically, the Neural Network Gaussian Process (NNGP) describes the Bayesian behavior of an infinite-width network at initialization, while the Neural Tangent Kernel (NTK) describes how it evolves during training via gradient descent.
While these infinite models are powerful tools for understanding generalization and training, their practical application has been arduous. Researchers previously had to derive specific kernels for every new architecture by hand—a process that is laborious and error-prone. Neural Tangents aims to be the "Automatic Differentiation" equivalent for infinite networks, moving the field from manual derivation to automated computation.
Methods
The library is built on JAX, leveraging its ability to compile high-performance code for CPU, GPU, and TPU via XLA. The core technical approach involves:
- Translation Rules: Mapping standard tensor operations (like
Dense,Conv, orRelu) to their corresponding kernel operations. - Compositionality: Allowing users to stack kernel operations just as they would stack layers in a standard network.
- Monte Carlo Estimation: Providing tools to estimate kernels by sampling wide-but-finite networks for architectures where an analytic kernel doesn't yet exist.
- Performance Optimizations: Handling the $O(N^2)$ or $O(N^3)$ complexity of kernel methods through block-diagonal covariance, 2D convolutional kernels, and simultaneous computation of NNGP and NTK kernels.
Results
The library validates theoretical predictions against empirical data from CIFAR-10, MNIST, and synthetic tasks.
Theoretical Alignment
A primary result is the library's ability to perfectly match the mean behavior of an ensemble of wide-but-finite networks with analytic predictions. As shown in Figure 1, the infinite-width theory accurately captures both the training loss dynamics and the final function learned by the network.
Architecture and Efficiency
On CIFAR-10, infinite-width models follow the same performance hierarchy as their finite counterparts (WideResNet > Convolutional > Fully-Connected). Furthermore, by leveraging XLA fusion and batching, the library can execute a 45,000 x 45,000 training covariance matrix solve in under 3 minutes on a single GPU, demonstrating near-perfect linear scaling across multiple accelerators.
Discussion
Despite these advancements, kernel methods still face fundamental bottlenecks, such as the memory requirements for storing $N \times N$ matrices. Future work involves exploring sparse or approximate kernels for larger datasets. Additionally, while many common layers are supported, some (e.g., Dropout, GlobalSelfAttention) currently require Monte Carlo estimation. Neural Tangents bridges the gap between weight-space and function-space views of deep learning, providing a robust platform for future theoretical and practical research.
Summary updated