Recipe Graphs and Checkpoint Migration#

Recipes are declarative graphs. Runtime datasets are wrapper trees. Checkpoint migration connects the two by reusing the saved state of every part of the runtime tree whose configuration is unchanged.

Recipe graph construction#

The main graph nodes are:

  • DatasetReference, a leaf path plus split, subset, shuffle, filter, and tag settings;

  • RecipeBlend and RecipeBlendEpochized, weighted child graphs;

  • Subset, which expresses relative or absolute selection;

  • Recipe, which owns named splits and resolves the full graph.

Recipe.post_initialize resolves references relative to the recipe root and validates the resulting graph. get_datasets builds runtime factories. traverse visits the same logical leaves without constructing the runtime pipeline; use it for preparation, diagnostics, and graph inspection.

Nested option composition#

When a reference wraps another recipe or reference, its settings compose with the inner settings:

  • positive shuffle-over-epochs multipliers multiply;

  • a shuffle value of -1 dominates positive multipliers;

  • None disables the composed shuffle and therefore dominates all numeric values;

  • relative subsets compose through the nesting;

  • absolute subset bounds belong at the concrete leaf, where the absolute sample space is known;

  • inner tags are retained, with outer values overriding the same keys;

  • an outer split selection may choose a different split of a nested recipe.

Keep these rules in one graph-resolution layer. Applying a subset a second time in the reader or moving shuffle composition into a wrapper changes the dataset configuration or iteration order.

Zero weights#

The supported recipe edits between saving and migrating are adding datasets and setting the weight of datasets to zero. A dataset with a zero weight stays in the list of loaded datasets, so it still counts for the worker rotation offsets of the datasets behind it. It is only left out when the training pipeline is built. Deleting the entry instead would shift those offsets.

Resume metadata#

Checkpoint migration compares the nodes of the saved and the current runtime tree by their configuration. The resume metadata mirrors the runtime tree and stores for every node:

  • the class name of the dataset;

  • a digest of its config() and of the digests of its children;

  • descriptions of the recipe datasets it reads, on the innermost node that names them.

A recipe dataset is a mapping containing _path anywhere in the configuration. Its description consists of the path, the selected split part, the subset, and the filter name. Descriptions name the datasets in warnings and decide which nodes may be matched. Nodes are compared by their digest only.

A leaf factory must therefore return a deterministic, serializable config() that contains everything distinguishing it from other datasets. Renaming or removing configuration fields is a checkpoint-migration change even when exact restoration of an unchanged runtime tree still works.

Migration algorithm#

Migration starts from a clean state generated by the current dataset topology. It then overlays saved progress:

  1. The saved states of all nodes that read recipe datasets are collected by their digest.

  2. A current node continues from the saved node with the same digest, including everything below it. The position of the saved node in its tree is irrelevant. The trees may therefore be shifted against each other, for example because a BlendDataset only exists for more than one used dataset.

  3. Otherwise the node keeps its fresh state and its children are migrated in the same way. This is also the case if several saved or several current nodes have the digest, e.g. for a dataset listed twice, because they cannot be told apart.

  4. A node that does not read a recipe dataset is not matched on its own. Nodes of different datasets can share its configuration, like the samplers of two datasets with the same shards.

An equal digest means that the whole subtree is configured identically. If nothing changed, this holds for the root, and the migrated state equals the saved state.

A rebuilt blend skips children known to have finished the saved pass. A saved blend can record this per child, or a wrapper can record it for its source while yielding buffered samples. For example, appending a dataset after the final short batch of a finite pass leaves only the new dataset to read. The blend’s random state and size accounting start fresh.

Migration preserves loader-level worker state that is independent of the changed dataset tree, including worker random state, sample-index scopes, offsets, worker scheduling, and the current micro-batch. The dataset subtree comes from the migrated current topology.

Dataset progress is tied to the samples assigned to a worker. The worker rotation offset of a dataset depends on the lengths of the entries in front of it, so adding entries in front of a dataset, deleting or reordering entries can change this assignment and with it the sampler configuration. Such a dataset stays fresh. Migration collects the datasets whose saved progress is reused and warns about every dataset that is part of both recipes but was not reused.

All state above a changed node is fresh, including buffered samples. For example, GroupBatchDataset resets group and batch indexes and pending buckets because those buffers cannot be safely reinterpreted under an altered graph.

Exact restore is stricter#

Migration is not a promise that recipe edits reproduce an uninterrupted run bit for bit.

  • Exact restore requires the same compatible runtime tree and continues the exact stream.

  • Migration preserves the progress of unchanged datasets and initializes changed structure safely.

Adding a dataset or setting a weight to zero is therefore accepted by migration while producing a different future stream. User-facing behavior and examples are documented in Saving and Restoring.

Developing graph changes#

When adding or changing a recipe node:

  1. define how it resolves nested paths, splits, subsets, shuffle values, and tags;

  2. ensure traverse and runtime construction find the same leaves;

  3. ensure the resulting leaf factory config is deterministic and contains _path and everything else that distinguishes the dataset;

  4. decide whether child order is semantic;

  5. test unchanged exact restore separately from changed-topology migration;

  6. classify any configuration, state-layout, or order change using Compatibility and Review Matrix.

At minimum, migration tests should cover:

  • unchanged graph round trips;

  • adding a dataset and setting a weight to zero;

  • nested recipes and split overrides;

  • changed subsets and filters;

  • datasets listed more than once, which must fail safe by using fresh state;

  • changed worker assignments, which must be reported;

  • buffered wrappers whose own pending state is intentionally reset.

The core tests are in test_checkpoint_resume.py and the recipe save/restore tests in test_recipe.py.