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

Function write_snapshot_file

training/mlp_train.py:195–229  ·  view source on GitHub ↗
(
    snapshots: Sequence[LayerSnapshot],
    directory: Path,
    order: int,
    identifier: str,
)

Source from the content-addressed store, hash-verified

193
194
195def write_snapshot_file(
196 snapshots: Sequence[LayerSnapshot],
197 directory: Path,
198 order: int,
199 identifier: str,
200) -> Path:
201 slug = slugify_identifier(identifier)
202 filename = f"{order:03d}_{slug}.json"
203 path = directory / filename
204 layers_payload = []
205 for snapshot in snapshots:
206 meta = snapshot.metadata
207 layers_payload.append(
208 {
209 "layer_index": meta.layer_index,
210 "name": meta.name,
211 "activation": meta.activation,
212 "weights": {
213 "shape": list(meta.weight_shape),
214 "data": tensor_to_base64(snapshot.weight),
215 },
216 "biases": {
217 "shape": list(meta.bias_shape),
218 "data": tensor_to_base64(snapshot.bias),
219 },
220 }
221 )
222 payload = {
223 "version": 1,
224 "dtype": "float16",
225 "layers": layers_payload,
226 }
227 directory.mkdir(parents=True, exist_ok=True)
228 path.write_text(json.dumps(payload, separators=(",", ":")))
229 return path
230
231
232def to_posix_relative(path: Path, base: Path) -> str:

Callers 1

record_snapshotFunction · 0.85

Calls 2

slugify_identifierFunction · 0.85
tensor_to_base64Function · 0.85

Tested by

no test coverage detected