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

add bnb test marker #3022

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Titus-von-Koeller
Copy link

Small utility to easily all tests that require bnb..

Unfortunately I'm on my Intel box right now and also don't have a fully functioning dev setup for accelerate. I think this should work as is, but be sure to give it a quick spin, as I can't execute the tests in my current setup.

@HuggingFaceDocBuilderDev

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.

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

This looks very nice! Small suggestion for cleaning things up some

(I can follow up where then we expand this to our other suites, e.g. FSDP, DeepSpeed, big model inference, core)

Comment on lines +258 to +266
if is_bnb_available():
try:
import pytest

return pytest.mark.bnb(test_case)
except ImportError:
return test_case
else:
return unittest.skip("test requires the bitsandbytes library")(test_case)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can simplify this quite a lot by having the following at the top of the file:

from .imports import is_pytest_available
if is_pytest_available():
    from pytest import mark

And then in the code:

    if is_bnb_available():
        return mark.bnb(test_case)
    return unittest.skip("test requires the bitsandbytes library")(test_case)

Copy link
Author

Choose a reason for hiding this comment

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

Wouldn't that throw an exception if someone would run the test suite without pytest present? I mean this whole discussion is a bit weird, I think we should just commit to pytest fully and that's it, but if we want to support people running without pytest as a runner, then we gotta leave it as is, imo...

Actually in Transformers I also bumped into a bunch of pytest things that would throw an exception if the test suite wouldn't be run with pytest, but seems noone does that anyways..

Copy link
Collaborator

Choose a reason for hiding this comment

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

Our test suite is pytest + unittest. It's required in our test requirements in the .py:

extras["test_prod"] = ["pytest>=7.2.0,<=8.0.0", "pytest-xdist", "pytest-subtests", "parameterized"]

And correct, we only run our tests inside unittest.TestCases :) (Explicit pytest tests are reserved in accelerate only in /src/accelerate/test_utils/scripts

Copy link
Author

Choose a reason for hiding this comment

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

Ok, so if we assume pytest is a hard requirement, then we don't need is_pytest_available(), right? We could just go ahead and import it. In case we assume someone might need to run these tests without pytest, then I think we need the code unmodified as I provided it (because in your suggestion mark would then be undefined, right?), unless I misunderstand sth?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a hard requirement, but this code exists in the base project. So it's still a test requirement and we need the check at the top :)

Copy link
Member

Choose a reason for hiding this comment

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

Maybe I misunderstand your suggestion, Zach, but in case pytest is not installed, mark would be undefined, right? This would not lead to an error as long as require_bnb is only called inside of tests, which require pytest as a runner. But would this not possibly be detected as a linting error, as the linter cannot know this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. Agreed (was chatting offline with Titus about it).

I think it'd be fine if we did:

if bnb_available() and is_pytest_available():
   ...
return unittest....

Honestly it could be even simpler and we abstract out the pytest + unittest logic

Copy link
Author

Choose a reason for hiding this comment

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

we did some brainstorming and after some back and forth came up with a very nice generic solution to apply markers for all requires_sth

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.

Thanks, LGTM, good discussion.

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