Raise a clear warning if a user tries to modify the AcceleratorState #458
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.
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
orcpu
flag toAccelerator()
after theAcceleratorState
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 theAcceleratorState
that fills a clear string template of what they tried to do, why they cannot do it, and how to achieve their desired behavior.