Skip to content

Commit 1297fab

Browse files
committed
fixes
1 parent 8c80718 commit 1297fab

File tree

4 files changed

+4
-126
lines changed

4 files changed

+4
-126
lines changed

tests/lora/test_lora_layers_cogvideox.py

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import sys
1616
import unittest
1717

18-
import numpy as np
19-
import pytest
2018
import torch
2119
from transformers import AutoTokenizer, T5EncoderModel
2220

@@ -29,16 +27,13 @@
2927
)
3028
from diffusers.utils.testing_utils import (
3129
floats_tensor,
32-
is_torch_version,
3330
require_peft_backend,
34-
skip_mps,
35-
torch_device,
3631
)
3732

3833

3934
sys.path.append(".")
4035

41-
from utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402
36+
from utils import PeftLoraLoaderMixinTests # noqa: E402
4237

4338

4439
@require_peft_backend
@@ -123,41 +118,6 @@ def get_dummy_inputs(self, with_generator=True):
123118

124119
return noise, input_ids, pipeline_inputs
125120

126-
@skip_mps
127-
@pytest.mark.xfail(
128-
condition=torch.device(torch_device).type == "cpu" and is_torch_version(">=", "2.5"),
129-
reason="Test currently fails on CPU and PyTorch 2.5.1 but not on PyTorch 2.4.1.",
130-
strict=True,
131-
)
132-
def test_lora_fuse_nan(self):
133-
for scheduler_cls in self.scheduler_classes:
134-
components, text_lora_config, denoiser_lora_config = self.get_dummy_components(scheduler_cls)
135-
pipe = self.pipeline_class(**components)
136-
pipe = pipe.to(torch_device)
137-
pipe.set_progress_bar_config(disable=None)
138-
_, _, inputs = self.get_dummy_inputs(with_generator=False)
139-
140-
pipe.transformer.add_adapter(denoiser_lora_config, "adapter-1")
141-
142-
self.assertTrue(check_if_lora_correctly_set(pipe.transformer), "Lora not correctly set in denoiser")
143-
144-
# corrupt one LoRA weight with `inf` values
145-
with torch.no_grad():
146-
pipe.transformer.transformer_blocks[0].attn1.to_q.lora_A["adapter-1"].weight += float("inf")
147-
148-
# with `safe_fusing=True` we should see an Error
149-
with self.assertRaises(ValueError):
150-
pipe.fuse_lora(components=self.pipeline_class._lora_loadable_modules, safe_fusing=True)
151-
152-
# without we should not see an error, but every image will be black
153-
pipe.fuse_lora(components=self.pipeline_class._lora_loadable_modules, safe_fusing=False)
154-
155-
out = pipe(
156-
"test", num_inference_steps=2, max_sequence_length=inputs["max_sequence_length"], output_type="np"
157-
)[0]
158-
159-
self.assertTrue(np.isnan(out).all())
160-
161121
def test_simple_inference_with_text_lora_denoiser_fused_multi(self):
162122
super().test_simple_inference_with_text_lora_denoiser_fused_multi(expected_atol=9e-3)
163123

tests/lora/test_lora_layers_hunyuanvideo.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import sys
1616
import unittest
1717

18-
import numpy as np
19-
import pytest
2018
import torch
2119
from transformers import CLIPTextModel, CLIPTokenizer, LlamaModel, LlamaTokenizerFast
2220

@@ -28,16 +26,14 @@
2826
)
2927
from diffusers.utils.testing_utils import (
3028
floats_tensor,
31-
is_torch_version,
3229
require_peft_backend,
3330
skip_mps,
34-
torch_device,
3531
)
3632

3733

3834
sys.path.append(".")
3935

40-
from utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402
36+
from utils import PeftLoraLoaderMixinTests # noqa: E402
4137

4238

4339
@require_peft_backend
@@ -144,46 +140,6 @@ def get_dummy_inputs(self, with_generator=True):
144140

145141
return noise, input_ids, pipeline_inputs
146142

147-
@pytest.mark.xfail(
148-
condition=torch.device(torch_device).type == "cpu" and is_torch_version(">=", "2.5"),
149-
reason="Test currently fails on CPU and PyTorch 2.5.1 but not on PyTorch 2.4.1.",
150-
strict=True,
151-
)
152-
def test_lora_fuse_nan(self):
153-
for scheduler_cls in self.scheduler_classes:
154-
components, text_lora_config, denoiser_lora_config = self.get_dummy_components(scheduler_cls)
155-
pipe = self.pipeline_class(**components)
156-
pipe = pipe.to(torch_device)
157-
pipe.set_progress_bar_config(disable=None)
158-
_, _, inputs = self.get_dummy_inputs(with_generator=False)
159-
160-
pipe.transformer.add_adapter(denoiser_lora_config, "adapter-1")
161-
162-
self.assertTrue(check_if_lora_correctly_set(pipe.transformer), "Lora not correctly set in denoiser")
163-
164-
# corrupt one LoRA weight with `inf` values
165-
with torch.no_grad():
166-
pipe.transformer.transformer_blocks[0].attn.to_q.lora_A["adapter-1"].weight += float("inf")
167-
168-
# with `safe_fusing=True` we should see an Error
169-
with self.assertRaises(ValueError):
170-
pipe.fuse_lora(components=self.pipeline_class._lora_loadable_modules, safe_fusing=True)
171-
172-
# without we should not see an error, but every image will be black
173-
pipe.fuse_lora(components=self.pipeline_class._lora_loadable_modules, safe_fusing=False)
174-
175-
out = pipe(
176-
prompt=inputs["prompt"],
177-
height=inputs["height"],
178-
width=inputs["width"],
179-
num_frames=inputs["num_frames"],
180-
num_inference_steps=inputs["num_inference_steps"],
181-
max_sequence_length=inputs["max_sequence_length"],
182-
output_type="np",
183-
)[0]
184-
185-
self.assertTrue(np.isnan(out).all())
186-
187143
def test_simple_inference_with_text_lora_denoiser_fused_multi(self):
188144
super().test_simple_inference_with_text_lora_denoiser_fused_multi(expected_atol=9e-3)
189145

tests/lora/test_lora_layers_mochi.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,20 @@
1515
import sys
1616
import unittest
1717

18-
import numpy as np
19-
import pytest
2018
import torch
2119
from transformers import AutoTokenizer, T5EncoderModel
2220

2321
from diffusers import AutoencoderKLMochi, FlowMatchEulerDiscreteScheduler, MochiPipeline, MochiTransformer3DModel
2422
from diffusers.utils.testing_utils import (
2523
floats_tensor,
26-
is_torch_version,
2724
require_peft_backend,
2825
skip_mps,
29-
torch_device,
3026
)
3127

3228

3329
sys.path.append(".")
3430

35-
from utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa: E402
31+
from utils import PeftLoraLoaderMixinTests # noqa: E402
3632

3733

3834
@require_peft_backend
@@ -103,40 +99,6 @@ def get_dummy_inputs(self, with_generator=True):
10399

104100
return noise, input_ids, pipeline_inputs
105101

106-
@pytest.mark.xfail(
107-
condition=torch.device(torch_device).type == "cpu" and is_torch_version(">=", "2.5"),
108-
reason="Test currently fails on CPU and PyTorch 2.5.1 but not on PyTorch 2.4.1.",
109-
strict=True,
110-
)
111-
def test_lora_fuse_nan(self):
112-
for scheduler_cls in self.scheduler_classes:
113-
components, text_lora_config, denoiser_lora_config = self.get_dummy_components(scheduler_cls)
114-
pipe = self.pipeline_class(**components)
115-
pipe = pipe.to(torch_device)
116-
pipe.set_progress_bar_config(disable=None)
117-
_, _, inputs = self.get_dummy_inputs(with_generator=False)
118-
119-
pipe.transformer.add_adapter(denoiser_lora_config, "adapter-1")
120-
121-
self.assertTrue(check_if_lora_correctly_set(pipe.transformer), "Lora not correctly set in denoiser")
122-
123-
# corrupt one LoRA weight with `inf` values
124-
with torch.no_grad():
125-
pipe.transformer.transformer_blocks[0].attn1.to_q.lora_A["adapter-1"].weight += float("inf")
126-
127-
# with `safe_fusing=True` we should see an Error
128-
with self.assertRaises(ValueError):
129-
pipe.fuse_lora(components=self.pipeline_class._lora_loadable_modules, safe_fusing=True)
130-
131-
# without we should not see an error, but every image will be black
132-
pipe.fuse_lora(components=self.pipeline_class._lora_loadable_modules, safe_fusing=False)
133-
134-
out = pipe(
135-
"test", num_inference_steps=2, max_sequence_length=inputs["max_sequence_length"], output_type="np"
136-
)[0]
137-
138-
self.assertTrue(np.isnan(out).all())
139-
140102
def test_simple_inference_with_text_lora_denoiser_fused_multi(self):
141103
super().test_simple_inference_with_text_lora_denoiser_fused_multi(expected_atol=9e-3)
142104

tests/lora/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ def test_simple_inference_with_text_denoiser_multi_adapter_weighted(self):
15281528
@pytest.mark.xfail(
15291529
condition=torch.device(torch_device).type == "cpu" and is_torch_version(">=", "2.5"),
15301530
reason="Test currently fails on CPU and PyTorch 2.5.1 but not on PyTorch 2.4.1.",
1531-
strict=True,
1531+
strict=False,
15321532
)
15331533
def test_lora_fuse_nan(self):
15341534
for scheduler_cls in self.scheduler_classes:

0 commit comments

Comments
 (0)