Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise a clear warning if a user tries to modify the AcceleratorState #458

Merged
merged 8 commits into from
Jun 21, 2022

Conversation

muellerzr
Copy link
Collaborator

Raise warnings if attempting a modification of the AcceleratorState

What does this add?

This PR adds a guard if the user tries to pass a different mixed_precision or cpu flag to Accelerator() after the AcceleratorState has been initialized once.

Who is it for?

Users of Accelerate

Why is it needed?

Currently if a modification is attempted to be made, it gets ignored leaving the user confused as to why they passed in a new mixed precision type, or told the Accelerator to run on the CPU, when in actually it has not due to the AcceleratorState being built once.

What parts of the API does this impact?

User-facing:

Nothing

Internal structure:

A new _check_initialized function has been included in the AcceleratorState that fills a clear string template of what they tried to do, why they cannot do it, and how to achieve their desired behavior.

@muellerzr muellerzr added the enhancement New feature or request label Jun 21, 2022
@muellerzr muellerzr requested a review from sgugger June 21, 2022 18:24
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 21, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes here! I'm good with this but also with adding a private reset method to the AcceleratorState as you suggested offline.

src/accelerate/state.py Outdated Show resolved Hide resolved
@muellerzr muellerzr requested a review from sgugger June 21, 2022 19:12
src/accelerate/state.py Outdated Show resolved Hide resolved
src/accelerate/state.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants