Skip to content

Add Trainer.save/load checkpointing for resumable runs - #13

Merged
davidkhjo merged 1 commit into
mainfrom
trainer-checkpoint
Aug 9, 2026
Merged

davidkhjo merged 1 commit into
mainfrom
trainer-checkpoint

Conversation

@davidkhjo

Copy link
Copy Markdown
Owner

Image-scale runs take minutes; until now an interruption lost everything. Trainer.save(path) / Trainer.load(path) (plus state_dict / load_state_dict) checkpoint and resume a full run:

  • energy weights, optimizer moments, the EMA copy
  • loss parameters (e.g. NCE's log_z) when the loss is an nn.Module
  • the PCD replay buffer — it lives inside the loss, not the trainer, so it's captured generically via loss_fn.buffer without coupling to any loss class
  • the step counter and metric history (resume continues the count)

Mirrors the plain-dict state_dict/load_state_dict convention already used by EMA and ReplayBuffer; load restores into a matching freshly-constructed Trainer (same load-into-existing pattern). save/load are thin torch.save/torch.load wrappers.

Tests

test_trainer_checkpoint_roundtrip_and_resume: trains a PCD trainer 30 steps, saves, loads into a differently-initialized trainer, and asserts energy params, EMA weights, buffer contents, optimizer state, and step_count/history all match — then resumes and confirms the counter continues 30→35.

Docs: new "Saving and resuming" section in docs/training.md.

🤖 Generated with Claude Code

Trainer.state_dict/load_state_dict (and save/load wrappers) capture everything
needed to resume a multi-minute image run: energy weights, optimizer moments,
the EMA copy, loss parameters (e.g. NCE log_z), the PCD replay buffer (owned by
the loss, captured generically via loss_fn.buffer), and the step counter and
metric history. Mirrors the plain-dict state_dict convention of EMA and
ReplayBuffer; load restores into a matching freshly-constructed Trainer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@davidkhjo
davidkhjo merged commit 8223863 into main Aug 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant