Lightning-AI / Lightning-AI/pytorch-lightning

Allow overriding the initial batch/step index, for when resuming training.

Open
#19,694 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Description & Motivation

The ModelCheckpoint and Logger callbacks both use a batch_idx that starts at 0 when the Trainer is created. When resuming training, it would be very convenient to be able to pass an offset to the trainer, so instead of restarting at zero, this batch_idx continues from that offset. E.g. if saving a checkpoint every 50k steps, and stopping then continuing after 250k steps, it would be preferable to have the checkpoints numbered 50k, 100k, 150k, 200k, 250k, 300k, 350k... than to have them numbered 50k, 100k, 150k, 200k, 250k, 50k, 100k (with the post-resume checkpoints overwriting the initial ones).

### Pitch

Trainer gets an additional argument, "initial_batch_idx", and "batch_idx" starts at that instead of zero. The logging and checkpointing callbacks use this index.

### Alternatives

The `initial_ix` param could instead be added to the logger and ModelCheckpoint constructors.

### Additional context

_No response_

cc @borda

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Trainer entry point and inspect how batch_idx is initialized and passed to the ModelCheckpoint and Logger callbacks. Trace the resume path and add or update tests to verify that an initial offset continues checkpoint and logging indices without overwriting earlier checkpoints.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.