Checkpointing¶
tinax.checkpointing owns Orbax V1 checkpointables and explicit abstract restoration targets. It atomically saves related resume-critical values together and returns asynchronous responses for callers to complete.
See the Training Checkpoints guide for task-oriented usage.
save_checkpointables
¶
save_checkpointables(
path: str | PathLike[str],
checkpointables: Mapping[str, Any],
) -> AsyncResponse[None]
Start one immutable atomic V1 save on every process's main thread and return its completion response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Destination checkpoint directory. Must not use Orbax's reserved temporary suffix. |
required |
checkpointables
|
Mapping[str, Any]
|
Non-empty mapping of checkpointable name to value. Names must be portable and distinct. |
required |
Returns:
| Type | Description |
|---|---|
AsyncResponse[None]
|
An Orbax |
AsyncResponse[None]
|
loading from or deleting the destination. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
load_checkpointables
¶
Load all named V1 targets together on every process's main thread after save completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Source checkpoint directory. |
required |
targets
|
Mapping[str, Any]
|
Non-empty mapping of checkpointable name to an explicit non- |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict mapping each requested name to its restored value. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
abstract_restore_target
¶
Replace JAX and NumPy arrays with shape/dtype targets while preserving JAX sharding and static leaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Any
|
Arbitrary pytree of restore targets. JAX arrays become
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
A pytree matching |
Any
|
shape/dtype restore targets. |
TrainingCheckpoint
dataclass
¶
TrainingCheckpoint(
step: int,
model: Any,
optimizer: Any,
rng: Any,
auxiliary: Any,
iterator: DatasetIterator[Any],
)
A complete restored training state from one atomic checkpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
int
|
Non-negative training step the checkpoint was written at. |
model |
Any
|
Restored model state. |
optimizer |
Any
|
Restored optimizer state. |
rng |
Any
|
Restored RNG state. |
auxiliary |
Any
|
Restored user auxiliary state. |
iterator |
DatasetIterator[Any]
|
Restored Grain input iterator. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
TrainingCheckpointNames
dataclass
¶
TrainingCheckpointNames(
model: str = "model",
optimizer: str = "optimizer",
rng: str = "rng",
auxiliary: str = "auxiliary",
iterator: str = "iterator",
)
Names for the five independently handled parts of a training checkpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
Checkpointable name for model state. |
optimizer |
str
|
Checkpointable name for optimizer state. |
rng |
str
|
Checkpointable name for RNG state. |
auxiliary |
str
|
Checkpointable name for auxiliary state and step metadata. |
iterator |
str
|
Checkpointable name for the input iterator state. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any name is not a string. |
ValueError
|
If any name is invalid (see |
save_training_checkpoint
¶
save_training_checkpoint(
path: str | PathLike[str],
step: int,
model: Any,
optimizer: Any,
rng: Any,
auxiliary: Any,
iterator: DatasetIterator[Any],
*,
names: TrainingCheckpointNames | None = None,
) -> AsyncResponse[None]
Start one atomic training save on every process's main thread and return its completion response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Destination checkpoint directory. |
required |
step
|
int
|
Non-negative training step. |
required |
model
|
Any
|
Model state to save. |
required |
optimizer
|
Any
|
Optimizer state to save. |
required |
rng
|
Any
|
RNG state to save. |
required |
auxiliary
|
Any
|
User auxiliary state saved alongside |
required |
iterator
|
DatasetIterator[Any]
|
Grain input iterator whose state is saved. |
required |
names
|
TrainingCheckpointNames | None
|
Optional override for the five checkpointable names. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
AsyncResponse[None]
|
An Orbax |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
load_training_checkpoint
¶
load_training_checkpoint(
path: str | PathLike[str],
model_target: Any,
optimizer_target: Any,
rng_target: Any,
auxiliary_target: Any,
iterator: DatasetIterator[Any],
*,
names: TrainingCheckpointNames | None = None,
) -> TrainingCheckpoint
Preflight value targets before restoring the stateful iterator from the same atomic checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Source checkpoint directory. |
required |
model_target
|
Any
|
Restore target for model state. |
required |
optimizer_target
|
Any
|
Restore target for optimizer state. |
required |
rng_target
|
Any
|
Restore target for RNG state. |
required |
auxiliary_target
|
Any
|
Restore target for user auxiliary state. |
required |
iterator
|
DatasetIterator[Any]
|
Grain iterator to restore in place. |
required |
names
|
TrainingCheckpointNames | None
|
Optional override for the five checkpointable names. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
TrainingCheckpoint
|
A |
TrainingCheckpoint
|
auxiliary state, and iterator. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If the auxiliary checkpointable is missing |
validate_checkpointable_name
¶
Validate one checkpointable name as a safe portable path component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
object
|
Candidate checkpointable name to validate. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The validated |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Legacy (Orbax V0)¶
Warning
The tinax.checkpointing.legacy.v0 namespace is retained only for explicit Orbax V0 compatibility work. Do not use it for new checkpoints.
save_legacy_v0_pytree
¶
Write one immutable legacy V0 PyTree checkpoint synchronously on every process's main thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Destination checkpoint directory. Must not use Orbax's reserved temporary suffix. |
required |
state
|
Any
|
PyTree of values to checkpoint. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
load_legacy_v0_pytree
¶
Read one legacy V0 PyTree checkpoint synchronously on every process's main thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Source checkpoint directory. |
required |
target
|
Any | None
|
Optional PyTree restore target guiding structure and sharding. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The restored PyTree. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
save_legacy_v0_grain_iterator
¶
Write one immutable Grain iterator with its legacy V0 handler on every process's main thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Destination checkpoint directory. |
required |
iterator
|
DatasetIterator[Any]
|
Grain |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
load_legacy_v0_grain_iterator
¶
load_legacy_v0_grain_iterator(
path: str | PathLike[str],
iterator: DatasetIterator[Any],
) -> DatasetIterator[Any]
Read one Grain iterator with its legacy V0 handler on every process's main thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Source checkpoint directory. |
required |
iterator
|
DatasetIterator[Any]
|
Grain |
required |
Returns:
| Type | Description |
|---|---|
DatasetIterator[Any]
|
The restored |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |