Skip to main content

omnibias.curvature

0.1.0a2AlphaPython >=3.10AGPL / commercial

Scoped parameter-curvature formulas, Fisher and Gauss–Newton constructions, natural steps, and sharpness utilities.

import omnibias.curvature

Choose curvature when its architecture and loss assumptions match your model. Exact parameter Hessians, Gauss–Newton matrices, Fisher information, empirical Fisher matrices, and KFAC approximations are different objects. Do not interchange their names or guarantees.

Several closed-form constructions target one-hidden-layer Riccati fields or particular likelihood families. Read parameter packing order, residual convention, reduction, and damping before using a returned matrix in an optimizer. A positive-semidefinite approximation can still be singular; the step solver's regularization and rank assumptions matter.

The optimization tutorial demonstrates a supported Gauss–Newton closure with a complete solve. Use it to understand the closure contract, then validate the specific curvature module you need. Generic optimizer interfaces elsewhere in the Torch and JAX packages may use autodiff-based primitives and are not automatically closed-form curvature algorithms.

Module contract & mathematical conventions

Closed-form second-order optimisation for one-layer Riccati fields.

This package promotes the omnibias closed-form Hessian (omnibias.jax.neural_field_value_grad_hessian, which is the D \times D Hessian *with respect to the input*) into a usable **parameter** Fisher / Hessian for the one-hidden-layer scalar field

f_\theta(x) \;=\; b \;+\; \sum_h c_h\, \sigma(W_h \cdot x + \beta_h),

where \sigma is one of the Riccati-class activations exposed by omnibias.jax.activations.get_activation (tanh, sigmoid, softplus, gaussian, exp). The closed forms for \sigma'(z) and \sigma''(z) mean every block of the parameter Hessian / Fisher can be assembled algebraically — no autograd needed.

What this v0.1 ships

The omnibias.curvature.one_layer module provides:

  • one_layer_param_grad — per-sample \nabla_\theta f(x) as a flat vector of length P = 1 + H + H + H \cdot D.
  • one_layer_param_hessian — per-sample full Hessian \nabla^2_\theta f(x); block-diagonal-in-hidden-unit with (D+2) \times (D+2) blocks.
  • mse_gauss_newton_fisher — Gauss-Newton Fisher F = \tfrac{2}{B}\sum_n g_n g_n^T for MSE loss; the standard positive-definite curvature surrogate used by natural-gradient and KFAC.
  • mse_newton_step — one Newton-Gauss step \theta \leftarrow \theta - \eta\,(F + \lambda I)^{-1} \nabla L.
  • kfac_kron_factors — closed-form KFAC (A, G) Kronecker factors for the hidden block, computed from x_n x_n^T and (c \odot \sigma'(z_n))(c \odot \sigma'(z_n))^T statistics.

Exact-curvature sharpness ("SAM done right")

The omnibias.curvature.sharpness module builds on the closed-form Hessian to measure and regularise the *sharpness* of a basin exactly, where Sharpness-Aware Minimisation only estimates its linear shadow:

  • mse_loss_hessian — the **exact full loss Hessian** (Gauss-Newton *plus* the r_n\,\nabla^2_\theta f residual term).
  • hessian_trace / hessian_frobenius_sq / hessian_top_eigenvalue — the sharpness functionals \sum_i\lambda_i, \sum_i\lambda_i^2, \lambda_{\max}.
  • sharpness_aware_loss — L + \lambda\,\mathcal S(\nabla^2 L), a differentiable curvature regulariser (its gradient pulls in \sigma''' in closed form).
  • sam_objective — the ascent-free, exact second-order SAM surrogate L + \rho\lVert\nabla L\rVert + \tfrac12\rho^2\lambda_{\max}.

These are the **one-layer, JAX** primitives. The arbitrary-depth, **PyTorch** port lives in omnibias.curvature.torch (matrix-free via exact Hessian-vector products) and requires the optional torch extra; it is intentionally not imported here so this namespace stays JAX-only.

What's still on the roadmap

  • Integration with kfac_jax as a custom layer registration so that a FermiNet trainer can drop in the closed-form Fisher block for the omnibias-envelope layer.

These follow-ups are tracked on the public roadmap in docs/roadmap.md.

Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.

Imports & aliases​

These names share a definition with another public module. Follow a name for its full contract, parameters, and examples.

Import from this moduleCanonical reference
CollapseResultomnibias.curvature.CollapseResult
damped_solveomnibias.curvature.damped_solve
fisher_information_metricomnibias.curvature.fisher_information_metric
glm_loss_gradientomnibias.curvature.glm_loss_gradient
glm_natural_gradient_stepomnibias.curvature.glm_natural_gradient_step
hessian_frobenius_sqomnibias.curvature.hessian_frobenius_sq
hessian_top_eigenvalueomnibias.curvature.hessian_top_eigenvalue
hessian_traceomnibias.curvature.hessian_trace
kfac_kron_factorsomnibias.curvature.kfac_kron_factors
min_norm_solveomnibias.curvature.min_norm_solve
mse_curvature_sharpnessomnibias.curvature.mse_curvature_sharpness
mse_gauss_newton_fisheromnibias.curvature.mse_gauss_newton_fisher
mse_lossomnibias.curvature.mse_loss
mse_loss_hessianomnibias.curvature.mse_loss_hessian
mse_newton_stepomnibias.curvature.mse_newton_step
natural_gradient_stepomnibias.curvature.natural_gradient_step
numerical_rankomnibias.curvature.numerical_rank
one_layer_param_gradomnibias.curvature.one_layer_param_grad
one_layer_param_hessianomnibias.curvature.one_layer_param_hessian
rank_collapseomnibias.curvature.rank_collapse
regularization_pathomnibias.curvature.regularization_path
regularized_solveomnibias.curvature.regularized_solve
sam_objectiveomnibias.curvature.sam_objective
sam_sharpness_gapomnibias.curvature.sam_sharpness_gap
sharpness_aware_lossomnibias.curvature.sharpness_aware_loss