Skip to content

Fix progress bar total under gradient accumulation with iterable datasets#21802

Open
Akrao9 wants to merge 1 commit into
Lightning-AI:masterfrom
Akrao9:fix/progress-bar-total-grad-accumulation
Open

Fix progress bar total under gradient accumulation with iterable datasets#21802
Akrao9 wants to merge 1 commit into
Lightning-AI:masterfrom
Akrao9:fix/progress-bar-total-grad-accumulation

Conversation

@Akrao9

@Akrao9 Akrao9 commented Jul 4, 2026

Copy link
Copy Markdown

What does this PR do?

Follow-up to #20869. That PR made ProgressBar.total_train_batches fall back to max_steps - global_step for infinite (no-__len__) dataloaders, so the progress bar shows a finite total instead of ?.

The problem: that quantity is in optimizer steps, but the bar's counter advances per batch. With accumulate_grad_batches=N, each optimizer step consumes N batches, so over a full run the bar reads e.g. 500000/100000 (5× overshoot at N=5) and the ETA is wrong. The regression slipped through because the tests added in #20869 leave accumulate_grad_batches at its default of 1, where steps and batches coincide.

Fix: convert the remaining-step count to batch units (* accumulate_grad_batches) before the min() with num_training_batches. Behavior is unchanged when accumulate_grad_batches=1 and for finite dataloaders (where num_training_batches wins the min).

Test: parametrized the existing test_tqdm_total_steps_with_iterator_no_length over accumulate_grad_batches=[1, 4], asserting both the bar total and the final counter (tqdm .n / rich .completed).

Follow-up to #20869; fixes the gradient-accumulation case of #20124.

Before submitting
  • Was this discussed/agreed via a GitHub issue? (Why does the progress bar not show the total steps when using iterable dataset? #20124)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (CHANGELOG updated)
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request? (none)
  • Did you update the CHANGELOG?

…sets

PR Lightning-AI#20869 made `total_train_batches` fall back to `max_steps - global_step`
for infinite dataloaders so the bar shows a finite total. That quantity is
in optimizer steps, but the bar's counter advances per batch: with
`accumulate_grad_batches=N` each optimizer step consumes N batches, so the
bar reads e.g. 500000/100000 over a full run (5x overshoot at N=5). The
tests added in Lightning-AI#20869 left `accumulate_grad_batches` at its default of 1,
where steps and batches coincide, which is why the mismatch went unnoticed.

Convert the remaining-step count to batch units before taking the min with
`num_training_batches`, and parametrize the regression test over
`accumulate_grad_batches` (asserting both the bar total and the final
counter, tqdm `.n` / rich `.completed`).
@Akrao9 Akrao9 force-pushed the fix/progress-bar-total-grad-accumulation branch from 2c892bd to 7d24ecf Compare July 4, 2026 01:42
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