From bc3ebe0943d0ff324800103ce0cdcdd636ca5839 Mon Sep 17 00:00:00 2001 From: Jedrzej Kosinski Date: Wed, 22 Jan 2025 19:42:10 -0600 Subject: [PATCH 1/2] Make CustomCFGKeyframe's effective_guarantee_steps check handle start_percent=0.0 better --- animatediff/sample_settings.py | 10 ++++++---- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/animatediff/sample_settings.py b/animatediff/sample_settings.py index 5f0adde..638e7c5 100644 --- a/animatediff/sample_settings.py +++ b/animatediff/sample_settings.py @@ -612,9 +612,9 @@ def __init__(self, cfg_multival: Union[float, Tensor], start_percent=0.0, guaran def get_effective_guarantee_steps(self, max_sigma: torch.Tensor): '''If keyframe starts before current sampling range (max_sigma), treat as 0.''' - if self.start_t > max_sigma: - return 0 - return self.guarantee_steps + if torch.allclose(self.start_t, max_sigma) or self.start_t < max_sigma: + return self.guarantee_steps + return 0 def clone(self): c = CustomCFGKeyframe(cfg_multival=self.cfg_multival, @@ -664,7 +664,9 @@ def clone(self): def initialize_timesteps(self, model: BaseModel): for keyframe in self.keyframes: - keyframe.start_t = model.model_sampling.percent_to_sigma(keyframe.start_percent) + to_assign = model.model_sampling.percent_to_sigma(keyframe.start_percent) + if keyframe.start_percent == 0.0 and to_assign > model.model_sampling.sigma_max: + keyframe.start_t = model.model_sampling.sigma_max def prepare_current_keyframe(self, t: Tensor, transformer_options: dict[str, Tensor]): curr_t: float = t[0] diff --git a/pyproject.toml b/pyproject.toml index f867f28..537e762 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-animatediff-evolved" description = "Improved AnimateDiff integration for ComfyUI." -version = "1.4.1" +version = "1.4.2" license = { file = "LICENSE" } dependencies = [] From 11cd8453d219915f9080dcc56f466a535d7e2ee4 Mon Sep 17 00:00:00 2001 From: Jedrzej Kosinski Date: Wed, 22 Jan 2025 19:53:27 -0600 Subject: [PATCH 2/2] Fixed bugs with previous commit --- animatediff/sample_settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/animatediff/sample_settings.py b/animatediff/sample_settings.py index 638e7c5..477452b 100644 --- a/animatediff/sample_settings.py +++ b/animatediff/sample_settings.py @@ -664,9 +664,11 @@ def clone(self): def initialize_timesteps(self, model: BaseModel): for keyframe in self.keyframes: - to_assign = model.model_sampling.percent_to_sigma(keyframe.start_percent) + to_assign = torch.tensor(model.model_sampling.percent_to_sigma(keyframe.start_percent), device=model.model_sampling.sigma_max.device) if keyframe.start_percent == 0.0 and to_assign > model.model_sampling.sigma_max: keyframe.start_t = model.model_sampling.sigma_max + else: + keyframe.start_t = to_assign def prepare_current_keyframe(self, t: Tensor, transformer_options: dict[str, Tensor]): curr_t: float = t[0]