Capture the current dense-layer parameters for export.
(model: SmallMLP, activations: Sequence[str])
| 134 | |
| 135 | |
| 136 | def 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 | |
| 159 | def build_network_payload(layers: Sequence[LayerMetadata]) -> dict[str, Any]: |
no test coverage detected