Solvers
The solver API computes an equilibrium state
by iterating on the residual
The package exposes one configuration object:
from silva_networks import SolverConfig
config = SolverConfig(
solver="anderson",
max_iter=25,
tol=1e-6,
alpha=0.5,
history=5,
stop_mode="relative",
anderson_batch_dims=1,
return_best=True,
indexing=(10, 20),
backward_mode="implicit",
backward_solver="gmres",
backward_stop_mode="relative",
)
fixed_point is the numerical forward-solver dispatcher. Package layers and
presets call solve_equilibrium, which uses the same forward solver and then
chooses the training rule from SolverConfig.backward_mode.
Picard Iteration
The damped Picard update, interpreted through the classical contraction result [41], starts with an initial state \(z_0\). At iteration \(k\), evaluate the transition
The residual is
Damping blends the old state with the proposed state:
When \(\alpha=1\), this is the classical Picard update. Smaller \(\alpha\) can help when the map is nearly non-contractive.
Anderson Acceleration
Anderson acceleration [10] [11] stores recent residuals
For the last \(m\) states, form
The coefficients solve a constrained least-squares problem:
The KKT system used in the implementation is
The next state is
anderson_batch_dims=1 solves the Anderson coefficient system independently
for each leading batch sample, and convergence uses the worst sample residual.
Packed coupled states use anderson_batch_dims=0.
For trainable modules, Anderson history is kept detached to control memory.
SolverConfig(reengage=True) lets package layers evaluate one final
differentiable transition after the accelerated numerical solve, so
solver="anderson" remains a usable training option.
Broyden
Broyden's method [12] treats the equilibrium condition as a root-finding problem:
If \(B_k\) approximates the inverse Jacobian \(J_F(z_k)^{-1}\), the Newton-like step is
Let
The good-Broyden inverse update is
The implementation stores low-rank inverse updates rather than an (n\times n)
matrix. history bounds the retained rank, so Broyden can be selected for
sequence, image, and coupled states without allocating a dense Jacobian-sized
matrix. The approximation restarts from the initial inverse when that rank is
full, then incorporates the newest secant pair.
The returned SolverResult.inverse_estimate is a
BroydenInverseEstimate. Its rank, left_factors, and right_factors expose
the retained numerical state, while apply_residual_inverse,
apply_residual_inverse_transpose, and
apply_fixed_point_adjoint_inverse apply it without materializing a dense
matrix. This is the shared object used by SHINE.
GMRES for Adjoint Systems
The SILVA study's implicit-gradient diagnostic uses the matrix-free GMRES method [13] for a linear adjoint solve. Around an equilibrium, let
The standard DEQ adjoint vector \(u\) solves
where \(g=\partial \mathcal L/\partial z^\star\). The package exposes a matrix-free GMRES helper:
from silva_networks import gmres
result = gmres(lambda v: A(v), b, max_iter=40, tol=1e-6)
u = result.x
For damped update diagnostics,
the helper implicit_adjoint_solve solves
This is useful for reproducing the local linear analysis and GMRES-style diagnostic experiments.
Backward Modes
SolverConfig(backward_mode="unrolled") is the default. It differentiates
through the finite solver computation, with reengage=True giving Anderson
training a final differentiable transition after the detached accelerated
history.
SolverConfig(backward_mode="implicit") runs the forward fixed-point solve
without recording the solver history, then uses GMRES in the backward pass:
from silva_networks import SolverConfig
config = SolverConfig(
solver="anderson",
alpha=0.5,
max_iter=40,
backward_mode="implicit",
backward_solver="gmres",
backward_max_iter=40,
backward_tol=1e-6,
backward_stop_mode="relative",
backward_relative_eps=1e-8,
)
This is the package-level DEQ/SILVA adjoint path. It is useful when reproducing paper setups that train equilibria with implicit differentiation rather than finite unrolling. The transition should be deterministic during the implicit backward solve; set stochastic layers such as dropout to zero or use a stable masking strategy when exact reproducibility matters.
backward_mode="phantom" starts from the detached numerical state and records
phantom_steps damped transitions with phantom_tau. This includes the common
one-step approximation and longer phantom-gradient trajectories.
backward_mode="jfb" implements Jacobian-Free Backpropagation
[88]. It treats the converged
state as a constant and differentiates through exactly one final transition:
backward_mode="shine" implements inverse-estimate sharing
[89]. It requires a Broyden
forward solve. If (B\approx(J_f-I)^{-1}), the initial adjoint estimate is
shine_refine_steps applies additional good-Broyden updates to the exact
adjoint residual. Zero steps uses the raw shared estimate.
config = SolverConfig(
solver="broyden",
history=10,
backward_mode="shine",
shine_refine_steps=2,
backward_tol=1e-6,
)
The public helper shine_adjoint_solve accepts an equilibrium, output gradient,
and BroydenInverseEstimate for direct numerical comparisons.
The implicit adjoint may use gmres, picard, anderson, or broyden through
backward_solver. backward_stop_mode and backward_relative_eps select its
criterion independently of the forward solve. indexing retains selected
one-based forward iterations for trajectory supervision, and return_best=True
returns the lowest-residual observed state when convergence is nonmonotone.
For a derivation and controlled comparison of all backward paths, see Learned Solvers and Backward Approximations.
Output Contract
fixed_point returns SolverResult:
| Field | Meaning |
|---|---|
z |
selected final or best equilibrium state |
states |
intermediate states requested by indexing |
residuals |
absolute or relative residual trace |
iterations, converged, solver |
numerical termination diagnostics |
info |
nonfinite termination and implicit backward diagnostics |
Tensor device and dtype follow the initial state z0.
solve_equilibrium returns the same SolverResult contract and records
result.info["backward_mode"] as "unrolled", "implicit", or "phantom".
gmres and implicit_adjoint_solve return LinearSolveResult, with the same
fields except that the solution field is named x.
Fixed-point and matrix-free linear solvers.
The fixed-point API follows the DEQ formulation of Bai, Kolter, and Koltun
(2019): a layer returns an equilibrium state z_star = f(z_star). Picard
iteration is the baseline fixed-point method, Anderson acceleration follows
Anderson (1965) and Walker and Ni (2011), Broyden follows Broyden's inverse
quasi-Newton update, and GMRES follows Saad and Schultz (1986) for the
matrix-free adjoint systems used in implicit-gradient diagnostics.
BroydenInverseEstimate
dataclass
Limited-memory approximation of the forward residual inverse.
Broyden solves g(z)=f(z)-z=0 and stores an approximation
The factors are detached numerical quantities. They can therefore be inspected, serialized, or reused as an adjoint preconditioner without retaining the forward autograd graph.
Source code in src/silva_networks/solvers.py
apply_fixed_point_adjoint_inverse
Approximate (I-J_f^T)^{-1} vector from the forward solve.
apply_residual_inverse
Apply the estimated inverse of J_f-I to vector.
Source code in src/silva_networks/solvers.py
apply_residual_inverse_transpose
Apply the transpose of the estimated inverse of J_f-I.
Source code in src/silva_networks/solvers.py
LinearSolveResult
dataclass
Output of a matrix-free linear solve.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Tensor
|
Linear-system solution tensor. |
residuals |
list[float]
|
Linear residual norms collected during iteration. |
iterations |
int
|
Number of Krylov iterations performed. |
converged |
bool
|
Whether the tolerance criterion was met. |
solver |
str
|
Solver name. |
Source code in src/silva_networks/solvers.py
SolverConfig
dataclass
Configuration for matrix-free fixed-point solvers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
SolverName
|
Fixed-point method: |
'picard'
|
max_iter
|
int
|
Maximum number of iterations. |
50
|
tol
|
float
|
Residual tolerance for convergence. |
1e-06
|
alpha
|
float
|
Damping factor used by Picard-style updates. |
1.0
|
history
|
int
|
Number of previous states used by Anderson acceleration or inverse updates retained by limited-memory Broyden. |
5
|
ridge
|
float
|
Ridge term in the Anderson least-squares system. |
0.0001
|
beta
|
float
|
Anderson mixing parameter. |
1.0
|
stop_mode
|
StopMode
|
Use an absolute residual or normalize by |
'absolute'
|
relative_eps
|
float
|
Positive stabilizer in the relative residual denominator. |
1e-08
|
anderson_batch_dims
|
int
|
Number of leading state dimensions that represent
independent Anderson solves. Use |
0
|
track_residuals
|
bool
|
If true, store residual norms in the result. |
True
|
reengage
|
bool
|
If true, trainable modules may apply one differentiable transition after a detached accelerated solve. |
True
|
backward_mode
|
BackwardMode
|
|
'unrolled'
|
backward_solver
|
BackwardSolverName
|
Matrix-free linear solver for implicit adjoints. |
'gmres'
|
backward_max_iter
|
int
|
Maximum number of backward linear-solver iterations. |
50
|
backward_tol
|
float
|
Residual tolerance for the backward linear solve. |
1e-06
|
backward_stop_mode
|
StopMode
|
Absolute or relative backward residual criterion. |
'absolute'
|
backward_relative_eps
|
float
|
Positive stabilizer for relative backward residuals. |
1e-08
|
phantom_steps
|
int
|
Number of differentiable refinement steps used by
|
1
|
phantom_tau
|
float
|
Damping used by phantom-gradient refinement steps. |
1.0
|
neumann_terms
|
int
|
Number of terms retained in the truncated Neumann approximation of the implicit adjoint. |
5
|
shine_refine_steps
|
int
|
Number of quasi-Newton refinement steps applied to
the forward Broyden inverse estimate in |
0
|
indexing
|
tuple[int, ...]
|
One-based solver iteration numbers whose states should be
retained in |
()
|
return_best
|
bool
|
Return the state with the lowest observed residual instead of the final iterate when the solver does not converge monotonically. |
False
|
Source code in src/silva_networks/solvers.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
SolverResult
dataclass
Output of a fixed-point solve.
Attributes:
| Name | Type | Description |
|---|---|---|
z |
Tensor
|
Final state tensor. |
residuals |
list[float]
|
Residual norms collected during iteration. |
iterations |
int
|
Number of iterations performed. |
converged |
bool
|
Whether the tolerance criterion was met. |
solver |
str
|
Solver name. |
info |
dict[str, float | int | str]
|
Optional extra scalar or string diagnostics. |
states |
list[Tensor]
|
Requested intermediate states, in |
inverse_estimate |
BroydenInverseEstimate | None
|
Limited-memory inverse retained by Broyden, when available. |
Source code in src/silva_networks/solvers.py
anderson
Anderson acceleration for vector-shaped states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[[Tensor], Tensor]
|
Transition map that accepts and returns tensors shaped like |
required |
z0
|
Tensor
|
Initial state. |
required |
config
|
SolverConfig | None
|
Optional solver configuration; |
None
|
Returns:
| Type | Description |
|---|---|
SolverResult
|
|
Source code in src/silva_networks/solvers.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
broyden
Limited-memory good-Broyden inverse update for fixed-point solves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[[Tensor], Tensor]
|
Transition map that accepts and returns tensors shaped like |
required |
z0
|
Tensor
|
Initial state. |
required |
config
|
SolverConfig | None
|
Optional solver configuration. |
None
|
Returns:
| Type | Description |
|---|---|
SolverResult
|
|
Source code in src/silva_networks/solvers.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
fixed_point
Dispatch to the configured fixed-point solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[[Tensor], Tensor]
|
Transition map. |
required |
z0
|
Tensor
|
Initial state. |
required |
config
|
SolverConfig | None
|
Solver configuration. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
SolverResult
|
|
Source code in src/silva_networks/solvers.py
gmres
Matrix-free GMRES for A x = b.
matvec must return A @ v with the same shape as v. The solver
materializes only the Arnoldi basis for the requested iteration budget, so
it is useful for small and medium implicit-adjoint diagnostics.
Source code in src/silva_networks/solvers.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 | |
implicit_adjoint_solve
implicit_adjoint_solve(f, z_star, grad_output, *, alpha=1.0, max_iter=50, tol=1e-06, solver='gmres', stop_mode='absolute', relative_eps=1e-08)
Solve the DEQ adjoint system with VJP-backed GMRES.
For the damped update T_alpha(z)=(1-alpha)z+alpha f(z), the adjoint
vector u solves
The returned u can be used with torch.autograd.grad to obtain
parameter sensitivities of the equilibrium map.
Source code in src/silva_networks/solvers.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 | |
picard
Damped Picard iteration for z = f(z).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[[Tensor], Tensor]
|
Transition map that accepts and returns tensors shaped like |
required |
z0
|
Tensor
|
Initial state. |
required |
config
|
SolverConfig | None
|
Optional solver configuration. |
None
|
Returns:
| Type | Description |
|---|---|
SolverResult
|
|
Source code in src/silva_networks/solvers.py
reengage_result
Reconnect a numerical fixed-point result to autograd when needed.
Anderson acceleration keeps its history detached for numerical stability and
memory control. Trainable modules can call this helper after fixed_point so
the returned state participates in ordinary PyTorch gradients without making
Picard or Broyden runs take an extra step.
Source code in src/silva_networks/solvers.py
shine_adjoint_solve
shine_adjoint_solve(f, z_star, grad_output, inverse_estimate, *, refine_steps=0, tol=1e-06, stop_mode='absolute', relative_eps=1e-08)
Reuse a forward Broyden inverse to approximate the DEQ adjoint.
The forward estimate approximates (J_f-I)^{-1}, so its negative
transpose approximates the inverse of the adjoint operator
A=I-J_f^T. Optional good-Broyden updates refine that shared estimate on
the linear residual A u-g while retaining only refine_steps rank-one
corrections.
Source code in src/silva_networks/solvers.py
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 | |
solve_equilibrium
Solve an equilibrium with the configured forward and backward mode.
backward_mode="unrolled" keeps the ordinary PyTorch finite-solver graph.
backward_mode="implicit" runs the forward fixed-point solve detached and
reconnects trainable sensitivities through the DEQ adjoint system
where T_alpha(z)=(1-alpha)z+alpha f(z). Pass module parameters through
params and differentiable non-state inputs through tensors when using
the implicit mode. backward_mode="phantom" instead performs a detached
solve followed by phantom_steps differentiable refinements with damping
phantom_tau; one step is the one-step-gradient special case. In
backward_mode="neumann", the forward root is detached and the adjoint
inverse is approximated by a finite Neumann series. In backward_mode="jfb",
the converged state is treated as a constant and one
final transition supplies the parameter gradient. In
backward_mode="shine", a Broyden forward solve shares its inverse estimate
with the adjoint and may refine it for shine_refine_steps iterations.
backward_map optionally separates the numerical forward approximation
from the equilibrium map used for implicit or phantom differentiation. It
is useful when the forward solve uses a source-compatible acceleration,
such as thresholded delta updates, while the derivative is defined by the
original equilibrium equation. Unrolled differentiation always follows
f directly.
Source code in src/silva_networks/solvers.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
Where to Go Next
| Question | Page |
|---|---|
| What mathematical problem do these solvers address? | Fixed Points |
| How is each update derived? | Solver Derivation Lab |
| Where is a solver checked against a closed form? | Scalar Equilibrium Example |