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

Rm strtobool #1964

Merged
merged 4 commits into from
Sep 12, 2023
Merged

Rm strtobool #1964

merged 4 commits into from
Sep 12, 2023

Conversation

muellerzr
Copy link
Collaborator

What does this PR do?

As strtobool will be removed in the next python version (3.12), this PR re-implements it for what we care about

Tags along with #1963 to get us to ~.9s for maximum efficiency too 🚀

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@BenjaminBossan

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 12, 2023

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

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Oh wow, nice catch, I didn't know that strtobool was deprecated. There doesn't seem to be any warning when importing it, who knows how many upgrades will fail when people switch to Python 3.12.

I like the decision to change the name, that way there can be no accidental usage of the previous function.

I only have one question, which is about the decision to return a bool instead of int now. I agree it makes more sense (maybe strtobool predates the existence of bools in Python), but it makes all the if str_to_bool(...) == 0 calls a bit awkward.

src/accelerate/utils/environment.py Outdated Show resolved Hide resolved
src/accelerate/utils/environment.py Outdated Show resolved Hide resolved
@@ -28,7 +42,7 @@ def get_int_from_env(env_keys, default):
def parse_flag_from_env(key, default=False):
"""Returns truthy value for `key` from the env if available else the default."""
value = os.environ.get(key, str(default))
return strtobool(value) == 1 # As its name indicates `strtobool` actually returns an int...
return str_to_bool(value) == 1 # As its name indicates `str_to_bool` actually returns an int...
Copy link
Member

Choose a reason for hiding this comment

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

This comment, which I assume is meant ironically, could be removed if we actually return a bool. But technically, a bool is an int, so not sure if it's really meant to be ironic :D

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. Well done catching this deprecation.

@muellerzr muellerzr merged commit d9b5ce6 into main Sep 12, 2023
26 checks passed
@muellerzr muellerzr deleted the remove-deprecate branch September 12, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants