Skip to content

tinker_cookbook.checkpoint_utils.CheckpointRecord

class tinker_cookbook.checkpoint_utils.CheckpointRecord()

A single checkpoint record stored in checkpoints.jsonl.

Known fields are exposed as typed attributes. batch is optional so that checkpoint files written by older code (or external tools that use different progress counters) can still be loaded.

Any additional user-supplied metadata from loop_state is preserved in extra so that custom keys round-trip through save/load without loss.

Fields:

  • name (str)
  • batch (int | None, default: None)
  • epoch (int | None, default: None)
  • final (bool | None, default: None)
  • state_path (str | None, default: None)
  • sampler_path (str | None, default: None)
  • extra (dict[str, Any], default: field(default_factory=dict))

to_dict()

Serialize to a dict for JSON storage.

Omits None optional fields. Extra metadata keys are merged into the top-level dict.

Returns: dict[str, Any] – JSON-serializable dict with known fields and any extra metadata.

from_dict(d)

Deserialize from a JSON-parsed dict.

Unknown keys are preserved in extra so that downstream metadata (e.g. step) round-trips without loss.

Parameters:

  • d (dict[str, Any]) – Dict with at least a "name" key.

Returns: CheckpointRecord – Reconstructed record.

has(key)

Check whether a field is present (not None), including extra keys.

Parameters:

  • key (str) – Field name to check (known attribute or extra key).

Returns: bool – True if the field exists and is not None.

get(key, default)

Get a field value by name, falling back to extra, then default.

This provides uniform access regardless of whether a key is a known attribute or user-supplied metadata stored in extra.

For known fields, returns the attribute value (which may be None if the field is optional and unset). Returns default only when the key is not a known field and is absent from extra.

Parameters:

  • key (str) – Field name to look up (known attribute or extra key).
  • default (Any) – Value to return if key is not a known field and is absent from extra. If omitted, returns None for missing extra keys.

Returns: Any – The field value, extra value, or default.