Skip to content

Fitting: allow callers to select the automatic differentiation backend #286

Open

Description

@alecloudenback

Problem

All loss-based fits currently use the global __FIT_ADTYPE = SecondOrder(AutoForwardDiff(), AutoForwardDiff()).

Forward mode is a good default for small parametric models, but its cost grows with the number of fitted parameters. Spline and key-rate fits may have dozens or hundreds of parameters, where reverse or sparse differentiation can be preferable. Models containing nondifferentiable operations may also need finite differences.

Proposed direction

Add an adtype keyword to the relevant fit entry points and loss-function builders. Retain a sensible default, but allow callers to provide another DifferentiationInterface/Optimization backend.

Consider using a first-order declaration by default for first-order optimizers and reserving SecondOrder for optimizers that request Hessians.

Acceptance criteria

  • Existing calls retain their current behavior.
  • A caller can supply at least an alternative first-order backend.
  • The selected backend is threaded through generic, spline, and MonotoneConvex loss construction.
  • Tests cover the default and one non-default backend or a lightweight test backend.

Activity

  1. alecloudenback commented on Oct 11, 2026

    @alecloudenback
    MemberAuthor

    Review update against FinanceModels v7.0.0 (6cb71714), 2026-10-11.

    Still applicable; medium priority. The global constant described in the issue has been replaced by per-fit ForwardDiff tags, but __minimize still constructs SecondOrder(AutoForwardDiff(...), AutoForwardDiff(...)) internally. Public fitting entry points do not accept an adtype keyword.

    See backend construction and fit signature. Selecting an optimizer or passing solve_kwargs is not the same as selecting the differentiation backend.

    A future implementation should preserve the current safeguards against differentiating unsupported solver paths and test a genuinely different backend. Benchmark larger calibrations to justify priority; this review did not establish a current performance regression from the default.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions