Add support for Custom Accelerate Instance in Trainer#40633
Open
Flakes342 wants to merge 5 commits into
Open
Conversation
Flakes342
commented
Sep 2, 2025
| raise ValueError("save_only_model option is not compatible with FSDP state dict type 'SHARDED_STATE_DICT'") | ||
|
|
||
|
|
||
| def postprocess_accelerator(self): |
Contributor
Author
There was a problem hiding this comment.
I wanted to create this as a different method to support any modifications to custom accelerate function in future too.
Contributor
Author
|
Again, I am not sure what these test failures are.. |
Contributor
Author
|
Changes for this PR have been done in: Rest all seems to have happened because of auto formatting fix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #40616
This PR adds the ability to pass a custom Accelerator instance to the Trainer constructor, giving users fine-grained control over distributed training configurations while maintaining all existing Trainer functionality.
Before submitting
Pull Request section?
to it if that's the case. Allow users to pass through
Accelerateinstance #40616documentation guidelines, and
here are tips on formatting docstrings.
Description
Currently, users who need advanced distributed training configurations (custom DeepSpeed settings, specific FSDP configurations, etc.) have limited options to customize the Accelerator used by Trainer. The existing approach forces users to either modify TrainingArguments which doesn't expose all accelerate options to them or use accelerator_config which is less intuitive and limited.
This change allows users to create and configure their own Accelerator instance with full control over:
Changes
Trainerinitialization to add an optionalacceleratorparameterpostprocess_acceleratormethod: Handles postprocessing for user-provided accelerators - similar to currentcreate_accelerator_and_postprocessmethodExample
Adding a simple example of how custom accelerator functionality can be used in trainer:
Testing
Added comprehensive tests to trainer/test_trainer.py covering:
Please let me know if the tests need to be written in some other way. Also, please review and provide your comments and I'd be happy to incorporate any corrections/suggestions.
Who can review? @Rocketknight1, @SunMarc, @anyone :)