Skip to content

Cap AutoEnzyme Lagrangian Hessian batches at width 8 - #1340

Draft
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/enzyme-lagrangian-hessian-batches
Draft

Cap AutoEnzyme Lagrangian Hessian batches at width 8#1340
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/enzyme-lagrangian-hessian-batches

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 4, 2026

Copy link
Copy Markdown
Member

Ignore this PR until it has been reviewed by @ChrisRackauckas.

What changed and why

OptimizationBase now computes generated AutoEnzyme Lagrangian Hessians in batches capped at width 8. Inputs larger than 8 use repeated fixed-width calls with zero tangent padding in the final batch, reusing the private policy and caches already used for objective Hessians.

OptimizationMOI requests lag_h for non-symbolic constrained problems. That path still differentiated every variable in one BatchDuplicated, so its LLVM compile time grew sharply with problem size even after objective Hessian batching was added in #1331. This change covers both dense and packed in-place Lagrangian Hessian outputs, is internal, and adds no public API or dependency.

Failing before and passing after

The same 17-parameter regression test computes and checks dense and packed Lagrangian Hessians, then verifies that the generated closure captures the width-8 policy.

Clean origin/master with the test applied:

Enzyme Hessian batch cap: Test Failed
Expression: any((getfield(optf_lagrangian.lag_h, i) isa Val{8} ...))
AD | 803 passed, 1 failed, 804 total in 9m06.1s

This branch:

AD | 804 passed / 804 total in 8m46.5s
Testing OptimizationBase tests passed
Testing Optimization tests passed

A focused Julia 1.11.9 reproducer using the exact 183-variable, 120-constraint clnlbeam equations loaded the OptimizationEnzymeExt path and checked its result against the analytic Hessian:

OptimizationBase 5.5.3, unbounded width: 207.182129194 seconds, max error 0.0
this branch, width 8:                  11.457115908 seconds, max error 0.0

The reduced three-backend benchmark sequence also discriminated the change:

OptimizationBase 5.5.3: exit 124 after 1:00:14, last line `start backend=enzyme N=60`
this branch: exit 0 after 6:40.57, correct objectives through the benchmark's time gating

Verification

GROUP=OptimizationBase_AD julia +1.12.7 --startup-file=no --project=. -e 'using Pkg; Pkg.test()'
AD | 804 passed / 804 total in 8m46.5s

GROUP=QA julia +1.12.7 --startup-file=no --project=. -e 'using Pkg; Pkg.test()'
QA | 21 passed / 21 total in 1m17.7s

The Runic check, typos on both changed files, and git diff --check all exited successfully with no output.

The exact Julia 1.11.9 SciMLBenchmarks page completed against this source tree and the refreshed registered stack:

timeout 14400 julia +1.11.9 --startup-file=no --threads=auto --project=. benchmark.jl benchmarks/OptimizationFrameworks/clnlbeam.jmd
exit 0 in 27:44.66, maximum RSS 4,833,580 KiB

The generated markdown had no error, exception, failure, unstable, or timeout markers. It produced a non-degenerate 576x384 plot with all six benchmark series, and every embedded objective/solution assertion passed.

Not verified

  • GROUP=Everything, GPU, and Julia prerelease jobs were not run locally.
  • Docs were not built because this changes neither documentation nor public API.
  • Constraint Jacobian and individual constraint-Hessian batching are unchanged.

The main review judgment is reusing the existing fixed private width of 8 for Lagrangian Hessians. A row-at-a-time implementation also avoids the wide batch, but the width-8 version retains batching and reduced the focused first call by about 18 times.

Links

🤖 Generated with Claude Code
https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512
@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the fix/enzyme-lagrangian-hessian-batches branch from ca50051 to 65f0594 Compare September 6, 2026 06:52
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.

2 participants