DEQ Engine API
The DEQ engine module provides a package-native convenience interface for single-state and multi-state fixed-point systems. It is inspired by the general DEQ interface style popularized by TorchDEQ, but it uses SILVA package solvers, configuration objects, and diagnostics. The relevant entries are DEQ [4], the general engine lineage [35], and SILVA [1].
For the source-to-package derivation and scope notes, see Method Adaptation Atlas.
Equations
For a single tensor state, the engine solves
For a multi-state system,
pack_state flattens the state tuple/list into one solver vector:
The packed transition is
and the solver computes
SILVAVariationalDropout reuses one dropout mask during a fixed-point solve:
The mask is reset with reset_silva_deq(model) before a new solve or training
step.
Multi-State Run
import torch
from silva_networks import SILVADEQConfig, silva_deq
x = torch.randn(2, 4)
initial = (torch.zeros(2, 6), torch.zeros(2, 3))
left_input = torch.nn.Linear(4, 6)
right_link = torch.nn.Linear(6, 3)
def transition(state):
left, right = state
return (
torch.tanh(left_input(x) + 0.2 * left),
torch.tanh(right_link(left) + 0.2 * right),
)
result = silva_deq(
transition,
initial,
config=SILVADEQConfig(forward_max_iter=20, forward_tol=1e-6),
params=(*left_input.parameters(), *right_link.parameters()),
tensors=(x,),
return_result=True,
)
assert result.state[0].shape == (2, 6)
assert result.state[1].shape == (2, 3)
print(result.solver_result.converged, result.solver_result.residual)
Tuple and list states are packed as one coupled vector, so their solver
configuration must use anderson_batch_dims=0.
Citation Map
| Object family | Cite |
|---|---|
| DEQ engine interface | SILVA package; TorchDEQ; Deep Equilibrium Models |
| fixed-point solvers | Anderson, Broyden, Picard, or GMRES according to the solver used |
| variational dropout in fixed-point solves | SILVA package and DEQ/TorchDEQ lineage when reported as a DEQ-engine practice |
Public Objects
| Object | Role |
|---|---|
SILVADEQConfig |
TorchDEQ-style configuration wrapper around package solver settings |
SILVADEQEngine |
fixed-point engine for tensor or tuple/list state |
SILVADEQEngineResult |
structured output with unpacked state and solver diagnostics |
SILVAVariationalDropout |
fixed-mask dropout module for solver calls |
silva_deq_config |
create SILVADEQConfig |
silva_deq_engine |
create SILVADEQEngine |
silva_deq |
solve one state or multi-state fixed point |
reset_silva_deq |
reset dropout masks in a module tree |
pack_state |
flatten tensor state structures into one solver vector |
unpack_state |
restore packed solver vectors into original state structures |
API Docs
SILVA DEQ engine utilities for single-state and multi-state systems.
This module provides a compact, package-native counterpart to the general DEQ interface popularized by TorchDEQ. It does not vendor TorchDEQ code. The design keeps the same mathematical contract:
but accepts either one tensor state or a tuple/list of tensor states. The engine
uses the package's SolverConfig and fixed_point implementations, so solver
choice, damping, tolerance, and iteration budget stay consistent with SILVA
layers.
References
- Silva, "SILVA Networks as Structured Implicit Layers and Vector Attractors via Dynamic Interaction Fields", 2026.
- Geng and Kolter, "TorchDEQ: A Library for Deep Equilibrium Models", GitHub repository, 2023.
- Bai, Kolter, and Koltun, "Deep Equilibrium Models", NeurIPS 2019.
SILVADEQConfig
dataclass
Configuration for SILVADEQEngine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
forward_solver
|
Literal['picard', 'anderson', 'broyden']
|
Solver used by the forward fixed-point solve. |
'anderson'
|
backward_mode
|
BackwardMode
|
Gradient estimator: finite unrolling, exact implicit differentiation, or phantom gradients. |
'unrolled'
|
backward_solver
|
Literal['picard', 'anderson', 'broyden', 'gmres']
|
Linear/fixed-point method for exact implicit adjoints. |
'gmres'
|
forward_max_iter
|
int
|
Maximum forward solver iterations. |
40
|
backward_max_iter
|
int
|
Maximum backward linear-solver iterations used by the implicit adjoint. |
40
|
forward_tol
|
float
|
Forward residual tolerance. |
0.0001
|
backward_tol
|
float
|
Backward residual tolerance. |
1e-06
|
backward_stop_mode
|
Literal['absolute', 'relative']
|
Absolute or relative backward residual criterion. |
'absolute'
|
backward_relative_eps
|
float
|
Stabilizer used by relative backward residuals. |
1e-08
|
alpha
|
float
|
Damping factor for the forward solve. |
0.7
|
history
|
int
|
Anderson history size. |
5
|
ridge
|
float
|
Anderson ridge term. |
0.0001
|
beta
|
float
|
Anderson mixing coefficient. |
1.0
|
eval_factor
|
float
|
Multiplier for the forward iteration budget in eval mode. |
1.0
|
track_residuals
|
bool
|
Whether to store residuals in |
True
|
reengage
|
bool
|
Whether to apply one differentiable transition after the numerical solve. This keeps gradients available when using detached acceleration history. |
True
|
stop_mode
|
Literal['absolute', 'relative']
|
Absolute or relative forward stopping criterion. |
'absolute'
|
relative_eps
|
float
|
Stabilizer used by relative residuals. |
1e-08
|
anderson_batch_dims
|
int
|
Number of independent leading batch dimensions for a single tensor state. Multi-state systems are packed as one coupled vector and therefore require zero. |
0
|
phantom_steps
|
int
|
Differentiable refinements for phantom gradients. |
1
|
phantom_tau
|
float
|
Damping for phantom-gradient refinements. |
1.0
|
indexing
|
tuple[int, ...]
|
One-based forward iterations retained for trajectory losses. |
()
|
return_best
|
bool
|
Return the lowest-residual forward state. |
False
|
Source code in src/silva_networks/deq_engine.py
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 | |
solver_config
Convert to the package's SolverConfig.
Source code in src/silva_networks/deq_engine.py
SILVADEQEngine
Bases: Module
General fixed-point engine for SILVA and DEQ-style modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SILVADEQConfig | SolverConfig | None
|
Engine configuration. A |
None
|
Inputs
transition: Callable mapping a state to a state with the same structure. init_state: Tensor, tuple of tensors, or list of tensors used as the solver initialization.
Output
Equilibrium state, or SILVADEQEngineResult when return_result=True.
Source code in src/silva_networks/deq_engine.py
solver_config
Return the active SolverConfig for the current training mode.
SILVADEQEngineResult
dataclass
Structured output from SILVADEQEngine.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
State
|
Equilibrium state with the same structure as the initial state. |
solver_result |
SolverResult
|
Underlying solver output on the packed tensor state. |
info |
dict[str, Any]
|
Small metadata dictionary containing state shapes and counts. |
Source code in src/silva_networks/deq_engine.py
SILVAVariationalDropout
Bases: Module
Variational dropout with a mask reused across solver calls.
This module follows the DEQ practice of keeping a fixed dropout mask during a fixed-point solve, avoiding a different random map at every solver step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dropout
|
float
|
Probability of dropping an element. |
0.5
|
channelwise
|
bool
|
If true for tensors with at least three dimensions, use a channelwise mask with singleton spatial dimensions. |
False
|
Inputs
x: Tensor of any shape.
Output
Tensor with the same shape as x.
Source code in src/silva_networks/deq_engine.py
pack_state
Flatten a tensor or tensor sequence into one solver vector.
Source code in src/silva_networks/deq_engine.py
reset_silva_deq
Reset variational dropout masks in a module tree.
This is the package-native counterpart to resetting DEQ-specific stochastic layers before a new fixed-point solve.
Source code in src/silva_networks/deq_engine.py
silva_deq
Solve a single-state or multi-state fixed point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transition
|
Callable[[State], State]
|
Callable mapping the state to the next state. The returned
state must have the same tensor structure as |
required |
init_state
|
State
|
Tensor, tuple of tensors, or list of tensors. |
required |
config
|
SILVADEQConfig | SolverConfig | None
|
Engine or solver configuration. |
None
|
params
|
Iterable[Tensor] | None
|
Trainable tensors used by a callable transition. Parameters are
inferred automatically when |
None
|
tensors
|
Iterable[Tensor]
|
Differentiable non-state inputs captured by the transition. |
()
|
return_result
|
bool
|
Whether to return diagnostics. |
False
|
Returns:
| Type | Description |
|---|---|
State | SILVADEQEngineResult
|
Equilibrium state, or |
Source code in src/silva_networks/deq_engine.py
silva_deq_config
silva_deq_engine
unpack_state
Unpack a solver vector using _StateSpec metadata.
Source code in src/silva_networks/deq_engine.py
Where to Go Next
| Question | Page |
|---|---|
| How does the engine connect to SILVA and optical flow? | DEQ Engine and Optical Flow |
| Where is a structured state executed? | DEQ Engine Bridge Example |
| How is the backward system solved? | Implicit Backward Guide |