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

provide temp flag for outside libs to detect multi-backend preview #1243

Conversation

Titus-von-Koeller
Copy link
Collaborator

@Titus-von-Koeller Titus-von-Koeller commented Jun 6, 2024

After internal discussion how to handle this Transformers issue that came up when trying to test the alpha release in conjunction with the HF ecosystem, this is a simple approach that could help outside libs detect if they're dealing with the BNB preview version.

Wdyt @younesbelkada @akx @matthewdouglas ?

Hmm, maybe setting it to True is cleaner.. Thought of the str before adding the extensive comment..

Added this snippet to bnb/__init__.py:

# NOTE: this is a temporary flag to allow outside libraries to employ conditional logic while the refactor is still in
# alpha/beta: sth like `if getattr(bitsandbytes, "is_multi_backend_refactor_preview", False): do sth`
# the getattr() call above would default to False and any string evaluates to True. This way we have temporary thing
# that we can remove in Transformers with the next release after the official BNB multi-platform release; then
# eventually making it the new default (e.g. just remove if statement and dedent in Transformers)
is_multi_backend_refactor_preview = "TO BE REMOVED ONCE MERGED TO `main`"  # bool evals to True for str
In [1]: import bitsandbytes as bnb

In [2]: bnb.is_multi_backend_refactor_preview
Out[2]: 'TO BE REMOVED ONCE MERGED TO `main`'

In [3]: bool(getattr(bnb, "is_multi_backend_refactor_preview", False))
Out[3]: True

In [4]: del bnb.is_multi_backend_refactor_preview  # not defined on `main`

In [5]: getattr(bnb, "is_multi_backend_refactor_preview", False)
Out[5]: False

Copy link
Collaborator

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks a lot !

Co-authored-by: Benjamin Bossan <BenjaminBossan@users.noreply.github.com>
Comment on lines +23 to +28
# NOTE: this is a temporary flag to allow outside libraries to employ conditional logic while the refactor is still in
# alpha/beta: sth like `if getattr(bitsandbytes, "is_multi_backend_refactor_preview", False): do sth`
# the getattr() call above would default to False and any string evaluates to True. This way we have temporary thing
# that we can remove in Transformers with the next release after the official BNB multi-platform release; then
# eventually making it the new default (e.g. just remove if statement and dedent in Transformers)
is_multi_backend_refactor_preview = "TO BE REMOVED ONCE MERGED TO `main`" # bool evals to True for str
Copy link
Contributor

Choose a reason for hiding this comment

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

If we wanted to make this a more permanent feature (and I don't see why not), it could just be e.g. features = {"multi_backend"}...

@Titus-von-Koeller Titus-von-Koeller merged commit c79b1e9 into bitsandbytes-foundation:multi-backend-refactor Jun 21, 2024
1 of 2 checks passed
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.

4 participants