NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Theseus: A Library for Differentiable Nonlinear Optimization

Luis Pineda, Taosha Fan, Maurizio Monge, Shobha Venkataraman, Paloma Sodhi, Ricky T. Q. Chen, Joseph Ortiz, Daniel DeTone, Austin S. Wang, Stuart Anderson, Jing Dong, Brandon Amos, Mustafa Mukadam

Deep learning excels at pattern recognition but often lacks the geometric and physical "common sense" inherent in classical robotics and vision algorithms. In these fields, core problems like Simultaneous Localization and Mapping (SLAM) or bundle adjustment are typically solved using Nonlinear Least Squares (NLS) optimization—finding the best parameters to minimize a sum of squared errors.

The challenge is that traditional optimization solvers (such as Ceres) are not easily differentiable, nor are they designed for the massive batching and GPU acceleration required by modern deep learning pipelines. Previous attempts to bridge this gap resulted in "one-off" implementations that were application-specific, slow, or highly memory-intensive because they relied on "unrolling" (tracking every single step of the optimizer), causing memory usage to explode.

The Theseus Framework

Theseus is an efficient, PyTorch-based library for Differentiable Nonlinear Least Squares (DNLS) optimization. It provides a common framework that allows researchers to plug classical optimization algorithms directly into neural networks as differentiable layers. This enables end-to-end learning with structured inductive priors.

Theseus architecture integrating optimization as a differentiable layer.

By treating an entire optimization problem as a single "layer," neural networks can delegate complex geometric reasoning to a solver that understands physics and geometry. Meanwhile, the neural network can focus on learning the underlying cost weights, feature extractions, or initializations.

Core Architecture and Methods

Theseus is built on three foundational pillars to ensure it is both flexible and highly performant:

  1. Application-Agnostic API: It offers modular components, including second-order optimizers (e.g., Gauss-Newton, Levenberg-Marquardt), standard cost functions, and crucially, differentiable Lie groups for correctly handling 3D rotations and positions.
  2. Efficiency-First Design: Most real-world robotics problems are "sparse"—each measurement only affects a few variables. Theseus demonstrates that utilizing sparse solvers is a strict requirement for scaling. It includes custom sparse solver backends, notably BaSpaCho (a batched sparse Cholesky solver) and cudaLU. It also leverages automatic vectorization via SIMD protocols to accelerate cost and Jacobian computations across batches.
  3. Advanced Differentiation: Instead of relying solely on unrolling, Theseus implements Implicit Differentiation. By applying the Implicit Function Theorem at the optimization's solution, it computes gradients with a constant memory footprint, regardless of how many optimization iterations are performed.

Performance and Scalability

The authors evaluated Theseus across several classic domains to prove its versatility, including Pose Graph Optimization (PGO), image-based tactile state estimation, bundle adjustment for 3D reconstruction, and differentiable motion planning.

Forward and backward pass times comparing sparse and dense solvers.

Key Results

  • Massive Speedups: In large-scale batch processing, Theseus achieves significant performance gains. Its forward pass is up to 20x faster than state-of-the-art C++ solvers like Ceres, which lack native GPU batching support.
  • Scalability: Standard dense solvers in PyTorch often crash due to memory limits at around 256 poses. In contrast, Theseus’s sparse solvers (like BaSpaCho) easily scale to 4096+ poses, maintaining low forward and backward pass times.
  • Better Gradients: Evaluations in tactile sensing showed that implicit differentiation not only saves memory but often yields more stable gradients. This leads to a lower final task loss compared to unrolling or truncated differentiation methods.

Limitations and Future Work

While powerful, Theseus has a few areas for future growth. Currently, the library only handles constraints via "weighted costs" (penalizing violations softly) and lacks support for strict "hard" constraints. Additionally, damping parameters in the Levenberg-Marquardt optimizer are not yet learnable. Finally, while the heavy lifting is done in C++/CUDA, there remains some Python-level overhead, and native distributed training beyond standard PyTorch capabilities is not yet supported.

Summary updated

BibTeX
@inproceedings{pineda2022theseus,
  author = {Luis Pineda and Taosha Fan and Maurizio Monge and Shobha Venkataraman and Paloma Sodhi and Ricky T. Q. Chen and Joseph Ortiz and Daniel DeTone and Austin S. Wang and Stuart Anderson and Jing Dong and Brandon Amos and Mustafa Mukadam},
  title = {{Theseus: A Library for Differentiable Nonlinear Optimization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=zOY5gt6Wq8},
}
Figure