hyejin.shin
commited on
Commit
·
23715a0
1
Parent(s):
000f1fd
add readme
Browse files- README.md +110 -0
- scheduler/scheduler_config.json +0 -1
README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# How to make this
|
| 2 |
+
|
| 3 |
+
- pretrained model: [epiCRealism](https://civitai.com/models/25694?modelVersionId=134065) + [hyper CFG lora 12steps](https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SD15-12steps-CFG-lora.safetensors)
|
| 4 |
+
-> merge with lora weight 0.3
|
| 5 |
+
- lora model: [AnimateLCM_sd15_t2v_lora.safetensors](https://huggingface.co/wangfuyun/AnimateLCM/blob/main/AnimateLCM_sd15_t2v_lora.safetensors)
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
|
| 11 |
+
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
|
| 12 |
+
|
| 13 |
+
from animatediff.models.unet import UNet3DConditionModel
|
| 14 |
+
from animatediff.models.sparse_controlnet import SparseControlNetModel
|
| 15 |
+
from animatediff.pipelines.pipeline_animation import AnimationPipeline
|
| 16 |
+
from animatediff.utils.util import load_weights
|
| 17 |
+
|
| 18 |
+
sdpipe = StableDiffusionPipeline.from_single_file(pretrained_model_path, use_safetensors=True, add_watermarker=False).to(dtype=torch.float16)
|
| 19 |
+
sdpipe.load_lora_weights(lora_model_path)
|
| 20 |
+
sdpipe.fuse_lora(lora_scale=0.3)
|
| 21 |
+
|
| 22 |
+
text_encoder = sdpipe.text_encoder.cuda()
|
| 23 |
+
vae = sdpipe.vae.cuda()
|
| 24 |
+
tokenizer = sdpipe.tokenizer
|
| 25 |
+
|
| 26 |
+
unet_additional_kwargs = params["unet_additional_kwargs"]
|
| 27 |
+
controlnet_additional_kwargs = params["controlnet_additional_kwargs"]
|
| 28 |
+
|
| 29 |
+
unet = UNet3DConditionModel.from_pretrained_2d(pretrained_model_path, subfolder="unet", unet_config=sdpipe.unet.config, unet_additional_kwargs=unet_additional_kwargs).cuda()
|
| 30 |
+
unet.config.num_attention_heads = 8
|
| 31 |
+
unet.config.projection_class_embeddings_input_dim = None
|
| 32 |
+
unet.to(dtype=torch.float16)
|
| 33 |
+
|
| 34 |
+
controlnet = SparseControlNetModel.from_unet(unet, controlnet_additional_kwargs=controlnet_additional_kwargs)
|
| 35 |
+
controlnet_path = "models/motion_module/v3_sd15_sparsectrl_rgb.ckpt"
|
| 36 |
+
|
| 37 |
+
print(f"loading controlnet checkpoint from {controlnet_path} ...")
|
| 38 |
+
controlnet_state_dict = torch.load(controlnet_path, map_location="cpu")
|
| 39 |
+
controlnet_state_dict = controlnet_state_dict["controlnet"] if "controlnet" in controlnet_state_dict else controlnet_state_dict
|
| 40 |
+
controlnet_state_dict = {name: param for name, param in controlnet_state_dict.items() if "pos_encoder.pe" not in name}
|
| 41 |
+
controlnet_state_dict.pop("animatediff_config", "")
|
| 42 |
+
controlnet.load_state_dict(controlnet_state_dict)
|
| 43 |
+
controlnet.to(dtype=torch.float16)
|
| 44 |
+
controlnet.cuda()
|
| 45 |
+
|
| 46 |
+
pipe = load_weights(
|
| 47 |
+
pipeline,
|
| 48 |
+
# motion module
|
| 49 |
+
motion_module_path = "models/Motion_Module/v3_sd15_mm.ckpt",
|
| 50 |
+
motion_module_lora_configs = [],
|
| 51 |
+
# domain adapter
|
| 52 |
+
adapter_lora_path = "models/Motion_Module/v3_sd15_adapter.ckpt",
|
| 53 |
+
adapter_lora_scale = 1.0,
|
| 54 |
+
# image layers
|
| 55 |
+
dreambooth_model_path = pretrained_model_path,
|
| 56 |
+
lora_model_path = "",
|
| 57 |
+
lora_alpha = 0.8,
|
| 58 |
+
).to("cuda")
|
| 59 |
+
pipe.to(dtype=torch.float16)
|
| 60 |
+
pipe.enable_vae_slicing()
|
| 61 |
+
pipe.enable_model_cpu_offload()
|
| 62 |
+
|
| 63 |
+
pipe.scheduler = DPMSolverMultistepScheduler(
|
| 64 |
+
beta_start = 0.00075,
|
| 65 |
+
beta_end = 0.0145,
|
| 66 |
+
beta_schedule = "linear",
|
| 67 |
+
use_karras_sigmas = True,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
# How to use this
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
controlnet_additional_kwargs = params["controlnet_additional_kwargs"]
|
| 76 |
+
|
| 77 |
+
pipe = AnimationPipeline.from_pretrained("models/animatediff_model")
|
| 78 |
+
unet = pipe.unet
|
| 79 |
+
vae = pipe.vae
|
| 80 |
+
|
| 81 |
+
unet.config.num_attention_heads = 8
|
| 82 |
+
unet.config.projection_class_embeddings_input_dim = None
|
| 83 |
+
unet.to(dtype=torch.float16)
|
| 84 |
+
|
| 85 |
+
controlnet = SparseControlNetModel.from_unet(unet, controlnet_additional_kwargs=controlnet_additional_kwargs)
|
| 86 |
+
controlnet_path = "./models/motion_module/v3_sd15_sparsectrl_rgb.ckpt"
|
| 87 |
+
|
| 88 |
+
print(f"loading controlnet checkpoint from {controlnet_path} ...")
|
| 89 |
+
controlnet_state_dict = torch.load(controlnet_path, map_location="cpu")
|
| 90 |
+
controlnet_state_dict = controlnet_state_dict["controlnet"] if "controlnet" in controlnet_state_dict else controlnet_state_dict
|
| 91 |
+
controlnet_state_dict = {name: param for name, param in controlnet_state_dict.items() if "pos_encoder.pe" not in name}
|
| 92 |
+
controlnet_state_dict.pop("animatediff_config", "")
|
| 93 |
+
controlnet.load_state_dict(controlnet_state_dict)
|
| 94 |
+
controlnet.to(dtype=torch.float16)
|
| 95 |
+
controlnet.cuda()
|
| 96 |
+
|
| 97 |
+
pipe.controlnet = controlnet
|
| 98 |
+
|
| 99 |
+
without_xformers = False
|
| 100 |
+
if is_xformers_available() and (not without_xformers):
|
| 101 |
+
unet.enable_xformers_memory_efficient_attention()
|
| 102 |
+
if controlnet is not None:
|
| 103 |
+
print("\nenable_xformers_memory_efficient_attention\n")
|
| 104 |
+
controlnet.enable_xformers_memory_efficient_attention()
|
| 105 |
+
|
| 106 |
+
pipe.to(dtype=torch.float16)
|
| 107 |
+
pipe.enable_vae_slicing()
|
| 108 |
+
pipe.enable_model_cpu_offload()
|
| 109 |
+
pipe.to("cuda")
|
| 110 |
+
```
|
scheduler/scheduler_config.json
CHANGED
|
@@ -8,7 +8,6 @@
|
|
| 8 |
"dynamic_thresholding_ratio": 0.995,
|
| 9 |
"euler_at_final": false,
|
| 10 |
"final_sigmas_type": "zero",
|
| 11 |
-
"lambda_min_clipped": -Infinity,
|
| 12 |
"lower_order_final": true,
|
| 13 |
"num_train_timesteps": 1000,
|
| 14 |
"prediction_type": "epsilon",
|
|
|
|
| 8 |
"dynamic_thresholding_ratio": 0.995,
|
| 9 |
"euler_at_final": false,
|
| 10 |
"final_sigmas_type": "zero",
|
|
|
|
| 11 |
"lower_order_final": true,
|
| 12 |
"num_train_timesteps": 1000,
|
| 13 |
"prediction_type": "epsilon",
|