KEMBAR78
enable deterministic in bnb 4 bit tests by jiqing-feng · Pull Request #11738 · huggingface/diffusers · GitHub
Skip to content

Conversation

@jiqing-feng
Copy link
Contributor

The motivation is that I can pass all tests when running pytest -rA tests/quantization/bnb/test_4bit.py, but failed on pytest -rA tests/quantization/bnb/test_4bit.py::ExtendedSerializationTest. That's because running all tests will trigger torch.use_deterministic_algorithms(True), and it will have impact on all the following tests. So the correct way should be calling this function at the setup stage.

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
@jiqing-feng
Copy link
Contributor Author

Hi @sayakpaul , could you please review this PR? Thanks!

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Should it not be propagated to test_mixed_int8.py as well?

@jiqing-feng
Copy link
Contributor Author

Should it not be propagated to test_mixed_int8.py as well?

Right, fixed.

@jiqing-feng jiqing-feng requested a review from sayakpaul June 19, 2025 05:05
@jiqing-feng jiqing-feng marked this pull request as draft June 19, 2025 05:07
@jiqing-feng
Copy link
Contributor Author

Hold on for a while, need to recheck if it works.

@jiqing-feng jiqing-feng marked this pull request as ready for review June 19, 2025 05:20
@jiqing-feng
Copy link
Contributor Author

Hi @sayakpaul . I have verified this PR on both test_4bit.py and test_mixed_int8.py, and they work well. Please review the new changes. Thanks!

seed = 0

@classmethod
def setUpClass(cls):
Copy link
Member

Choose a reason for hiding this comment

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

Where is this method called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The @classmethod method setUpClass() is automatically called once per test class, before any test methods run.

Copy link
Member

Choose a reason for hiding this comment

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

We have this:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setUp will be called before each test module but setUpClass will be called only once before all test modules in a test class. For torch.use_deterministic_algorithms(True), we only need called once so it's better in the setUpClass.

@sayakpaul sayakpaul merged commit ee40088 into huggingface:main Jun 23, 2025
8 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.

2 participants