Skip to content

Conversation

@irisTa56
Copy link

@irisTa56 irisTa56 commented Dec 13, 2025

What this does

Adds gradient accumulation support to the training script.
This allows simulating larger batch sizes without increasing GPU memory usage, which is useful when training large models or when memory is limited.

  • Added gradient_accumulation_steps configuration parameter to TrainPipelineConfig (default: 1)
  • Updated update_policy() to use accelerator.accumulate() context manager
  • Updated effective batch size calculation in logging and MetricsTracker
  • Training loop now skips evaluation and checkpointing during gradient accumulation steps (i.e., treats step as an optimizer step)

How it was tested

  • Added tests in tests/training/test_update_policy.py.
    • test_update_policy_sync_gradients: Verifies gradient sync behavior
    • test_update_policy_gradient_accumulation_equivalence: Validates mathematical equivalence
  • Added test_metrics_tracker_step_with_accelerator in tests/utils/test_logging_utils.py

P.S. I have removed those tests since we’re using the Accelerate API, and testing it is out of the scope of this PR. But they can be seen at d5df208 and d365eb8.

How to checkout & try? (for the reviewer)

# Effective batch size: 8 × 1 × 4 = 32
lerobot-train \
  --dataset.repo_id=lerobot/svla_so101_pickplace \
  --policy.type=act \
  --policy.repo_id=foo/my_policy \
  --policy.push_to_hub=false \
  --batch_size=8 \
  --gradient_accumulation_steps=4 \
  --log_freq=1 \
  --steps=50

@irisTa56 irisTa56 marked this pull request as ready for review December 13, 2025 16:50
Copilot AI review requested due to automatic review settings December 13, 2025 16:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds gradient accumulation support to the training pipeline, enabling simulation of larger batch sizes without increasing GPU memory usage. The implementation leverages Accelerator's built-in gradient accumulation features.

Key changes:

  • Added gradient_accumulation_steps configuration parameter (default: 1) to control how many batches to accumulate before performing an optimizer step
  • Updated training loop to properly handle gradient synchronization, skipping evaluation/checkpointing during accumulation steps
  • Modified effective batch size calculations throughout the codebase to account for gradient accumulation

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/lerobot/configs/train.py Adds gradient_accumulation_steps configuration parameter with documentation
src/lerobot/scripts/lerobot_train.py Updates training loop and update_policy() to use Accelerator's accumulation context, removes unused lock parameter, and adds gradient sync checks
src/lerobot/utils/logging_utils.py Updates MetricsTracker.step() to calculate effective batch size including gradient accumulation
tests/training/test_update_policy.py Adds comprehensive tests for gradient sync behavior and mathematical equivalence
tests/utils/test_logging_utils.py Adds test for MetricsTracker with gradient accumulation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

irisTa56 and others added 5 commits December 14, 2025 02:12
Remove lock parameter and related changes that are outside the scope
of gradient accumulation feature. This keeps the branch focused on
its primary topic and reduces unnecessary diff from main.
@jadechoghari jadechoghari added the training Issues related at training time label Jan 1, 2026
@jadechoghari
Copy link
Member

jadechoghari commented Jan 1, 2026

Hey @irisTa56 that's a very useful feature! I did it locally to train bigger models. Could you maybe resolve the conflicts with main, so we kickoff a review?
Thanks!

@github-actions github-actions bot added tests Problems with test coverage, failures, or improvements to testing configuration Problems with configuration files or settings labels Jan 1, 2026
@irisTa56
Copy link
Author

irisTa56 commented Jan 1, 2026

@jadechoghari
Thanks for the feedback! I've resolved the merge conflicts with main and also added code comments for the newly introduced RA-BC feature. The PR should be ready for review now.

@jadechoghari jadechoghari self-requested a review January 1, 2026 12:45
@jadechoghari
Copy link
Member

Thanks! @irisTa56, the tests in this PR seem unnecessary since we’re using the accelerate api, and testing this functionality is the responsibility of accelerate itself. Removing the accelerate-related tests would make the PR cleaner and shorter 😄

@irisTa56
Copy link
Author

irisTa56 commented Jan 1, 2026

Thanks! @irisTa56, the tests in this PR seem unnecessary since we’re using the accelerate api, and testing this functionality is the responsibility of accelerate itself. Removing the accelerate-related tests would make the PR cleaner and shorter 😄

Thanks for the feedback! I agree and have removed the tests.

@github-actions github-actions bot removed the tests Problems with test coverage, failures, or improvements to testing label Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Problems with configuration files or settings training Issues related at training time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants