8.3 KiB
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.
Closing a restore point removes its directory. If any file cannot be removed
(or an interrupt stops the removal), DiskSnapshot.close() leaves the snapshot
unusable: the snapshot's own policy records status: "close_failed" with
restore unavailable and the path, it raises SnapshotError naming the path and
the first failing entries, and calling DiskSnapshot.close() again retries.
ModelHandle.cleanup() reports the restore point closed and unavailable,
lets go of it, then closes it, and never retries. On a close failure the
handle's snapshot_policy reports status: "closed", restore unavailable, and
a reason naming the failure; the error is raised to the caller and names the
path to remove manually (the handle cannot retry DiskSnapshot.close()).
Library call sites that clean up a handle while another error is propagating
(cleanup_on_exit, cleanup_during_error in obliteratus.handle_cleanup,
also importable from obliteratus.models.loader) log the cleanup failure and
attach it to that error as a note instead of replacing it. An interrupt
(KeyboardInterrupt, SystemExit) raised by the cleanup itself is not turned
into a note: it propagates, with the original error as its __context__.
Garbage-collection finalization only logs a cleanup failure.
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. Resident tensors
with expanded (stride-0, Tensor.expand) axes are admitted: restore writes the
shared element once and keeps the original layout and tensor identity, and a
saved value that varies along an expanded axis is rejected before any write.
Other strided layouts, including interleaved non-dense as_strided views, are
admitted when their remaining elements address distinct storage. A cheap stride
test proves this for ordinary layouts; otherwise the storage offsets are
enumerated exactly, on the host, for up to 4 Mi (4,194,304) distinct elements.
That check's scratch (48 bytes per enumerated element) is added to the admitted
host staging, so staging_bytes remains a hard cap, and restore validation
never runs a larger check than the restore point admitted. Snapshot
creation fails for a layout that truly overlaps (for example overlapping
as_strided windows) and, above that limit, for a layout that could not be
proven non-overlapping even if it does not overlap; register a contiguous copy
instead. 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:
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_bytesand 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 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. Sizes alone do not reveal tensor strides, so a plan
without layout information adds a conservative exact overlap-check allowance of
48 bytes per element for min(4 Mi, largest_tensor_bytes) elements (at most
192 MiB), reported as exact_check_bytes with exact_check_basis: "unknown_layout_allowance". Its host figure is therefore a conservative upper
bound on runtime host demand for the same sizes: runtime measures the real
scratch from live layouts (exact_check_basis: "measured", usually 0 for
contiguous weights). A disk_backed plan is still not a promise: runtime
admission can refuse a layout the plan cannot see (one that overlaps or exceeds
the 4 Mi element limit), or because available host memory or disk changed.
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.