-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[WIP] FEAT Decorator to purge accelerate env vars #3252
[WIP] FEAT Decorator to purge accelerate env vars #3252
Conversation
In some circumstances, calling certain classes or functions can result in accelerate env vars being set and not being cleaned up afterwards. As an example, when calling: TrainingArguments(fp16=True, ...) The following env var will be set: ACCELERATE_MIXED_PRECISION=fp16 This can affect subsequent code, since the env var takes precedence over TrainingArguments(fp16=False). This is especially relevant for unit testing, where we want to avoid the individual tests to have side effects on one another. Decorate the unit test function or whole class with this decorator to ensure that after each test, the env vars are cleaned up. This works for both unittest.TestCase and normal classes (pytest); it also works when decorating the parent class. In its current state, this PR adds the new decorator and tests it, but the decorator is not yet applied to potentially problematic functions or classes.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LG2M since we both agreed offline :)
@muellerzr how much will this still be needed if huggingface/transformers#34886 is merged? |
None, but it's not bad to over protect imo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ! Thanks for the nice tests
What does this PR do?
In some circumstances, calling certain classes or functions can result in accelerate env vars being set and not being cleaned up afterwards. As an example, when calling:
TrainingArguments(fp16=True, ...)
The following env var will be set:
ACCELERATE_MIXED_PRECISION=fp16
This can affect subsequent code, since the env var takes precedence over
TrainingArguments(fp16=False)
. This is especially relevant for unit testing, where we want to avoid the individual tests to have side effects on one another. Decorate the unit test function or whole class with this decorator to ensure that after each test, the env vars are cleaned up. This works for bothunittest.TestCase
and normal classes (pytest) and standalone functions; it also works when decorating the parent class and in conjunction with other decorators.Notes
In its current state, this PR adds the new decorator and tests it, but the decorator is not yet applied to potentially problematic functions or classes.
Personally, I'm not super happy with the implementation, as it turned out to be more complicated than I initially thought (mainly because of the subclassing). I tested this decorator on the initial test failure in PEFT and it solved it. However, it requires to decorate each and every class/function that could potentially have side effects. It is thus easy to miss something.
Before submitting
Pull Request section?
Was this discussed/approved via a Github issue or the forum? Please add a linkInternal discussion on Slackto it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.