dgasmith/opt_einsum

⚡️Optimizing einsum functions in NumPy, Tensorflow, Dask, and more with contraction order optimization.

What it solves

opt_einsum addresses the performance bottlenecks inherent in complex tensor contractions. Standard einsum implementations often perform operations in a sub-optimal sequence, leading to massive memory overhead and slow execution times. This library automatically finds the most efficient order to perform these contractions, often resulting in speedups of several orders of magnitude.

How it works

It functions as a drop-in replacement for standard einsum functions. By analyzing the expression, it calculates an optimized contraction path—essentially determining the best sequence of operations to minimize the number of intermediate calculations. It then dispatches these operations to high-performance backends like BLAS, cuBLAS, or various deep learning frameworks.

Who it’s for

It is designed for researchers, data scientists, and engineers working with large-scale tensor operations, such as those found in quantum chemistry, physics simulations, and deep learning model development.

Highlights

  • Backend-agnostic: Supports NumPy, PyTorch, TensorFlow, JAX, Dask, CuPy, and more.
  • Massive performance gains: Can optimize contractions involving hundreds or thousands of tensors.
  • Reusable paths: Allows for pre-calculating and reusing contraction paths for compiled, high-performance execution.
  • Advanced features: Supports sharing intermediate computations and computing gradients via autograd or JAX.

Related

  • Project
  • Project
  • Project
  • Project