(
snapshots: Sequence[LayerSnapshot],
directory: Path,
order: int,
identifier: str,
)
| 193 | |
| 194 | |
| 195 | def 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 | |
| 232 | def to_posix_relative(path: Path, base: Path) -> str: |
no test coverage detected