Skip to content

Add batched block-tridiagonal Levenberg-Marquardt optimizer - #2955

Open
kshaji3 wants to merge 2 commits into
borglab:developfrom
kshaji3:gpu-batched-lm-optimizer
Open

kshaji3 wants to merge 2 commits into
borglab:developfrom
kshaji3:gpu-batched-lm-optimizer

Conversation

@kshaji3

@kshaji3 kshaji3 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor
  • This PR adds batched tridiagonal processing via BatchedBlockTridiagonalLevenbergMarquardtOptimizer, which runs Levenberg-Marquardt over a set of independent nonlinear factor graphs in a single batched GPU call.
  • This PR builds on the batched block-tridiagonal linear solver and Hessian assembly method added in Add batched block-tridiagonal CUDA linear solver for independent systems #2954.
  • The BatchedFactorGroupHook lets a caller batch an expensive, cross-item factor evaluation across a whole batch in one call instead of once per item per graph, which further streamlines operations.
  • Also added appropriate unit tests that report timing
  • Multi-GPU usage:

Multi-GPU usage

  • BatchedSolverOptions.deviceId is left at its default (-1), an instance binds to whatever CUDA device is already current for the constructing thread. However, you can modify this externally by using PyTorch 'DistributedDataParallel`, so it can use different GPUs for each thread.

This PR builds on #2954

@kshaji3 kshaji3 mentioned this pull request Nov 27, 2026
@kshaji3 kshaji3 closed this Nov 27, 2026
@kshaji3 kshaji3 reopened this Nov 27, 2026
@kshaji3

kshaji3 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

This PR is GPU batching for optimizers only.

Shaji and others added 2 commits December 2, 2026 10:20
Adds a persistent cuSOLVER/cuBLAS backend that factorizes and solves B
independent block-tridiagonal SPD linear systems in a single batched GPU
call (block Thomas algorithm), plus the Hessian assembler that builds
those block-tridiagonal normal equations from a batch of Jacobians on
the device. This targets graphs whose factors only couple one or two
adjacent variable blocks -- chain/window-graph structures such as
DFG-TAMP's build_window_graph -- reducing factorize cost to
O(numBlocks * blockDim^3) instead of forming and factorizing a dense
n x n Hessian per item.

This is scoped as a standalone linear-algebra layer, analogous to the
existing LinearSolverSession split of system representation from
backend selection and factorize/solve. It does not itself expose an
optimizer or a differentiation API; those are separate, independent
consumers of this solver (to follow as separate PRs) and should not
need to re-implement block-tridiagonal factorization or Hessian
assembly themselves.

New classes:
- BatchedBlockTridiagonalCholeskySolver (gtsam/linear/cuda/internal):
  factorize()/solve() over DeviceArray<double> diagonal/off-diagonal
  blocks and RHS, reusing persistent cuSOLVER/cuBLAS handles and device
  buffers across calls instead of allocating per step.
- BatchedBlockHessianAssembler (gtsam/linear/cuda/internal): builds the
  block-tridiagonal A^T A / A^T b blocks for a batch of linearized
  systems directly on the GPU via cuBLAS, avoiding a host round-trip.
- BatchedSolverOptions (gtsam/linear/cuda/internal): the device-
  selection struct shared by every batched CUDA backend built on top of
  this solver (deviceId -1 keeps the calling thread's current device,
  >= 0 pins an instance to one device).

Tests: testCudaBatchedBlockHessianAssembler.cpp and
testCudaBatchedBlockTridiagonalCholeskySolver.cpp validate assembly and
factorize/solve against an Eigen ldlt() reference on the equivalent
dense system, including rejection of a non-positive-definite block.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds BatchedBlockTridiagonalLevenbergMarquardtOptimizer, which runs
Levenberg-Marquardt over B independent nonlinear factor graphs of the
same block-tridiagonal shape in a single batched GPU call, built on the
batched block-tridiagonal linear solver and Hessian assembler added in
the prior PR. This targets GTSAM's existing data-parallel-training use
case -- many small, independent, same-shaped graphs (e.g. one per
timestep/window) -- where per-item CPU or single-graph-GPU optimization
is dominated by kernel-launch/dispatch overhead rather than compute.

Per-graph lambda, acceptance, and convergence state are tracked
independently per item (BatchedBlockTridiagonalLevenbergMarquardtItemResult),
and the optimizer reuses the same LM damping/acceptance policy as the
existing single-graph implementation (gtsam::internal::LevenbergMarquardtPolicy)
rather than reimplementing it, so behavior such as diagonal damping
stays consistent with gtsam::LevenbergMarquardtOptimizer. optimize()
runs to convergence per gtsam::LevenbergMarquardtParams; polish(n) takes
n further accepted-if-improving steps per item afterward.

BatchedFactorGroupHook lets a caller batch an expensive, cross-item
factor evaluation (e.g. a neural-network energy function evaluated via
vmap/jacrev) across the whole batch in one call instead of once per
item per graph, which is the dominant cost for DFG-TAMP's energy-based
factors; it has no effect on factors that don't register a hook.

Tests (testCudaBatchedBlockTridiagonalLevenbergMarquardt.cpp) compare
batched results against gtsam::LevenbergMarquardtOptimizer on scalar
CPU Pose2 graphs, including an ill-scaled chain graph with diagonal
damping enabled (one LM step), and exercise the factor-group hook path.
A timing harness (timing/batched_lm) reports linearization, assembly,
transfer, factorize, solve, and total time separately against a scalar
CPU baseline, measured on DFG-TAMP's production chain-graph shape.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kshaji3

kshaji3 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Updated PR description.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant