| 5 | |
| 6 | @comfy_node(name="DynamicConditioning") |
| 7 | class DynamicConditioning: |
| 8 | @classmethod |
| 9 | def INPUT_TYPES(s): |
| 10 | return { |
| 11 | "required": { |
| 12 | "model": ("MODEL",), |
| 13 | "power": ("FLOAT", {"default": 1.3, "min": 1, "max": 2, "step": 0.01}), |
| 14 | "only_first_frame": ("BOOLEAN", {"default": True}), |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | RETURN_TYPES = ("MODEL",) |
| 19 | FUNCTION = "apply" |
| 20 | CATEGORY = "lightricks/LTXV" |
| 21 | INIT = False |
| 22 | |
| 23 | def apply(self, model, power, only_first_frame): |
| 24 | self.only_first_frame = only_first_frame |
| 25 | self.power = power |
| 26 | model = model.clone() |
| 27 | model.set_model_denoise_mask_function(self.forward) |
| 28 | return (model,) |
| 29 | |
| 30 | def find_step(self, sigma: torch.Tensor, step_sigmas: torch.Tensor): |
| 31 | for i, step_sigma in enumerate(step_sigmas): |
| 32 | if step_sigma <= sigma: |
| 33 | return i |
| 34 | return len(step_sigmas) - 1 |
| 35 | |
| 36 | def forward( |
| 37 | self, sigma: torch.Tensor, denoise_mask: torch.Tensor, extra_options: dict |
| 38 | ): |
| 39 | model = extra_options["model"] |
| 40 | step_sigmas = extra_options["sigmas"] |
| 41 | step = self.find_step(sigma, step_sigmas) |
| 42 | # In order to apply power multiple times, this is the same as applying power number of times equal to step |
| 43 | power = self.power**step |
| 44 | denoise_mask = denoise_mask.clone() |
| 45 | if self.only_first_frame: |
| 46 | num_channels = model.model_patcher.model.diffusion_model.in_channels |
| 47 | denoise_mask[:, :num_channels, :1] **= power |
| 48 | else: |
| 49 | denoise_mask **= power |
| 50 | # make sure to update the denoise mask in the model, to get correct timestep values for all tokens |
| 51 | for k in model.conds: |
| 52 | if "positive" in k or "negative" in k: |
| 53 | for cond in model.conds[k]: |
| 54 | if "model_conds" in cond and "denoise_mask" in cond["model_conds"]: |
| 55 | cond["model_conds"]["denoise_mask"].cond = denoise_mask |
| 56 | # print(f"DynamicConditioning: power: {power}, step: {step}, sigma: {sigma}, step_sigmas: {step_sigmas}") |
| 57 | return denoise_mask |
nothing calls this directly
no outgoing calls
no test coverage detected