add a `from_pipe` method to `DiffusionPipeline` (#7241) · Harshs27/diffusers@7956c36 · GitHub
Skip to content

Commit 7956c36

Browse files
yiyixuxuyiyixuxusayakpaulDN6
authored
add a from_pipe method to DiffusionPipeline (huggingface#7241)
* add from_pipe --------- Co-authored-by: yiyixuxu <yixu310@gmail,com> Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
1 parent 5266ab7 commit 7956c36

22 files changed

Lines changed: 675 additions & 63 deletions

File tree

‎docs/source/en/using-diffusers/loading.md‎

Lines changed: 204 additions & 0 deletions

‎examples/community/lpw_stable_diffusion.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ class StableDiffusionLongPromptWeightingPipeline(
439439
Model that extracts features from generated images to be used as inputs for the `safety_checker`.
440440
"""
441441

442+
model_cpu_offload_seq = "text_encoder-->unet->vae"
442443
_optional_components = ["safety_checker", "feature_extractor"]
444+
_exclude_from_cpu_offload = ["safety_checker"]
443445

444446
def __init__(
445447
self,

‎src/diffusers/models/unets/unet_motion_model.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import torch.nn as nn
1818
import torch.utils.checkpoint
1919

20-
from ...configuration_utils import ConfigMixin, register_to_config
20+
from ...configuration_utils import ConfigMixin, FrozenDict, register_to_config
2121
from ...loaders import UNet2DConditionLoadersMixin
2222
from ...utils import logging
2323
from ..attention_processor import (
@@ -393,8 +393,11 @@ def from_unet2d(
393393
):
394394
has_motion_adapter = motion_adapter is not None
395395

396+
if has_motion_adapter:
397+
motion_adapter.to(device=unet.device)
398+
396399
# based on https://github.com/guoyww/AnimateDiff/blob/895f3220c06318ea0760131ec70408b466c49333/animatediff/models/unet.py#L459
397-
config = unet.config
400+
config = dict(unet.config)
398401
config["_class_name"] = cls.__name__
399402

400403
down_blocks = []
@@ -427,6 +430,7 @@ def from_unet2d(
427430
if not config.get("num_attention_heads"):
428431
config["num_attention_heads"] = config["attention_head_dim"]
429432

433+
config = FrozenDict(config)
430434
model = cls.from_config(config)
431435

432436
if not load_weights:

‎src/diffusers/pipelines/animatediff/pipeline_animatediff.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(
131131
vae: AutoencoderKL,
132132
text_encoder: CLIPTextModel,
133133
tokenizer: CLIPTokenizer,
134-
unet: UNet2DConditionModel,
134+
unet: Union[UNet2DConditionModel, UNetMotionModel],
135135
motion_adapter: MotionAdapter,
136136
scheduler: Union[
137137
DDIMScheduler,

‎src/diffusers/pipelines/pipeline_loading_utils.py‎

Lines changed: 36 additions & 18 deletions

0 commit comments

Comments
 (0)