Enabling Mid-Epoch Training Resumption with Ray Train
Training failures are increasingly common at scale, and effective training infrastructure is judged by how quickly it recovers from them. Mid-epoch resumption lets Ray Train and Ray Data checkpoint your data loader alongside your model, so your restarted run picks up where its last checkpoint left off without breaking exactly-once training. Here's what it gives you:
Less repeated work: a restarted job picks up from its last checkpoint, instead of starting the epoch over.
Correct data coverage: every row is still trained on exactly once per epoch, even across failures.
Simple adoption: it works with your existing Ray Train checkpoints and requires minimal changes to your training script.
In our benchmark, with mid-epoch resumption, a training job that failed 75% of the way through an epoch achieved 9% faster overall runtime and 9% lower dollar cost than when it skipped batches to resume. The bigger your epochs, the more it saves you on failure.
Mid-epoch resumption will ship with Ray 2.61 and is currently available in the Anyscale Runtime starting with Ray version 2.50.
LinkThe cost of mid-epoch training failures
Mid-epoch training failures can be costly. Picture a run whose latest checkpoint was saved 75% of the way through an epoch, followed by a worker failure at 80%:

The model restores from the 75% checkpoint, but the data loader has no record of where it was. The typical recovery approach is to restart the epoch from the beginning, but that has two costs:
Data imbalance: Previously consumed rows are trained on twice in the same epoch while the rest of the dataset is trained on once, which skews what the model learns toward that part of the data.
GPU time: Additional GPU time is spent training on rows that were already consumed.
Both of these costs grow with the size of your epoch. On a small dataset, replaying most of an epoch is a minor cost. However, on a dataset that takes a day to get through, a single late failure can cost another day of GPU time.
To avoid these costs, teams often fast-forward to where training failed, iterating past the batches they've already seen after a restart. However, with streaming loaders like Ray Data that process data on the fly and don’t guarantee row order, skipped rows still need to be recomputed, and fast-forwarding can't guarantee each row is trained on exactly once.
Instead, we require a data loader that keeps its own record of which rows have been consumed and saves it alongside model checkpoints so the two never drift apart. The rest of this post shows how Ray Train and Ray Data do that, and what it saves in practice.
LinkHow it works

