Implementation Derivations
This page is the traceability layer between the SILVA equations, the SILVA paper families, and the package implementation. It is written for readers who need to audit, extend, or cite the implementation rather than only run examples.
Pair this page with the Research Citation Audit when preparing a paper, README, model card, or experiment report.
Citation Trace
| Implementation family | Package surface | Primary references to cite |
|---|---|---|
| fixed-point layer | fixed_point, DEQLayer, SILVALayer, presets |
SILVA paper/package [1] [2]; Bai et al., DEQ [4] |
| implicit gradients | implicit_adjoint_solve, VJP/JVP helpers |
Deep Implicit Layers tutorial [3]; DEQ [4] |
| Anderson solver | anderson |
Anderson, 1965 [10]; Walker-Ni, 2011 [11] |
| Broyden solver | broyden |
Broyden, 1965 [12] |
| GMRES adjoint solve | gmres, LinearSolveResult |
Saad-Schultz, 1986 [13] |
| graph local terms | GraphLocal, GraphAttentionLocal |
Kipf-Welling GCN [15]; Velickovic et al. GAT [16]; Gilmer et al. MPNN [17] |
| global set/attention terms | MeanFieldGlobal, TopKGlobalAttention, channel attention |
Deep Sets [18], Attention [29], Set Transformer [19] |
| dynamic kNN local terms | TopKLocal, DynamicChannelLocal, dataset kNN graph builders |
Wang et al., Dynamic Graph CNN [20]; SILVA for hidden-channel adaptation [1] |
| Jacobian penalty | hutchinson_jacobian_norm, jacobian_regularization_loss |
Hutchinson, 1989 [14]; Bai et al., Jacobian-regularized DEQ [6] |
| implicit bridge | SILVAFixedPointBlock, SILVAEulerFlowBlock, SILVAQuadraticOptimizationLayer, SILVAMultiscaleDEQBlock |
DEQ [4], Neural ODEs [7], OptNet [8], differentiable convex optimization layers [9], MDEQ [5] |
| scientific operators | SILVAImplicitTimeStep, SILVAOperatorModel, SILVAFourierNeuralOperator, finite-difference and residual helpers |
Neural ODEs [7], FNO [31], neural operators [32], SILVA [1] |
| input-injected Fourier equilibrium | SILVAFNODEQBlock, SILVAFNODEQ |
FNO-DEQ [43], FNO [31], SILVA [1] |
| physics-guided graph equilibrium | graph_convection_diffusion, SILVAGraphConvectionDiffusion, SILVAPhysicsGuidedGraphDEQ |
physics-guided graph DEQ [44], graph convolution [15], SILVA [1] |
| continuous residual path | SILVAHomotopyTransition, SILVAHomotopyEquilibrium |
HomoODE [46], Neural ODEs [7], SILVA [1] |
| empirical-measure equilibrium | distributional_discrepancy, SILVADistributionalTransition, SILVADistributionalDEQ |
DDEQ [45], SILVA [1] |
| DEQ engine | SILVADEQEngine, silva_deq, pack_state, SILVAVariationalDropout |
SILVA package [2], TorchDEQ [35], DEQ [4] |
| SILVA DEQ flow | SILVADEQFlow, flow warp, all-pairs correlation |
RAFT [22], DEQ-Flow [23], SILVA package [2] |
Reading Contract
Every SILVA equilibrium layer exposes three levels of meaning:
| Level | Mathematical object | Package surface |
|---|---|---|
| Transition | \(z \mapsto f_\theta(z,x)\) | layer.f(...), custom transition callable |
| Solver | \(z_{k+1}=T(z_k)\) until \(\|f(z_k)-z_k\|\le\varepsilon\) | fixed_point, SolverConfig, SolverResult |
| Model | equilibrium state plus readout | SILVAStack, SILVAGraphNetwork, preset classifiers/regressors |
The core contract is shape preservation:
For entity and graph layers,
For vector vision layers,
For convolutional image layers,
Universal Fixed-Point Form
All implemented families reduce to
The convergence check recorded in SolverResult.residuals is
The default zero initialization in the package is not part of the mathematical definition; it is an implementation convention:
unless z0 is supplied by the caller. Warm starts, learned starts, or
continuation states are valid as long as they have the same shape as the
equilibrium state.
Generic SILVALayer
The implementation in SILVALayer.f computes
then adds self, local, and global terms:
The returned transition is
when normalize=True, and \(\tanh(u)\) otherwise. In code:
s = self.stimulus(x)
y = self.activation(z)
self_update = self.self_term(y, ...)
local = self.local(y, ...)
global_context = self.global_term(y, ...)
return self.norm(self.output_activation(s + self_update + local + global_context))
The keyword dispatcher passes only the arguments a branch accepts. This lets a custom branch be as small as
or as context-aware as
without changing the solver.
Generic Branch Conditions
A branch is compatible when it is shape-preserving:
The branch may be zero, identity, linear, graph-local, attention-based, or a
user module. What matters for the fixed-point solver is that the full
transition returns a tensor shaped like z0.
Graph Preset Layer
SILVAGraphPresetLayer uses the reference graph form
The SILVA layer intentionally omits the generic learned self branch. State persistence comes from the damped solver:
When local_depth > 1, the local branch is tied inside one solver step:
for intermediate hops, with the final local term \(h^{(D)}\). This gives a controlled way to increase graph mixing without adding another equilibrium layer.
Mean Graph Local Branch
GraphLocal projects every source state and averages incoming messages. For
edges \(j\to i\),
The implementation uses index_add_ on the destination indices. This is
permutation-equivariant: if node order is permuted and edge_index is permuted
consistently, the output is permuted the same way.
If edge_index is None, GraphLocal returns the projected state when
self_loop_when_empty=True; otherwise it returns zeros. This matters when using
generic entity sets without graph structure.
Graph Attention Local Branch
GraphAttentionLocal implements pure-PyTorch multi-head graph attention over
edge_index. With \(H\) heads and head width \(d_h/H\), the projected state is
For each directed edge \(j\to i\),
If edge attributes are present,
After LeakyReLU, normalization is destination-segment softmax:
The head output is
When concat=True, heads are concatenated. When concat=False, heads are
averaged and projected back to the state dimension.
Top-k Local Branch
TopKLocal builds a dynamic nearest-neighbor graph from the current state. For
entity \(i\),
The local term is
This branch is state-dependent: changing \(z_k\) can change the neighborhood used at the next solver step. It is useful for entity sets and hidden-channel vision cases where no fixed graph is supplied.
Global Mean and Gated Mean
MeanFieldGlobal pools one mean state per graph:
It broadcasts the projection
GatedMeanFieldGlobal adds a scalar graph gate:
The batch tensor is therefore not an input feature; it is a segmentation operator that prevents graph-level context from leaking across examples in a minibatch.
Top-k Global Attention
TopKGlobalAttention computes bounded dense attention inside each graph. For
each receiver \(i\),
Only the top \(k\) source indices are kept:
Then
This gives a global branch with work \(O(Nkd_h)\) after score construction, rather than using every source in the final weighted sum.
Vector Vision Layers
SILVAVisionVectorLayer treats hidden channels as interacting entities inside
each sample. The state shape is
The transition is intentionally raw-sum rather than LayerNorm(ReLU(...)):
The dynamic channel local branch forms k-nearest neighbors among channel values within each sample:
symmetrizes the channel adjacency, and averages projected channel states by degree. This is the implemented hidden-channel interaction graph.
The single-head channel global branch forms
The multi-head variant computes an intermediate attended representation and then builds a dense channel attention matrix from the mixed vector.
Convolutional Vision Classifier
SILVAConvVisionClassifier factors image processing into
The convolutional stem is not itself an equilibrium. It is a feature extractor:
The equilibrium dynamics happen after the stem in the vector SILVA core.
Molecular SILVA
SILVAMolecularLayer is a bond-aware graph equilibrium. Atom and bond features
are first embedded or projected to the hidden width. Inside each molecular
layer,
where \(L_\theta\) is edge-aware graph attention using bond attributes. The global molecule context is
The transition is
When spectral normalization is enabled, the stimulus and global projections are
constrained by torch.nn.utils.spectral_norm. This is an implementation-level
stabilizer, not a proof of global contraction.
Stacked Equilibrium Models
SILVAStack composes equilibrium layers:
Graph preset and molecular networks often pass
as the next layer input. Each layer has its own SolverConfig, so a fast/slow
hierarchy is represented by different damping values:
or by an arbitrary stack_alphas sequence.
Readouts and Pooling
For node tasks, the readout is applied per entity:
For graph tasks, states are pooled first:
Implemented pooling modes are
Picard Solver
The package records residuals before applying the next damped step:
The update is
Convergence is declared when
Best practice: lower alpha when residuals oscillate, increase max_iter only
after checking whether the residual curve is still decreasing, and inspect
result.converged rather than assuming the last iterate is an equilibrium.
Anderson Solver
Anderson acceleration stores recent states and transition outputs:
Residual columns are
The coefficients solve the ridge-regularized constrained least-squares problem
The implemented KKT system is
The mixed output is
and the final update is
Implementation note: stored states and transition outputs are detached. This makes the solver practical for documentation examples and finite-step training, while implicit-gradient diagnostics are handled separately.
Broyden Solver
The package uses the root form
It stores a dense inverse-Jacobian approximation \(B_k\), initialized as
The step is
Because \(B_0=-I\), the first Broyden step matches the damped residual direction:
With
the inverse secant condition is
The implemented good-Broyden update is
Because the implementation materializes a dense \(n\times n\) inverse estimate for \(n=\operatorname{numel}(z)\), it is best for small states and controlled diagnostic experiments.
GMRES and Implicit Adjoints
For an equilibrium \(z^\star\), define
Implicit differentiation gives
For the executed damped update
the diagnostic adjoint solve in the package uses
Since
the linear operator is
implicit_adjoint_solve applies this operator with VJP calls and solves the
matrix-free system using GMRES.
GMRES builds an Arnoldi basis \(V_m\) and upper Hessenberg matrix \(H_m\):
At iteration \(m\), it solves
The package exposes the residual history in LinearSolveResult.residuals.
Jacobian Diagnostics
For small states, full_jacobian materializes
For larger states, use products:
The spectral-radius estimator runs power iteration on VJP products:
damped_spectral_radius(f, z_star, alpha) estimates
The Hutchinson Frobenius estimator uses Rademacher probes \(v\):
This is why hutchinson_jacobian_norm can estimate a norm without storing the
full Jacobian.
Energy Diagnostics
The package's quadratic interaction energy is
For a local plus global interaction \(h_i=L_i+G_i\), lower energy means the state aligns more strongly with the interaction field under this diagnostic. It is a monitoring quantity:
is evidence of descent for the chosen trace, but it is not by itself a Lyapunov proof unless the user's model assumptions justify it.
solve_with_energy evaluates the energy function before each fixed-point
transition and returns:
| Quantity | Meaning |
|---|---|
result |
final SolverResult |
energies |
per-iteration diagnostic energy |
energy_deltas |
\(E_{k+1}-E_k\) |
stability |
optional local Jacobian report |
Implicit Bridge Formula Map
The silva_networks.implicit module keeps tutorial implicit-layer models inside
the package solver and Jacobian APIs. These modules are deliberately compact,
but each one corresponds to a standard implicit-learning case.
Affine-Tanh DEQ Transition
DEQMLPTransition implements
with default \(\phi=\tanh\). The fixed-point block solves
using the package update
Because
a simple sufficient local contraction condition is
For tanh, \(|\phi'|\le 1\), so controlling the recurrent spectral norm gives the conservative check
DEQMLPTransition.project_state_weight(max_norm) applies this tutorial-scale
initialization guard to the recurrent matrix.
TanhFixedPointClassifier adds a readout
where \(D\) is dropout or the identity.
Use the DEQ paper and Deep Implicit Layers tutorial when citing this bridge case. Use the SILVA package citation when using the package-native classes or SILVA-named factories.
Explicit Euler ODE Bridge
ExplicitEulerODEBlock is not an equilibrium solver. It is included to show how
continuous-depth intuition relates to repeated state updates. Starting from
explicit Euler gives
After \(K\) steps,
The same state-space thinking appears in equilibrium models, but a DEQ solves for a stationary state while the Euler block returns the terminal state of a finite trajectory.
Use Neural ODEs when citing the continuous-depth model and the Deep Implicit Layers tutorial when citing this bridge in the implicit-layer context.
Implicit ODE/PDE and Operator Implementation
SILVAImplicitTimeStep represents a backward-Euler step for a semidiscrete
right-hand side \(R_h\):
Its source-level transition is equivalent to
The implementation checks that rhs preserves the state shape, applies the
projector on every transition evaluation, and calls solve_equilibrium with
the module parameters and differentiable context tensors. Therefore
SolverConfig.backward_mode has the same meaning as it does for other SILVA
points.
The numerical helpers expose the centered formulas directly. In one dimension,
In two dimensions,
SILVAReactionDiffusionRHS2D computes
and SILVABurgersRHS1D computes
Both accept an optional state-shaped context and return the state shape.
Boundary projection is separate through SILVADirichletBoundary2D, so the
discretization and constraint can be tested independently.
SILVAOperatorModel constructs the learned function map from existing
abstractions:
Conv2d(in_channels, state_channels, 1)lifts the sampled input;- a built-in spatial point architecture or supplied module defines the state-dependent field;
SILVACortexLayercomposes optional self, local, global, and interaction fields and solves the equilibrium;- a readout maps the equilibrium state to
out_channels; - an optional output transform applies a boundary mask or physical projection.
The input and output contract is
SILVAFourierNeuralOperator selects the Fourier point architecture, whose
state field is
The full SILVAOperatorOutput contains the decoded output, equilibrium state,
and SolverResult. Physical diagnostics remain separate:
This separation prevents a low solver residual from being reported as evidence that the governing equation or boundary condition is satisfied.
Quadratic Optimization Layer
QuadraticOptimizationLayer forms
with \(\lambda>0\), so \(A\) is symmetric positive definite. The layer's objective is
The first-order condition is
Thus the exact optimizer is
The package also exposes the equivalent gradient-descent fixed-point map
For this quadratic case, the fixed-point iteration converges when
This is a useful bridge from differentiable optimization layers to SILVA-style fixed-point solvers: the implicit state is defined by an equation rather than by a fixed number of explicit neural layers.
Use OptNet or differentiable convex optimization layers when citing the optimization-layer perspective. Use the SILVA citation for this package's quadratic tutorial implementation.
Toy Multiscale DEQ
ToyMultiscaleDEQBlock splits the state into low- and high-resolution parts,
Its transition is
The joint equilibrium is therefore
This compact module mirrors the multiscale DEQ idea: several feature scales are coupled and solved together.
Use Multiscale Deep Equilibrium Models when citing the coupled-scale equilibrium idea.
Jacobian Regularization and Residual Ratio
jacobian_regularization_loss adds a stability penalty of the form
The package estimates the Frobenius norm with Hutchinson probes:
residual_ratio reports
Values below one indicate that the numerical solve reduced the residual; values near zero indicate a strong solve relative to the initial state.
Use Hutchinson's trace estimator for the stochastic norm estimate and Jacobian-regularized DEQs for the DEQ stability-regularization objective.
Bridge Case Summary
| Module | Equation class | Package behavior |
|---|---|---|
DEQMLPTransition |
affine nonlinear fixed point | defines \(f_\theta(z,x)\) |
TanhFixedPointBlock |
vector DEQ solve | calls fixed_point and returns \(z^\star\) |
TanhFixedPointClassifier |
DEQ representation plus readout | maps \(z^\star\) to logits |
ExplicitEulerODEBlock |
finite explicit trajectory | returns \(h_K\), optionally with the trajectory |
SILVAImplicitTimeStep |
backward-Euler ODE/PDE point | returns \(u^{n+1}\) or a SolverResult |
SILVAOperatorModel |
learned sampled function map | returns a decoded field or SILVAOperatorOutput |
SILVAFourierNeuralOperator |
Fourier field inside a SILVA point | reuses spectral parameters across compatible grid sizes |
QuadraticOptimizationLayer |
implicit argmin / KKT equation | solves \(Az=b_\theta(x)\) by fixed-point iteration or exact solve |
ToyMultiscaleDEQBlock |
coupled multiscale fixed point | solves \((z_\ell^\star,z_h^\star)\) jointly |
jacobian_regularization_loss |
VJP-based stability penalty | estimates \(\|J_f\|_F^2\) |
residual_ratio |
residual trace summary | compresses solver progress into one diagnostic |
General DEQ Engine Formula Map
The silva_networks.deq_engine module exposes a package-native DEQ interface
for one tensor state or a tuple/list of tensor states. This is useful for
models whose equilibrium state has several coupled components.
For a multi-state transition,
the equilibrium equation is
pack_state converts the state into one solver vector:
The engine solves the packed fixed point
After solving, unpack_state returns
When reengage=True, the engine evaluates one more differentiable transition:
and stores the packed result back into solver_result.z. This mirrors the
package's compact bridge modules: acceleration history can be numerical, while
the final returned state remains connected to PyTorch autograd.
SILVAVariationalDropout uses one mask during a solve:
The mask is intentionally reusable across solver calls until reset, avoiding a different stochastic transition at every fixed-point iteration.
Optical Flow Formula Map
The silva_networks.flow module is a compact RAFT/DEQ-Flow-inspired validation
case implemented with SILVA solvers.
For a pixel
and a flow field
silva_flow_warp samples the source tensor at
Feature maps
produce the all-pairs correlation volume
The local lookup samples the neighborhood
The update block predicts an increment from the current flow, image features, warped features, residual features, and local correlations:
The transition is
SILVADEQFlow solves
Endpoint error is
With a validity mask \(M\), the mean EPE is
The first-order smoothness penalty is
Use RAFT for the all-pairs correlation and recurrent refinement lineage, and DEQ-Flow when citing the optical-flow equilibrium framing.
Tensor Contracts
| Case | Required tensors | Shape contract |
|---|---|---|
| Generic entity | x, optional edge_index, edge_attr, batch |
x: (entities, in_dim) |
| Graph/node | x, edge_index, optional batch |
edge_index: (2, edges) |
| Graph-level | x, edge_index, batch |
pooled by graph id |
| Vision vector | image vectors or flattened tensors | internal state (batch, hidden_dim) |
| Conv vision | x |
(batch, channels, height, width) |
| Molecular | x, edge_index, edge_attr, batch |
atom and bond tensors segmented by molecule |
| Implicit bridge vector | x, optional z0 |
x: (batch, in_dim), state (batch, state_dim) |
| Implicit bridge multiscale | x, optional z0 |
concatenated state (batch, low_dim + high_dim) |
| General DEQ engine | tensor, tuple, or list state | each component is packed into one solver vector |
| Optical flow | image1, image2, optional flow0 |
images (batch, channels, height, width), flow (batch, 2, height, width) |
Validation best practices:
- Confirm the transition returns the same shape as
z0. - Confirm
edge_index[0]are sources andedge_index[1]are destinations. - Confirm
batchis present for multiple graphs or molecules. - Confirm
edge_attr.shape[0] == edge_index.shape[1]when edge attributes are used. - Request
return_result=Trueorreturn_results=Trueduring development.
Professional Reporting Checklist
When reporting a SILVA experiment, include:
| Item | Why it matters |
|---|---|
| layer family | generic, graph, vector vision, conv vision, molecular |
| local/global/self branches | identifies the implemented \(L,G,H\) terms |
solver and alpha |
defines the executed dynamics |
max_iter, tol, convergence rate |
separates approximation quality from model accuracy |
| residual summary | shows whether the equilibrium was actually reached |
| Jacobian or spectral-radius diagnostic | local stability evidence |
| dataset adapter and tensor shapes | reproducibility and batching correctness |
| readout and pooling | distinguishes node, graph, image, and molecule outputs |
Common Failure Modes
| Symptom | Likely cause | Check |
|---|---|---|
| residual plateaus | transition is not locally contractive, alpha too high, normalization mismatch |
lower alpha, inspect result.residuals, estimate damped spectral radius |
| residual oscillates | damped map has eigenvalues near or below \(-1\) | reduce alpha, try Anderson with ridge |
| graph output changes under node reorder | edge_index or batch not permuted consistently |
validate data adapter |
| molecules mix context | missing or wrong batch |
inspect molecule ids and pooled count |
| Jacobian computation is slow | full materialization on a large state | use vjp, jvp, Hutchinson, or spectral-radius estimates |
| energy decreases but residual is high | diagnostic alignment improved but fixed point not solved | report both energy and residual |
Where to Go Next
| Question | Page |
|---|---|
| Where is the fixed-point mathematics developed from first principles? | Mathematical Foundations |
| How are the supported scientific cases organized? | Case Atlas |
| Where can I execute the implicit-layer derivations? | Implicit Layers Bridge |
| Which package signatures implement these equations? | API Reference |