Skip to content

Commit 4f92293

Browse files
authored
Merge branch 'main' into issue221
2 parents 93cc35f + 1cb73cb commit 4f92293

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

src/diffusers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@
860860
EulerDiscreteScheduler,
861861
FlowMatchEulerDiscreteScheduler,
862862
FlowMatchHeunDiscreteScheduler,
863+
FlowMatchLCMScheduler,
863864
HeunDiscreteScheduler,
864865
IPNDMScheduler,
865866
KarrasVeScheduler,

src/diffusers/loaders/lora_conversion_utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ def _maybe_map_sgm_blocks_to_diffusers(state_dict, unet_config, delimiter="_", b
3333
# 1. get all state_dict_keys
3434
all_keys = list(state_dict.keys())
3535
sgm_patterns = ["input_blocks", "middle_block", "output_blocks"]
36+
not_sgm_patterns = ["down_blocks", "mid_block", "up_blocks"]
37+
38+
# check if state_dict contains both patterns
39+
contains_sgm_patterns = False
40+
contains_not_sgm_patterns = False
41+
for key in all_keys:
42+
if any(p in key for p in sgm_patterns):
43+
contains_sgm_patterns = True
44+
elif any(p in key for p in not_sgm_patterns):
45+
contains_not_sgm_patterns = True
46+
47+
# if state_dict contains both patterns, remove sgm
48+
# we can then return state_dict immediately
49+
if contains_sgm_patterns and contains_not_sgm_patterns:
50+
for key in all_keys:
51+
if any(p in key for p in sgm_patterns):
52+
state_dict.pop(key)
53+
return state_dict
3654

3755
# 2. check if needs remapping, if not return original dict
3856
is_in_sgm_format = False
@@ -126,7 +144,7 @@ def _maybe_map_sgm_blocks_to_diffusers(state_dict, unet_config, delimiter="_", b
126144
)
127145
new_state_dict[new_key] = state_dict.pop(key)
128146

129-
if len(state_dict) > 0:
147+
if state_dict:
130148
raise ValueError("At this point all state dict entries have to be converted.")
131149

132150
return new_state_dict

src/diffusers/pipelines/hidream_image/pipeline_hidream_image.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
```py
3737
>>> import torch
3838
>>> from transformers import PreTrainedTokenizerFast, LlamaForCausalLM
39-
>>> from diffusers import UniPCMultistepScheduler, HiDreamImagePipeline, HiDreamImageTransformer2DModel
39+
>>> from diffusers import UniPCMultistepScheduler, HiDreamImagePipeline
4040
4141
>>> scheduler = UniPCMultistepScheduler(
4242
... flow_shift=3.0, prediction_type="flow_prediction", use_flow_sigmas=True
@@ -50,16 +50,11 @@
5050
... torch_dtype=torch.bfloat16,
5151
... )
5252
53-
>>> transformer = HiDreamImageTransformer2DModel.from_pretrained(
54-
... "HiDream-ai/HiDream-I1-Full", subfolder="transformer", torch_dtype=torch.bfloat16
55-
... )
56-
5753
>>> pipe = HiDreamImagePipeline.from_pretrained(
5854
... "HiDream-ai/HiDream-I1-Full",
5955
... scheduler=scheduler,
6056
... tokenizer_4=tokenizer_4,
6157
... text_encoder_4=text_encoder_4,
62-
... transformer=transformer,
6358
... torch_dtype=torch.bfloat16,
6459
... )
6560
>>> pipe.enable_model_cpu_offload()

src/diffusers/schedulers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
_import_structure["scheduling_euler_discrete"] = ["EulerDiscreteScheduler"]
6161
_import_structure["scheduling_flow_match_euler_discrete"] = ["FlowMatchEulerDiscreteScheduler"]
6262
_import_structure["scheduling_flow_match_heun_discrete"] = ["FlowMatchHeunDiscreteScheduler"]
63+
_import_structure["scheduling_flow_match_lcm"] = ["FlowMatchLCMScheduler"]
6364
_import_structure["scheduling_heun_discrete"] = ["HeunDiscreteScheduler"]
6465
_import_structure["scheduling_ipndm"] = ["IPNDMScheduler"]
6566
_import_structure["scheduling_k_dpm_2_ancestral_discrete"] = ["KDPM2AncestralDiscreteScheduler"]
@@ -161,6 +162,7 @@
161162
from .scheduling_euler_discrete import EulerDiscreteScheduler
162163
from .scheduling_flow_match_euler_discrete import FlowMatchEulerDiscreteScheduler
163164
from .scheduling_flow_match_heun_discrete import FlowMatchHeunDiscreteScheduler
165+
from .scheduling_flow_match_lcm import FlowMatchLCMScheduler
164166
from .scheduling_heun_discrete import HeunDiscreteScheduler
165167
from .scheduling_ipndm import IPNDMScheduler
166168
from .scheduling_k_dpm_2_ancestral_discrete import KDPM2AncestralDiscreteScheduler

src/diffusers/utils/dummy_pt_objects.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,21 @@ def from_pretrained(cls, *args, **kwargs):
17631763
requires_backends(cls, ["torch"])
17641764

17651765

1766+
class FlowMatchLCMScheduler(metaclass=DummyObject):
1767+
_backends = ["torch"]
1768+
1769+
def __init__(self, *args, **kwargs):
1770+
requires_backends(self, ["torch"])
1771+
1772+
@classmethod
1773+
def from_config(cls, *args, **kwargs):
1774+
requires_backends(cls, ["torch"])
1775+
1776+
@classmethod
1777+
def from_pretrained(cls, *args, **kwargs):
1778+
requires_backends(cls, ["torch"])
1779+
1780+
17661781
class HeunDiscreteScheduler(metaclass=DummyObject):
17671782
_backends = ["torch"]
17681783

tests/pipelines/kolors/test_kolors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ def test_save_load_float16(self):
145145
super().test_save_load_float16(expected_max_diff=2e-1)
146146

147147
def test_inference_batch_single_identical(self):
148-
self._test_inference_batch_single_identical(expected_max_diff=5e-4)
148+
self._test_inference_batch_single_identical(expected_max_diff=5e-3)

0 commit comments

Comments
 (0)