The key idea is to track consumed rows rather than a position. Ray Data doesn't hand out rows in a fixed order, so knowing how many batches were consumed isn't enough to find your place again, but knowing which rows were consumed is. To make that work, every row needs a unique ID, each worker records the IDs it trains on, and after a restart Ray Data uses that record to skip those rows as it reads. Let’s walk through how Ray Train and Ray Data do this when saving and restoring progress.
LinkSaving progress
Record every yielded batch. Once you turn on data checkpointing for a dataset with a
DatasetCheckpointConfig, every batch Ray Data’s data iterator hands to your training loop is recorded: a background thread writes the batch's row IDs to files in shared storage.Commit at checkpoint time. When you checkpoint the model, you also call
state_dict()on the data iterator. That call flushes any remaining row IDs, closes out the current set of files, and returns a small dictionary: the epoch, a checkpoint index, the path where the row ID files live, and the ID column name.Save it with the model. You store that dictionary in the same checkpoint as the model and optimizer state, and report it with
ray.train.report(). The model and the data loader state are committed together, so they always agree on what has been trained.
Each worker writes its own files, organized by rank, epoch, and checkpoint index:
ray_data_checkpoints/train/
└── rank=0/
└── epoch=0/
├── checkpoint=0/chunk_0.parquet
├── checkpoint=1/chunk_0.parquet
└── checkpoint=2/chunk_0.parquetBy default these files live under your Ray Train storage path and are deleted once an epoch finishes, since there's nothing left to resume within it.
LinkRestoring progress
Load the state. When the job restarts, your training function gets the latest checkpoint from
ray.train.get_checkpoint(), reads the saved dictionary from it, and passes it toray.train.get_dataset_shard()through thestate_dictargument.Load the consumed row IDs. Ray Data reads the row ID files for that epoch up to the saved checkpoint index, across every rank, and sorts them so lookups are fast.
Filter as you read. A filter step right after the read drops any row whose ID is in that set, using a binary search per row. Skipped rows never reach your preprocessing or your training loop.
Continue the epoch. Training picks up with the remaining rows. After that epoch ends, later epochs read the full dataset as usual.
Because the filter applies to the dataset as a whole rather than to each worker, the remaining rows are split across whatever workers the restarted run has. Restoring still rereads the input files, but reading and filtering a row costs far less than preprocessing it and running it through a training step.
LinkUsing mid-epoch resumption
All of this bookkeeping happens inside Ray Train and Ray Data. If you already checkpoint with ray.train.report, turning on mid-epoch resumption takes three changes: tell Ray Train which dataset to track, save the data iterator's state with your model, and pass that state back in when you restore.
import ray
from ray.train import DataConfig, DatasetCheckpointConfig, ScalingConfig
from ray.train.torch import TorchTrainer
def train_func():
model, data_state = build_model(), None
if checkpoint := ray.train.get_checkpoint():
model, data_state = load_checkpoint(checkpoint) # your restore logic
# Change 3: resume the data iterator from the saved state.
shard = ray.train.get_dataset_shard("train", state_dict=data_state)
for step, batch in enumerate(shard.iter_torch_batches(batch_size=64)):
... # training step
if step % 100 == 0:
# Change 2: save the data iterator state with the model.
checkpoint = save_checkpoint(model, data_state=shard.state_dict())
ray.train.report({"step": step}, checkpoint=checkpoint)
trainer = TorchTrainer(
train_func,
datasets={"train": ray.data.read_parquet("s3://my-bucket/train/")},
# Change 1: track which rows each worker has consumed.
dataset_config=DataConfig(
dataset_checkpoint_configs={
"train": DatasetCheckpointConfig(id_column="id")
}
),
scaling_config=ScalingConfig(num_workers=16, use_gpu=True),
)
trainer.fit()Note: build_model, save_checkpoint, and load_checkpoint stand in for your existing model and checkpoint code.
Here's what each change above does:
Turn on data checkpointing for the dataset. Pass a
DatasetCheckpointConfigfor the dataset throughDataConfig(dataset_checkpoint_configs=...).id_columnnames the column that uniquely identifies each row, here a column called id. If your data doesn't have one, see the requirements below.Save the data iterator's state with every model checkpoint. Call
shard.state_dict()on every worker each time you checkpoint. On each worker, the call makes sure every row ID that worker has consumed is written to shared storage. What it returns isn't those IDs but a small, JSON-serializable dictionary that points to where every worker's files are stored, so it's identical on every worker. Store it in the checkpoint directory next to your model before callingray.train.report.Pass the state back in on restore. Load the dictionary from the checkpoint and pass it to
ray.train.get_dataset_shard. Every worker loads the same dictionary, so every worker can pass it in. Ray Train uses rank 0's copy to set up the restored dataset.
For a complete, runnable script, see the mid-epoch resumption docs.
LinkRequirements
To use mid-epoch resumption, there are a few conditions:
Every row needs a unique ID. Point
id_columnat an existing column whose values are unique and survive your preprocessing. If your data doesn't have one,generate_id_column=Truecreates one for you and removes it from the batches your training loop sees. Generated IDs currently only work with Parquet.Only use row-preserving transformations. Stick to transformations that don't add rows, such as
map,map_batches, andfilter, and pass the ID column through to the end of the pipeline.Checkpoints need shared storage. Row ID files go to your Ray Train storage path by default, so it must be cloud storage or a network file system that every node can reach.
Automatic restarts need fault tolerance. Set
FailureConfig(max_failures=...)in yourRunConfigso Ray Train restarts the run after a failure and restores the latest checkpoint.Finish consuming a batch before you checkpoint. Ray Data’s iterator counts a batch as consumed once it hands it to your loop. If your framework queues batches before the model trains on them, drain that queue before calling
ray.train.report. Otherwise, your data checkpoint will be ahead of what the model has actually trained on.
LinkEvaluating the impact
With the setup covered, how much does mid-epoch resumption actually save when a run fails late in an epoch? We benchmarked it on an image classification job. The setup is as follows:
Model and data: ResNet-50 (26M parameters) on a modified ImageNet with images up to 2048x2048, with 1M training rows and 50k validation rows.
Cluster: 16 A100 GPUs for training, plus 10 CPU nodes for Ray Data preprocessing.
Checkpointing and validation: every 50 steps.
Failure: a simulated failure 75% of the way through the epoch.
With this setup, we ran the same job twice: once skipping batches to get back to the restored position after the failure, which is what frameworks like Hugging Face Transformers do by default, and once with mid-epoch resumption:
Metric | Baseline (skip batches) | Mid-epoch resumption |
|---|---|---|
End-to-end time | 594 s | 542 s |
Cost | $1.45 | $1.32 |
Compared to skipping batches, enabling mid-epoch resumption reduced both end-to-end job runtime and dollar cost by 9%. Without mid-epoch resumption, skipping batches still needs to read, preprocess, and transfer every row before the restore point, only to throw it away. Mid-epoch resumption still reads those rows, but drops them right after the read, before any preprocessing or transfer to the training workers. This is also why the savings grow with larger epochs and heavier preprocessing.
LinkSummary
Training runs fail, and the bigger the run, the more each failure costs. Mid-epoch resumption makes the data loader's state part of your checkpoint, so a restarted Ray Train job picks up where its last checkpoint left off, training on each row exactly once. In our benchmark, it cut the job's end-to-end runtime and total cost by 9% compared with skipping batches, and every row is still trained on exactly once per epoch. Mid-epoch resumption ships with open source Ray starting in Ray 2.61 and is available today in the Anyscale Runtime starting with Ray 2.50. For usage details, see the mid-epoch resumption docs. If you run into problems or have ideas for what we should build next, file an issue on GitHub.
We'd like to thank Justin Yu, who led the work on mid-epoch resumption, and our colleagues on the Ray Train and Ray Data teams for their reviews, design feedback, and contributions to this work.


