MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / capture_layer_snapshots

Function capture_layer_snapshots

training/mlp_train.py:136–156  ·  view source on GitHub ↗

Capture the current dense-layer parameters for export.

(model: SmallMLP, activations: Sequence[str])

Source from the content-addressed store, hash-verified

134
135
136def capture_layer_snapshots(model: SmallMLP, activations: Sequence[str]) -> list[LayerSnapshot]:
137 """Capture the current dense-layer parameters for export."""
138 dense_layers = [m for m in model.net if isinstance(m, nn.Linear)]
139 snapshots: list[LayerSnapshot] = []
140 for idx, (layer, activation) in enumerate(zip(dense_layers, activations, strict=False)):
141 metadata = LayerMetadata(
142 layer_index=idx,
143 type="dense",
144 name=f"dense_{idx}",
145 activation=activation,
146 weight_shape=tuple(int(dim) for dim in layer.weight.shape),
147 bias_shape=tuple(int(dim) for dim in layer.bias.shape),
148 )
149 snapshots.append(
150 LayerSnapshot(
151 metadata=metadata,
152 weight=layer.weight.detach().cpu(),
153 bias=layer.bias.detach().cpu(),
154 )
155 )
156 return snapshots
157
158
159def build_network_payload(layers: Sequence[LayerMetadata]) -> dict[str, Any]:

Callers 1

record_snapshotFunction · 0.85

Calls 2

LayerMetadataClass · 0.85
LayerSnapshotClass · 0.85

Tested by

no test coverage detected