#4283·accelerate

[Bug] RNG state restoration failure swallowed silently — resumed training diverges without warning

Author: cmaguire001Created Sep 19, 2026Updated Sep 26, 2026

System Info

bash
- `Accelerate` version: 1.16.0.dev0
- Platform: Windows-10-10.0.26200-SP0
- `accelerate` bash location: Not found
- Python version: 3.11.13
- Numpy version: 1.26.4
- PyTorch version: 2.14.0+cpu
- PyTorch accelerator: N/A
- System RAM: 11.90 GB
- `Accelerate` default config:
        - compute_environment: LOCAL_MACHINE
        - distributed_type: NO
        - mixed_precision: no
        - use_cpu: True
        - debug: False
        - num_processes: 1
        - machine_rank: 0
        - num_machines: 1
        - rdzv_backend: static
        - same_network: False
        - main_training_function: main
        - enable_cpu_affinity: False
        - downcast_bf16: False
        - tpu_use_cluster: False
        - tpu_use_sudo: False

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • One of the scripts in the examples/ folder of Accelerate or an officially supported no_trainer script in the examples folder of the transformers repo (such as run_no_trainer_glue.py)
  • My own task or dataset (give details below)

Reproduction

python
import pathlib
import tempfile
import torch
from accelerate import Accelerator
from accelerate.checkpointing import save_accelerator_state, load_accelerator_state
from accelerate.utils import RNG_STATE_NAME

accelerator = Accelerator()
model = torch.nn.Linear(4, 2)
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
ckpt = pathlib.Path(tempfile.mkdtemp())

# Capture RNG state before save
rng_before = torch.get_rng_state()

# Save a valid checkpoint
save_accelerator_state(
    output_dir=str(ckpt),
    model_states=[model.state_dict()],
    optimizers=[opt],
    schedulers=[],
    dataloaders=[],
    process_index=0,
    step=100,
)

# Simulate partial write from preempted job
(ckpt / f"{RNG_STATE_NAME}_0.pkl").write_bytes(b"CORRUPTED")

# Advance RNG so we can detect whether restore happened
torch.manual_seed(99999)
rng_diverged = torch.get_rng_state()

# Resume — should warn loudly but does not
load_accelerator_state(
    input_dir=str(ckpt),
    models=[model],
    optimizers=[opt],
    schedulers=[],
    dataloaders=[],
    process_index=0,
)

rng_after = torch.get_rng_state()
print("RNG restored:", torch.equal(rng_after, rng_before))   # False
print("RNG diverged:", torch.equal(rng_after, rng_diverged)) # True

Actual output:

[RANK 0] Could not load random states
RNG restored: False
RNG diverged: True

Expected behavior

When RNG state cannot be restored from a checkpoint — due to a corrupted file or partial write from a preempted job — accelerate should emit at minimum a logger.warning() so the user knows their resumed run is not numerically equivalent to an uninterrupted one.

Currently the failure is caught by a bare except Exception block in src/accelerate/checkpointing.py line 317 and logged at INFO level — the same level as a successful restore — making it invisible in real training logs.

The only observable symptom is subtle loss curve divergence, which is extremely difficult to attribute and typically blamed on learning rate, data quality, or model architecture instead.

At minimum:

  • Change logger.info("Could not load random states") to logger.warning() with a message explaining the consequence (training will diverge).

Ideally:

  • Distinguish FileNotFoundError (missing file) from other failures (corruption)
  • Raise a RuntimeError for unrecoverable failures with an opt-out flag such as strict_checkpoint=False for users who want to continue anyway

Static analysis of checkpointing.py confirms three related silent failure points:

[BROAD_EXCEPT] — 1 instance — line 317 [EXISTS_NO_ELSE] — 1 instance — line 280 (stateful dataloader silent skip) [ISINSTANCE_NO_ELSE] — 4 instances — lines 137, 139, 273, 275 (sampler type guards)

I am happy to submit a PR implementing the fix once the preferred approach is confirmed.

reproduce_v2.py

analyze.py