Devices
SILVA Networks uses standard PyTorch device semantics.
The resolver returns CUDA when available, then MPS when available, otherwise CPU.
Tensor Placement
Every tensor participating in a forward pass should live on the same device:
Use move_to_device for nested dictionaries, tuples, and lists:
from silva_networks import move_to_device
batch = move_to_device(batch, device)
model = model.to(device)
Solvers allocate residual workspaces, identity matrices, and aggregation buffers on the device of the current state.
Operational Contract
This API surface connects device and dtype propagation to the same SILVA experiment contract used by the learning pages and notebooks. Its central relation is
| Part | What must remain inspectable |
|---|---|
| State | the same state layout on the selected device and floating dtype. |
| Condition | inputs, parameters, temporary tensors, solver history, and outputs must agree on device and dtype. |
| Diagnostic | shape, finite values, gradient availability, and residual. |
| Replacement point | the automatic device selection with an explicit device passed by the experiment runner. |
| Scale axes | batch size, precision, device count, and data-loader workers. |
The relevant method lineage is recorded in the SILVA construction [1] and implicit-layer foundation [4]. Those references define the source mechanisms; this API exposes them through SILVA objects so a reader can inspect, replace, solve, differentiate, and scale the construction.
Complete Compact Study
Run the complete repository program below from the project root. The page uses the same file that is exercised by the test suite, so the displayed call is not an isolated fragment.
from __future__ import annotations
import torch
from silva_networks import SILVAGraphLayer, SolverConfig, stability_report
def main() -> None:
torch.manual_seed(7)
x = torch.randn(8, 5)
y = (x[:, 0] + x[:, 1] > 0).long()
edge_index = torch.tensor(
[[0, 1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 0]],
dtype=torch.long,
)
layer = SILVAGraphLayer(5, 12, config=SolverConfig(max_iter=18, alpha=0.45))
head = torch.nn.Linear(12, 2)
z = layer(x, edge_index=edge_index)
loss = torch.nn.functional.cross_entropy(head(torch.tanh(z)), y)
loss.backward()
report = stability_report(lambda zz: layer.f(zz, x, edge_index=edge_index), z, samples=2, iters=10)
print("state_shape", tuple(z.shape))
print("loss", float(loss.detach()))
print("residual", report.residual)
print("spectral_radius", report.spectral_radius)
if __name__ == "__main__":
main()
Measured Compact Output
state_shape (8, 12)
loss 0.7801069021224976
residual 0.07725001126527786
spectral_radius 0.7778381109237671
Interpret the Output
The printed shape confirms the graph state contract, and the finite loss, residual, and spectral-radius estimate are computed on the same selected device. Device equivalence still requires a separate CPU/accelerator comparison with fixed seeds.
For a controlled experiment, retain the compact call as a regression case and change one scale axis at a time. Record the resolved constructor, data source and split, preprocessing, seed, forward and backward solver settings, task metric, normalized residual, iteration count, runtime, peak memory, and any failed convergence case. A larger run becomes evidence only when its own resolved configuration and outputs are archived; the compact output above is evidence for the executable mechanism and its stated invariants.
available_devices
Return the PyTorch device backends currently available.
Source code in src/silva_networks/device.py
module_device
Return the first parameter or buffer device for a module.
Source code in src/silva_networks/device.py
move_to_device
Recursively move tensors in common batch containers to a device.
Source code in src/silva_networks/device.py
resolve_device
Resolve "auto", "cuda", "mps", or "cpu" to a PyTorch device.
Source code in src/silva_networks/device.py
Where to Go Next
| Question | Page |
|---|---|
| How are several points placed across devices? | Stacking and Devices |
| Which optional backends can be installed? | Installation |
| Which model containers use these helpers? | Architectures API |