Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import tempfile
|
|
7 |
import numpy as np
|
8 |
import cv2
|
9 |
import subprocess
|
10 |
-
|
11 |
from diffusers import AnimateDiffPipeline, MotionAdapter, EulerDiscreteScheduler
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
from safetensors.torch import load_file
|
@@ -34,6 +34,22 @@ dtype = torch.float16
|
|
34 |
pipe = AnimateDiffPipeline.from_pretrained(bases[base_loaded], torch_dtype=dtype).to(device)
|
35 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# ----------------------------- VIDEO ENCODING ---------------------------------
|
38 |
# Unfortunately, the Hugging Face Diffusers utils hardcode MP4V as a codec,
|
39 |
# which is not supported by all browsers. This is a critical issue for AiTube,
|
|
|
7 |
import numpy as np
|
8 |
import cv2
|
9 |
import subprocess
|
10 |
+
from DeepCache import DeepCacheSDHelper
|
11 |
from diffusers import AnimateDiffPipeline, MotionAdapter, EulerDiscreteScheduler
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
from safetensors.torch import load_file
|
|
|
34 |
pipe = AnimateDiffPipeline.from_pretrained(bases[base_loaded], torch_dtype=dtype).to(device)
|
35 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
|
36 |
|
37 |
+
|
38 |
+
# Note Julian: I'm not sure this works well when the pipeline changes dynamically.. to check
|
39 |
+
helper = DeepCacheSDHelper(pipe=pipe)
|
40 |
+
helper.set_params(
|
41 |
+
# cache_interval means the frequency of feature caching, specified as the number of steps between each cache operation.
|
42 |
+
|
43 |
+
cache_interval=3,
|
44 |
+
|
45 |
+
# cache_branch_id identifies which branch of the network (ordered from the shallowest to the deepest layer) is responsible for executing the caching processes.
|
46 |
+
cache_branch_id=0,
|
47 |
+
|
48 |
+
# Opting for a lower cache_branch_id or a larger cache_interval can lead to faster inference speed at the expense of reduced image quality
|
49 |
+
#(ablation experiments of these two hyperparameters can be found in the paper).
|
50 |
+
)
|
51 |
+
helper.enable()
|
52 |
+
|
53 |
# ----------------------------- VIDEO ENCODING ---------------------------------
|
54 |
# Unfortunately, the Hugging Face Diffusers utils hardcode MP4V as a codec,
|
55 |
# which is not supported by all browsers. This is a critical issue for AiTube,
|