Architectures
The architecture helpers are ordinary torch.nn.Module classes built from
SILVA equilibrium layers. They expose the same knobs that appear in an
experiment: state width, number of layers, local operator, global operator,
optional learned self term, solver family, solver parameters, readout head, task
mode, pooling rule, and device placement.
The stacked equilibrium interpretation follows DEQ [4]; multiscale stacks connect to MDEQ [5], and graph/set readouts use the corresponding graph and invariant-set sources [15] [18].
Stack Recurrence
For a stack with \(K\) equilibrium layers, define
Layer \(k\) solves
then passes
to the next layer. A scalar hidden_dims=64 repeats the same state dimension in
each layer. A list such as hidden_dims=[64, 48, 32] gives each layer its own
width.
from silva_networks import SILVAStack, SolverConfig
stack = SILVAStack(
in_dim=8,
hidden_dims=[32, 32, 16],
config=[
SolverConfig(solver="picard", max_iter=10, alpha=0.5),
SolverConfig(solver="anderson", max_iter=10, alpha=0.4, history=4, ridge=1e-4),
SolverConfig(solver="broyden", max_iter=6, alpha=0.3),
],
local=["graph", "topk", "graph_attention"],
local_kwargs=[None, {"k": 8}, {"heads": 2}],
global_term=["mean", "simple", "topk_attention"],
global_kwargs=[None, None, {"k": 12}],
self_term=[None, "linear", None],
)
When config is a single SolverConfig, the same solver settings are reused in
every layer. When config is a list, each layer receives its own solver family
and parameters.
The same rule applies to operator kwargs. A single dictionary is reused for
every built-in operator. A list such as [None, {"k": 8}, {"heads": 2}]
passes settings to each layer separately.
Control Surface
| Control | Argument | Typical values |
|---|---|---|
| Input width | in_dim |
Feature columns, node features, stem output width |
| State width | hidden_dims |
64, [64, 64], [128, 64, 32] |
| Stack depth | num_layers or len(hidden_dims) |
One layer through deep multistacks |
| Local structure | local |
"graph", "gat", "topk", custom nn.Module |
| Global context | global_term |
"mean", "simple", "topk_attention", custom nn.Module |
| Learned self branch | self_term |
None, "linear", "identity", custom nn.Module |
| Solver | config.solver |
"picard", "anderson", "broyden" |
| Solver damping | config.alpha |
One scalar per layer |
| Solver budget | config.max_iter, config.tol |
Iteration cap and residual tolerance |
| Anderson controls | config.history, config.ridge, config.beta |
Memory, regularization, mixing |
| Graph edges | edge_index |
Shape (2, edges) |
| Edge features | edge_attr |
Shape (edges, edge_dim) for edge-aware custom or GAT branches |
| Minibatch grouping | batch |
Shape (entities,) |
| Prediction mode | task, pooling |
Node prediction or graph prediction |
| Readout capacity | head_hidden_dims, dropout |
MLP head depth and regularization |
Strings select built-in operators. Lists select one operator per layer.
Factories receive (dim, index) when they accept two positional arguments, so a
stack can create width-specific modules automatically:
import torch
from silva_networks import SILVAGraphNetwork
class SignedLocal(torch.nn.Module):
def __init__(self, dim: int, sign: float):
super().__init__()
self.sign = sign
self.proj = torch.nn.Linear(dim, dim, bias=False)
def forward(self, z, edge_index=None, edge_attr=None):
return self.sign * torch.tanh(self.proj(z))
model = SILVAGraphNetwork(
in_dim=12,
hidden_dims=[64, 48, 32],
out_dim=5,
local=lambda dim, index: SignedLocal(dim, sign=(-1.0) ** index),
global_term="simple",
)
Cortex Composition
SILVACortexLayer exposes a more general composition point than SILVAStack.
It is designed for SILVA cortex hierarchies and for user-defined
architectures where a single equilibrium point contains several trainable
submodules.
One cortex point computes
The damped solver step is
Several cortex points can be linked:
from silva_networks import SILVACortexLayer, SILVACortexNetwork, SolverConfig
layer1 = SILVACortexLayer(
input_dim=5,
state_dim=14,
state_network=torch.nn.Sequential(
torch.nn.Linear(14, 14),
torch.nn.Tanh(),
torch.nn.Linear(14, 14),
),
config=SolverConfig(solver="picard", alpha=0.5, max_iter=10),
)
layer2 = SILVACortexLayer(
input_encoder=torch.nn.Linear(14, 10),
state_dim=10,
state_network=torch.nn.Sequential(
torch.nn.Linear(10, 20),
torch.nn.GELU(),
torch.nn.Linear(20, 10),
),
config=SolverConfig(solver="anderson", alpha=0.2, max_iter=10, history=3),
normalize=False,
)
model = SILVACortexNetwork([layer1, layer2], links="tanh", head=torch.nn.Linear(10, 2))
Custom modules may accept z, stimulus, x, edge_index, edge_attr, or
batch. Only the supported arguments are passed to each module. This keeps
ordinary PyTorch modules usable while still allowing graph-aware and
context-aware interaction branches.
The internal modules may be MLPs, convolutions, residual networks, U-Nets, attention blocks, or graph modules. Intermediate representations may change shape, but the completed transition must return exactly the equilibrium-state shape. Interaction fields may broadcast into that shape. A shape mismatch raises an error naming the responsible transition or branch before the solver continues.
Use normalizer=torch.nn.GroupNorm(...) for (batch, channels, height, width)
states. The default LayerNorm(state_dim) is intended for states whose final
dimension is the feature width.
Graph Readout
For graph-level prediction, entity states are pooled:
The readout head maps \(h_g\) to logits or regression outputs:
For node-level prediction, the readout is applied to every node state:
The pooling mode can be "mean", "sum", or "max". A custom readout can be
attached by replacing model.head with any PyTorch module whose input width
matches the final equilibrium state.
Reference Stacks
SILVAGraphPresetNetwork, SILVAVisionVectorClassifier,
SILVAConvVisionClassifier, and SILVAMolecularRegressor keep the SILVA paper
defaults available through direct constructor arguments:
from silva_networks import SILVAGraphPresetNetwork
model = SILVAGraphPresetNetwork(
in_dim=dataset_num_features,
hidden_dim=[64, 48],
out_dim=num_classes,
task="node",
attention_mode="simple",
graph_mode="GAT",
num_heads=4,
k_neighbors=16,
local_depth=2,
stack_alphas=[0.5, 0.2],
max_iter=15,
solver="picard",
)
The same pattern works for molecules. Categorical atom and bond ids are embedded
directly. Continuous features can be projected with atom_feature_dim and
bond_feature_dim:
from silva_networks import SILVAMolecularRegressor
model = SILVAMolecularRegressor(
hidden_dim=[128, 64],
atom_feature_dim=9,
bond_feature_dim=4,
num_heads=4,
alphas=(0.5, 0.2),
max_iter=20,
)
Device Contract
Move the model and all tensors to the same device:
from silva_networks import move_to_device, resolve_device
device = resolve_device("auto")
model = model.to(device)
batch = move_to_device(batch, device)
Internal tensors created by solvers and layers follow the input state's device and dtype. CUDA, MPS, and CPU use the same public API; the installed PyTorch wheel determines which accelerators are available.
SILVACortexLayer
Bases: Module
Flexible SILVA equilibrium point with arbitrary internal modules.
A cortex layer first encodes the incoming object into a stimulus tensor,
then solves one equilibrium point
The state_network term \(B_\theta\) may be a deep nn.Sequential or a
list of modules. The interaction terms may be local, global, self, or any
user-defined PyTorch modules. This covers the SILVA cortex hierarchy:
a convolutional or linear front end, a fast first equilibrium point, a
slower second equilibrium point, and different internal transition
architectures at each point.
Reference: Jose Luis Silva, "SILVA Networks as Structured Implicit Layers and Vector Attractors via Dynamic Interaction Fields", arXiv:2607.28989.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
int | None
|
Input width for the default linear encoder. |
None
|
state_dim
|
int | None
|
State width. Required when |
None
|
input_encoder
|
Module | None
|
Module mapping the incoming tensor to the recurrent
state shape. If omitted, |
None
|
state_network
|
CortexModuleSpec
|
Module or sequence applied to the activated state inside each solver step. |
None
|
self_terms
|
CortexModuleSpec
|
Modules added as self-interaction branches. |
None
|
local_terms
|
CortexModuleSpec
|
Modules added as local interaction branches. |
None
|
global_terms
|
CortexModuleSpec
|
Modules added as global interaction branches. |
None
|
interaction_terms
|
CortexModuleSpec
|
Additional state-shaped interaction branches. |
None
|
output_network
|
Module | None
|
Optional module applied after summing the stimulus and interactions and before the outer activation. |
None
|
normalizer
|
Module | None
|
Optional normalization module. If omitted and
|
None
|
config
|
SolverConfig | None
|
Fixed-point solver configuration. |
None
|
activation
|
Callable[[Tensor], Tensor]
|
State activation \(a\) applied before interactions. |
tanh
|
output_activation
|
Callable[[Tensor], Tensor]
|
Outer nonlinearity \(\Psi\). |
tanh
|
initializer
|
CortexInitializer
|
|
'zeros'
|
Source code in src/silva_networks/architectures.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 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 | |
encode
f
Evaluate the undamped cortex transition.
Source code in src/silva_networks/architectures.py
initial_state
Return the initial solver state.
Source code in src/silva_networks/architectures.py
SILVACortexNetwork
Bases: Module
Link several SILVACortexLayer equilibrium points in one PyTorch model.
Each layer may have its own encoder, internal transition network,
interaction terms, and solver configuration. The link between equilibrium
points is configurable; the SILVA fast/slow hierarchy uses
links="tanh" with different SolverConfig.alpha values per layer.
Source code in src/silva_networks/architectures.py
SILVACortexOutput
dataclass
Structured output for linked cortex-style equilibrium points.
Attributes:
| Name | Type | Description |
|---|---|---|
output |
Tensor
|
Final tensor after the optional readout head. |
state |
Tensor
|
Final equilibrium state. |
states |
list[Tensor]
|
Equilibrium state produced by each cortex point. |
solver_results |
list[SolverResult]
|
Solver metadata for each cortex point. |
Source code in src/silva_networks/architectures.py
SILVAGraphNetwork
Bases: Module
End-to-end graph or node model built from a SILVA stack and readout head.
Source code in src/silva_networks/architectures.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 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 | |
SILVAImageClassifier
Bases: Module
Image classifier using one or more SILVA image equilibrium layers.
Source code in src/silva_networks/architectures.py
SILVANetworkOutput
dataclass
Optional structured output for models that expose equilibrium states.
Source code in src/silva_networks/architectures.py
SILVAStack
Bases: Module
Stack multiple trainable SILVA equilibrium layers.
Source code in src/silva_networks/architectures.py
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
build_mlp_head
Build a small readout head for node, graph, or image representations.
Source code in src/silva_networks/architectures.py
pool_entities
Pool entity states into graph-level or set-level states.
Source code in src/silva_networks/architectures.py
silva_cortex_layer
Create a flexible cortex-style SILVA equilibrium point.
Source code in src/silva_networks/architectures.py
silva_cortex_network
Create a linked hierarchy of cortex-style equilibrium points.
Where to Go Next
| Question | Page |
|---|---|
| How are linked points derived? | Cortex Hierarchies |
| Where is a hierarchy executed? | Cortex Hierarchy Example |
| Which objects define an individual point? | Layers API |