Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/quantization/bnb/test_4bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class Base4bitTests(unittest.TestCase):
num_inference_steps = 10
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.

torch.use_deterministic_algorithms(True)

def get_dummy_inputs(self):
prompt_embeds = load_pt(
"https://huggingface.co/datasets/hf-internal-testing/bnb-diffusers-testing-artifacts/resolve/main/prompt_embeds.pt",
Expand Down Expand Up @@ -480,7 +484,6 @@ def test_generate_quality_dequantize(self):
r"""
Test that loading the model and unquantize it produce correct results.
"""
torch.use_deterministic_algorithms(True)
self.pipeline_4bit.transformer.dequantize()
output = self.pipeline_4bit(
prompt=self.prompt,
Expand Down
5 changes: 4 additions & 1 deletion tests/quantization/bnb/test_mixed_int8.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class Base8bitTests(unittest.TestCase):
num_inference_steps = 10
seed = 0

@classmethod
def setUpClass(cls):
torch.use_deterministic_algorithms(True)

def get_dummy_inputs(self):
prompt_embeds = load_pt(
"https://huggingface.co/datasets/hf-internal-testing/bnb-diffusers-testing-artifacts/resolve/main/prompt_embeds.pt",
Expand Down Expand Up @@ -485,7 +489,6 @@ def test_generate_quality_dequantize(self):
r"""
Test that loading the model and unquantize it produce correct results.
"""
torch.use_deterministic_algorithms(True)
self.pipeline_8bit.transformer.dequantize()
output = self.pipeline_8bit(
prompt=self.prompt,
Expand Down