Skip to content

Commit 4bc49f9

Browse files
committed
update
1 parent 7833ed9 commit 4bc49f9

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/diffusers/loaders/single_file_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ..utils import deprecate, is_accelerate_available, logging
2323
from .single_file_utils import (
2424
SingleFileComponentError,
25+
convert_animatediff_checkpoint_to_diffusers,
2526
convert_controlnet_checkpoint,
2627
convert_ldm_unet_checkpoint,
2728
convert_ldm_vae_checkpoint,
@@ -70,6 +71,9 @@
7071
"checkpoint_mapping_fn": convert_sd3_transformer_checkpoint_to_diffusers,
7172
"default_subfolder": "transformer",
7273
},
74+
"MotionAdapter": {
75+
"checkpoint_mapping_fn": convert_animatediff_checkpoint_to_diffusers,
76+
},
7377
}
7478

7579

src/diffusers/loaders/single_file_utils.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
"stable_cascade_stage_b": "down_blocks.1.0.channelwise.0.weight",
7575
"stable_cascade_stage_c": "clip_txt_mapper.weight",
7676
"sd3": "model.diffusion_model.joint_blocks.0.context_block.adaLN_modulation.1.bias",
77+
"animatediff": "down_blocks.0.motion_modules.0.temporal_transformer.norm.weight",
78+
"animatediff_v2": "mid_block.motion_modules.0.temporal_transformer.norm.bias",
79+
"animatediff_sdxl_beta": "down_blocks.3.motion_modules.0.temporal_transformer.norm.bias",
7780
}
7881

7982
DIFFUSERS_DEFAULT_PIPELINE_PATHS = {
@@ -103,6 +106,9 @@
103106
"sd3": {
104107
"pretrained_model_name_or_path": "stabilityai/stable-diffusion-3-medium-diffusers",
105108
},
109+
"animatediff_v2": "guoyww/animatediff-motion-adapter-v1-5-2",
110+
"animatediff_v3": "guoyww/animatediff-motion-adapter-v1-5-3",
111+
"animatediff_sdxl": "guoyww/animatediff-motion-adapter-sdxl-beta",
106112
}
107113

108114
# Use to configure model sample size when original config is provided
@@ -485,6 +491,13 @@ def infer_diffusers_model_type(checkpoint):
485491
elif CHECKPOINT_KEY_NAMES["sd3"] in checkpoint:
486492
model_type = "sd3"
487493

494+
elif CHECKPOINT_KEY_NAMES["animatediff"] in checkpoint:
495+
if CHECKPOINT_KEY_NAMES["animatediff_v2"] in checkpoint:
496+
model_type = "animatediff_v2"
497+
elif CHECKPOINT_KEY_NAMES["animatediff_sdxl_beta"] in checkpoint:
498+
model_type = "animatediff_sdxl_beta"
499+
else:
500+
model_type = "animatediff_v3"
488501
else:
489502
model_type = "v1"
490503

@@ -1822,3 +1835,22 @@ def create_diffusers_t5_model_from_checkpoint(
18221835
param.data = param.data.to(torch.float32)
18231836

18241837
return model
1838+
1839+
1840+
def convert_animatediff_checkpoint_to_diffusers(checkpoint, **kwargs):
1841+
converted_state_dict = {}
1842+
for k, v in checkpoint.items():
1843+
if "pos_encoder" in k:
1844+
continue
1845+
1846+
else:
1847+
converted_state_dict[
1848+
k.replace(".norms.0", ".norm1")
1849+
.replace(".norms.1", ".norm2")
1850+
.replace(".ff_norm", ".norm3")
1851+
.replace(".attention_blocks.0", ".attn1")
1852+
.replace(".attention_blocks.1", ".attn2")
1853+
.replace(".temporal_transformer", "")
1854+
] = v
1855+
1856+
return converted_state_dict

src/diffusers/models/unets/unet_motion_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import torch.utils.checkpoint
2020

2121
from ...configuration_utils import ConfigMixin, FrozenDict, register_to_config
22-
from ...loaders import UNet2DConditionLoadersMixin
22+
from ...loaders import FromOriginalModelMixin, UNet2DConditionLoadersMixin
2323
from ...utils import logging
2424
from ..attention_processor import (
2525
ADDED_KV_ATTENTION_PROCESSORS,
@@ -93,7 +93,7 @@ def __init__(
9393
)
9494

9595

96-
class MotionAdapter(ModelMixin, ConfigMixin):
96+
class MotionAdapter(ModelMixin, ConfigMixin, FromOriginalModelMixin):
9797
@register_to_config
9898
def __init__(
9999
self,

0 commit comments

Comments
 (0)