Files
OBLITERATUS/docs/model-snapshots.md
2026-10-19 01:45:01 -04:00

95 lines
5.3 KiB
Markdown

# Model restore points
`ModelHandle.snapshot()` writes a private disk-backed restore point, bound to
the original model and module structure. `ensure_snapshot()` creates one if
loading skipped it, then validates the payloads before a study begins. The
runner restores after every ablation, including failed ablation/evaluation,
and publishes results only after restoration succeeds. It removes owned
snapshot storage on both successful and failed study exits.
Snapshot replacement is transactional: a rejected replacement leaves the
previous restore point available. Restore checks the complete inventory and
payload digests before writing; a partial write invalidates the restore point
and model. Reload an invalid model before further use.
The backend supports resident floating parameters and persistent buffers, and
floating parameters and ordinary boolean/integer persistent buffers in
qualified Accelerate CPU/disk backing layouts. Packed quantized parameters
and unsupported buffer layouts fail before a study starts. Quantization metadata is not silently omitted.
Call `snapshot(directory=..., max_bytes=..., staging_bytes=...)` to set the
storage location and byte limits. Defaults are 64 GiB disk and
`staging_bytes=None`, which admits 50% of currently available host memory at
snapshot creation (`DEFAULT_STAGING_HOST_FRACTION = 0.5`). Explicit
`staging_bytes` values remain hard caps: the admitted budget is the smaller of
the configured value and currently available host memory. In study YAML, omit
`staging_bytes` or set it to `null` to use the default.
The admission estimate reserves six largest-tensor copies plus aggregate
CPU-offload overlays. Disk-offload restores publish private safetensors files
through the existing loader's lazy index, then discard superseded owned files.
They preserve the source offload directory and remain readable after snapshot
cleanup. The disk budget reserves space for the snapshot, current restored
backing, and replacement backing.
Current host availability is the minimum of system memory, process address-space
headroom, and applicable cgroup ancestor limits. Restore rechecks it before
writes. Individual tensors must fit the staging allowance; this backend does
not split a single oversized tensor into chunks.
Study YAML can select a large-model budget and storage location:
```yaml
snapshot:
directory: /srv/obliteratus/snapshots
max_bytes: 300000000000
staging_bytes: 4000000000
```
The directory must exist. Requested limits do not override actual available
memory or disk capacity. If staging admission fails, raise
`snapshot.staging_bytes` in study config or the `staging_bytes=` argument, or
free host memory; an explicit cap cannot override available host memory.
The runner skips loader-time snapshots and acquires
its restore point using these study settings.
For a checkpoint with 145 GB of BF16 tensors, the default 64 GiB cap refuses a
restore point. Select one explicit policy before loading or editing:
- Admit disk-backed snapshots with a larger `max_bytes` and adequate host
staging. Resident weights need approximately one checkpoint of snapshot
storage. Weights offloaded through Accelerate dispatch to CPU or disk can
require three checkpoint equivalents for the snapshot and repeated replacement
backing, plus per-file overhead.
- Disable optional loader snapshots with `skip_snapshot=True`, record why
restoration is unavailable, and reload the immutable source for independent
runs. Studies that require rollback still obtain an admitted restore point
before starting; disabling a loader snapshot does not disable that contract.
`plan_snapshot()` in `obliteratus.models.snapshot` computes the same disk and
host requirements from total bytes, largest tensor, tensor count and backing
layout before allocating weights. It reports `disk_backed`, `refused`, or
`disabled_with_reason`. Disabling requires a nonempty reason. Missing live
memory/disk observations set `runtime_check_required`; actual snapshot creation
always checks both again. `ModelHandle.snapshot_policy` records the active
restore-point policy or the loader's reason for skipping it.
Native dense Qwen2.5 checkpoints with untied embeddings can use the bounded
checkpoint exporter when split across devices or qualified Accelerate CPU/disk
offload. `plan_native_export()` inspects loaded tensor metadata and offload
owners without materializing the weights. It reserves one CPU shard,
serialization copies and the largest temporary offload owner. A single tensor
can exceed the shard size; admission uses the actual planned shard size.
`native_export_summary()` exposes these bounds as run evidence.
Config-only meta instantiation can request `allow_unbacked_meta=True` to estimate
native export capacity. That plan is marked `capacity_estimate_only` and the
writer refuses to use it. Recheck the loaded model before edits: quantization,
custom serialization, adapters, native tensor parallelism and offloaded shared
ties can make a model ineligible. Large-model qualification requires bounded
eligibility unless the operator explicitly requests the legacy fallback; an
ineligible plan is never proof that a whole-state host gather will fit.
CPU tests cover metadata admission and tiny partial CPU/disk offload, including
peak live CPU tensor storage during export. Broader layouts and physical
device/host peaks still require hardware qualification.