I was testing cross-platform resume for Efficio (an open-source PyTorch training library): start a run on Kaggle's 2x T4 GPUs, finish it on Colab's single T4. Training resumed fine, right up until it tried to restore the random number generator state. Then it crashed with an IndexError.
Here's what was going on, and the fix.
The setup
Efficio checkpoints save CUDA's RNG state so a resumed run is numerically consistent, not just "roughly where you left off." That means saving torch.cuda.get_rng_state_all() , which returns one RNG state per GPU that was active when the checkpoint was written.
The restore side used torch.cuda.set_rng_state_all() to put them back. That function expects a list with exactly as many entries as GPUs available right now . My checkpoint had 2 entries (from Kaggle's 2 GPUs). Colab had 1. Index out of range.
Why this is an easy bug to miss
Most resume testing happens on the same machine, or at least the same GPU count.β¦