├── .gitignore
├── nodes
├── modify_hy_model_node.py
├── hy_feta_enhance_node.py
├── hy_attn_override_node.py
├── hy_model_pred_nodes.py
├── rectified_sampler_nodes.py
├── hy_regional_cond_nodes.py
├── flowedit_nodes.py
├── flow_edit_nodes.py
└── wrapper_flow_edit_nodes.py
├── utils
├── mask_utils.py
├── feta_enhance_utils.py
├── latent_preview.py
└── rope_utils.py
├── __init__.py
├── README.md
├── modules
├── hy_layers.py
└── hy_model.py
├── example_workflows
├── example_hy_flowedit.json
├── wrapper_example_hunyuan_flowedit.json
└── example_hy_regional_prompting_t2v.json
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/nodes/modify_hy_model_node.py:
--------------------------------------------------------------------------------
1 | from ..modules.hy_layers import inject_blocks
2 | from ..modules.hy_model import inject_model
3 |
4 |
5 | class ConfigureModifiedHYNode:
6 | @classmethod
7 | def INPUT_TYPES(s):
8 | return {"required": {
9 | "model": ("MODEL",),
10 | }}
11 | RETURN_TYPES = ("MODEL",)
12 |
13 | CATEGORY = "hunyuanloom"
14 | FUNCTION = "apply"
15 |
16 | def apply(self, model):
17 | inject_model(model.model.diffusion_model)
18 | inject_blocks(model.model.diffusion_model)
19 | return (model,)
20 |
21 |
--------------------------------------------------------------------------------
/nodes/hy_feta_enhance_node.py:
--------------------------------------------------------------------------------
1 | DEFAULT_ATTN = {
2 | 'double': [i for i in range(0, 100, 1)],#[0,1,2,3,4,5,6,7,9,11,13,15,17,19,21,23,25],
3 | 'single': [i for i in range(0, 100, 1)]
4 | }
5 |
6 | class HYFetaEnhanceNode:
7 | @classmethod
8 | def INPUT_TYPES(s):
9 | return {"required": {
10 | "model": ("MODEL",),
11 | "feta_weight": ("FLOAT", {"default": 2, "min": -100.0, "max": 100.0, "step":0.01}),
12 | }, "optional": {
13 | "attn_override": ("ATTN_OVERRIDE",)
14 | }}
15 | RETURN_TYPES = ("MODEL",)
16 |
17 | CATEGORY = "hunyuanloom"
18 | FUNCTION = "apply"
19 |
20 | def apply(self, model, feta_weight, attn_override=DEFAULT_ATTN):
21 | model = model.clone()
22 |
23 | model_options = model.model_options.copy()
24 | transformer_options = model_options['transformer_options'].copy()
25 |
26 | transformer_options['feta_weight'] = feta_weight
27 | transformer_options['feta_layers'] = attn_override
28 | model_options['transformer_options'] = transformer_options
29 |
30 | model.model_options = model_options
31 | return (model,)
32 |
33 |
--------------------------------------------------------------------------------
/nodes/hy_attn_override_node.py:
--------------------------------------------------------------------------------
1 |
2 | def is_integer(string):
3 | try:
4 | int(string)
5 | return True
6 | except ValueError:
7 | return False
8 |
9 |
10 | class HYAttnOverrideNode:
11 | @classmethod
12 | def INPUT_TYPES(s):
13 | return {
14 | "required": {
15 | "double_blocks": ("STRING", { "multiline": True }),
16 | "single_blocks": ("STRING", { "multiline": True }),
17 | }
18 | }
19 |
20 | RETURN_TYPES = ("ATTN_OVERRIDE",)
21 | FUNCTION = "build"
22 |
23 | CATEGORY = "hunyuanloom/attn"
24 |
25 | def build(self, double_blocks, single_blocks):
26 |
27 | double_block_map = set()
28 | for block in double_blocks.split(','):
29 | block = block.strip()
30 | if is_integer(block):
31 | double_block_map.add(int(block))
32 |
33 | single_block_map = set()
34 | for block in single_blocks.split(','):
35 | block = block.strip()
36 | if is_integer(block):
37 | single_block_map.add(int(block))
38 |
39 | return ({ "double": double_block_map, "single": single_block_map },)
40 |
41 |
--------------------------------------------------------------------------------
/utils/mask_utils.py:
--------------------------------------------------------------------------------
1 | import torch
2 |
3 | def consolidate_masks(masks: torch.Tensor, num_latents: int, method: str) -> torch.Tensor:
4 | # masks are floats (e.g., 0.0 or 1.0), do not convert to boolean
5 |
6 | n_frames = masks.shape[0]
7 | frames_per_latent = 4
8 | expected_frames = (num_latents * frames_per_latent) - 3
9 |
10 | if n_frames == expected_frames:
11 | # Perfect match
12 | pass
13 | elif n_frames == 1 or method == "first_only":
14 | # If only one frame, repeat it for all latents
15 | return masks[:1].repeat(num_latents, 1, 1)
16 | elif n_frames > expected_frames:
17 | # Truncate if there are more frames than expected
18 | masks = masks[:expected_frames]
19 | n_frames = expected_frames
20 | else:
21 | # Not enough frames
22 | raise ValueError(
23 | f"For {num_latents} latents, expected {expected_frames} frames "
24 | f"((num_latents * 4) - 3), but got {n_frames} frames"
25 | )
26 |
27 | # Add padding frames to form a multiple of frames_per_latent
28 | padding_frame = masks[-1:].clone()
29 | padded_masks = torch.cat([masks, padding_frame.repeat(3, 1, 1)], dim=0)
30 |
31 | # Reshape into (num_latents, frames_per_latent, H, W)
32 | grouped_masks = padded_masks.reshape(num_latents, frames_per_latent, *masks.shape[1:])
33 |
34 | if method == "select_first":
35 | return grouped_masks[:, 0]
36 | elif method == "select_last":
37 | return grouped_masks[:, -1]
38 | elif method == "union":
39 | return 1 - torch.clamp(grouped_masks.sum(dim=1), max=1)
40 | else:
41 | raise ValueError(f"Unknown consolidation method: {method}")
42 |
--------------------------------------------------------------------------------
/utils/feta_enhance_utils.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from einops import rearrange
3 |
4 |
5 | def _feta_score(query_image, key_image, head_dim, num_frames, enhance_weight):
6 | scale = head_dim**-0.5
7 | query_image = query_image * scale
8 | attn_temp = query_image @ key_image.transpose(-2, -1) # translate attn to float32
9 | attn_temp = attn_temp.to(torch.float32)
10 | attn_temp = attn_temp.softmax(dim=-1)
11 |
12 | # Reshape to [batch_size * num_tokens, num_frames, num_frames]
13 | attn_temp = attn_temp.reshape(-1, num_frames, num_frames)
14 |
15 | # Create a mask for diagonal elements
16 | diag_mask = torch.eye(num_frames, device=attn_temp.device).bool()
17 | diag_mask = diag_mask.unsqueeze(0).expand(attn_temp.shape[0], -1, -1)
18 |
19 | # Zero out diagonal elements
20 | attn_wo_diag = attn_temp.masked_fill(diag_mask, 0)
21 |
22 | # Calculate mean for each token's attention matrix
23 | # Number of off-diagonal elements per matrix is n*n - n
24 | num_off_diag = num_frames * num_frames - num_frames
25 | mean_scores = attn_wo_diag.sum(dim=(1, 2)) / num_off_diag
26 |
27 | enhance_scores = mean_scores.mean() * (num_frames + enhance_weight)
28 | enhance_scores = enhance_scores.clamp(min=1)
29 | return enhance_scores
30 |
31 |
32 | @torch.compiler.disable()
33 | def get_feta_scores(img_q, img_k, transformer_options):
34 | num_frames = transformer_options['original_shape'][2]
35 | _, num_heads, ST, head_dim = img_q.shape
36 | spatial_dim = ST // num_frames
37 |
38 | query_image = rearrange(
39 | img_q, "B N (T S) C -> (B S) N T C", T=num_frames, S=spatial_dim, N=num_heads, C=head_dim
40 | )
41 | key_image = rearrange(img_k, "B N (T S) C -> (B S) N T C", T=num_frames, S=spatial_dim, N=num_heads, C=head_dim)
42 | weight = transformer_options.get('feta_weight', 0)
43 | return _feta_score(query_image, key_image, head_dim, num_frames, weight)
--------------------------------------------------------------------------------
/__init__.py:
--------------------------------------------------------------------------------
1 | from .nodes.modify_hy_model_node import ConfigureModifiedHYNode
2 | from .nodes.hy_model_pred_nodes import HYInverseModelSamplingPredNode, HYReverseModelSamplingPredNode
3 | from .nodes.rectified_sampler_nodes import HYForwardODESamplerNode, HYReverseODESamplerNode
4 | from .nodes.flowedit_nodes import HYFlowEditGuiderNode, HYFlowEditGuiderAdvNode, HYFlowEditSamplerNode, HYFlowEditGuiderCFGNode, HYFlowEditGuiderCFGAdvNode
5 |
6 | from .nodes.hy_regional_cond_nodes import HYApplyRegionalCondsNode, HYCreateRegionalCondNode
7 | from .nodes.hy_attn_override_node import HYAttnOverrideNode
8 |
9 | from .nodes.hy_feta_enhance_node import HYFetaEnhanceNode
10 |
11 | from .nodes.wrapper_flow_edit_nodes import HyVideoFlowEditSamplerNode
12 |
13 |
14 | NODE_CLASS_MAPPINGS = {
15 | "ConfigureModifiedHY": ConfigureModifiedHYNode,
16 | # RF-Inversion
17 | "HYInverseModelSamplingPred": HYInverseModelSamplingPredNode,
18 | "HYReverseModelSamplingPred": HYReverseModelSamplingPredNode,
19 | "HYForwardODESampler": HYForwardODESamplerNode,
20 | "HYReverseODESampler": HYReverseODESamplerNode,
21 | # FlowEdit
22 | "HYFlowEditGuider": HYFlowEditGuiderNode,
23 | "HYFlowEditGuiderAdv": HYFlowEditGuiderAdvNode,
24 | "HYFlowEditGuiderCFG": HYFlowEditGuiderCFGNode,
25 | "HYFlowEditGuiderCFGAdv": HYFlowEditGuiderCFGAdvNode,
26 | "HYFlowEditSampler": HYFlowEditSamplerNode,
27 | # Regional
28 | "HYApplyRegionalConds": HYApplyRegionalCondsNode,
29 | "HYCreateRegionalCond": HYCreateRegionalCondNode,
30 | "HYAttnOverride": HYAttnOverrideNode,
31 | # Enhance
32 | "HYFetaEnhance": HYFetaEnhanceNode,
33 | # Wrapper
34 | "HyVideoFlowEditSamplerWrapper": HyVideoFlowEditSamplerNode,
35 | }
36 |
37 | NODE_DISPLAY_NAME_MAPPINGS = {
38 | "ConfigureModifiedHY": "Modify Hunyuan Model",
39 | # RF-Inversion
40 | "HYInverseModelSamplingPred": "HY Inverse Model Pred",
41 | "HYReverseModelSamplingPred": "HY Reverse Model Pred",
42 | "HYForwardODESampler": "HY RF-Inv Forward Sampler",
43 | "HYReverseODESampler": "HY RF-Inv Reverse Sampler",
44 | # FlowEdit
45 | "HYFlowEditGuider": "HY FlowEdit Guider",
46 | "HYFlowEditGuiderCFG": "HY FlowEdit Guider CFG",
47 | "HYFlowEditGuiderCFGAdv": "HY FlowEdit Guider CFG Adv.",
48 | "HYFlowEditSampler": "HY FlowEdit Sampler",
49 | # Regional
50 | "HYApplyRegionalConds": "HY Apply Regional Conds",
51 | "HYCreateRegionalCond": "HY Create Regional Cond",
52 | "HYAttnOverride": "HY Attention Override",
53 | # Enhance
54 | "HYFetaEnhance": "HY Feta Enhance",
55 | # Wrapper
56 | "HyVideoFlowEditSamplerWrapper": "HunyuanVideo Flow Edit Sampler (Wrapper)",
57 | }
58 |
--------------------------------------------------------------------------------
/nodes/hy_model_pred_nodes.py:
--------------------------------------------------------------------------------
1 | import comfy.sd
2 | import comfy.model_sampling
3 | import comfy.latent_formats
4 | import nodes
5 |
6 |
7 | class InverseCONST:
8 | def calculate_input(self, sigma, noise):
9 | return noise
10 |
11 | def calculate_denoised(self, sigma, model_output, model_input):
12 | sigma = sigma.view(sigma.shape[:1] + (1,) * (model_output.ndim - 1))
13 | return model_output
14 |
15 | def noise_scaling(self, sigma, noise, latent_image, max_denoise=False):
16 | return latent_image
17 |
18 | def inverse_noise_scaling(self, sigma, latent):
19 | return latent
20 |
21 |
22 | class HYInverseModelSamplingPredNode:
23 | @classmethod
24 | def INPUT_TYPES(s):
25 | return {"required": { "model": ("MODEL",),
26 | "shift": ("FLOAT", {"default": 7, "min": 0.0, "max": 100.0, "step":0.01}),
27 | }}
28 |
29 | RETURN_TYPES = ("MODEL",)
30 | FUNCTION = "patch"
31 |
32 | CATEGORY = "hunyuanloom"
33 |
34 | def patch(self, model, shift):
35 | m = model.clone()
36 |
37 | sampling_base = comfy.model_sampling.ModelSamplingDiscreteFlow
38 | sampling_type = InverseCONST
39 |
40 | class ModelSamplingAdvanced(sampling_base, sampling_type):
41 | pass
42 |
43 | model_sampling = ModelSamplingAdvanced(model.model.model_config)
44 | model_sampling.set_parameters(shift=shift, multiplier=1000)
45 | m.add_object_patch("model_sampling", model_sampling)
46 | return (m, )
47 |
48 |
49 | class ReverseCONST:
50 | def calculate_input(self, sigma, noise):
51 | return noise
52 |
53 | def calculate_denoised(self, sigma, model_output, model_input):
54 | return model_output # model_input - model_output * sigma
55 |
56 | def noise_scaling(self, sigma, noise, latent_image, max_denoise=False):
57 | return latent_image
58 |
59 | def inverse_noise_scaling(self, sigma, latent):
60 | return latent / (1.0 - sigma)
61 |
62 |
63 | class HYReverseModelSamplingPredNode:
64 | @classmethod
65 | def INPUT_TYPES(s):
66 | return {"required": { "model": ("MODEL",),
67 | "shift": ("FLOAT", {"default": 7, "min": 0.0, "max": 100.0, "step":0.01}),
68 | }}
69 |
70 | RETURN_TYPES = ("MODEL",)
71 | FUNCTION = "patch"
72 |
73 | CATEGORY = "hunyuanloom"
74 |
75 | def patch(self, model, shift):
76 | m = model.clone()
77 |
78 | sampling_base = comfy.model_sampling.ModelSamplingDiscreteFlow
79 | sampling_type = ReverseCONST
80 |
81 | class ModelSamplingAdvanced(sampling_base, sampling_type):
82 | pass
83 |
84 | model_sampling = ModelSamplingAdvanced(model.model.model_config)
85 | model_sampling.set_parameters(shift=shift, multiplier=1000)
86 | m.add_object_patch("model_sampling", model_sampling)
87 | return (m, )
88 |
--------------------------------------------------------------------------------
/utils/latent_preview.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from PIL import Image
3 |
4 | from comfy.cli_args import args, LatentPreviewMethod
5 | import comfy.model_management
6 | import comfy.utils
7 |
8 | MAX_PREVIEW_RESOLUTION = args.preview_size
9 |
10 | def preview_to_image(latent_image):
11 | latents_ubyte = (((latent_image + 1.0) / 2.0).clamp(0, 1) # change scale from -1..1 to 0..1
12 | .mul(0xFF) # to 0..255
13 | ).to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(latent_image.device))
14 |
15 | return Image.fromarray(latents_ubyte.numpy())
16 |
17 | class LatentPreviewer:
18 | def decode_latent_to_preview(self, x0):
19 | pass
20 |
21 | def decode_latent_to_preview_image(self, preview_format, x0):
22 | preview_image = self.decode_latent_to_preview(x0)
23 | return ("GIF", preview_image, MAX_PREVIEW_RESOLUTION)
24 |
25 | class Latent2RGBPreviewer(LatentPreviewer):
26 | def __init__(self):
27 | latent_rgb_factors = [[-0.41, -0.25, -0.26],
28 | [-0.26, -0.49, -0.24],
29 | [-0.37, -0.54, -0.3],
30 | [-0.04, -0.29, -0.29],
31 | [-0.52, -0.59, -0.39],
32 | [-0.56, -0.6, -0.02],
33 | [-0.53, -0.06, -0.48],
34 | [-0.51, -0.28, -0.18],
35 | [-0.59, -0.1, -0.33],
36 | [-0.56, -0.54, -0.41],
37 | [-0.61, -0.19, -0.5],
38 | [-0.05, -0.25, -0.17],
39 | [-0.23, -0.04, -0.22],
40 | [-0.51, -0.56, -0.43],
41 | [-0.13, -0.4, -0.05],
42 | [-0.01, -0.01, -0.48]]
43 | self.latent_rgb_factors = torch.tensor(latent_rgb_factors, device="cpu").transpose(0, 1)
44 | self.latent_rgb_factors_bias = torch.tensor([0.138, 0.025, -0.299], device="cpu")
45 |
46 | def decode_latent_to_preview(self, x0):
47 | self.latent_rgb_factors = self.latent_rgb_factors.to(dtype=x0.dtype, device=x0.device)
48 | if self.latent_rgb_factors_bias is not None:
49 | self.latent_rgb_factors_bias = self.latent_rgb_factors_bias.to(dtype=x0.dtype, device=x0.device)
50 |
51 | latent_image = torch.nn.functional.linear(x0[0].permute(1, 2, 0), self.latent_rgb_factors,
52 | bias=self.latent_rgb_factors_bias)
53 | return preview_to_image(latent_image)
54 |
55 |
56 | def get_previewer():
57 | previewer = None
58 | method = args.preview_method
59 | if method != LatentPreviewMethod.NoPreviews:
60 | # TODO previewer method
61 |
62 | if method == LatentPreviewMethod.Auto:
63 | method = LatentPreviewMethod.Latent2RGB
64 |
65 | if previewer is None:
66 | previewer = Latent2RGBPreviewer()
67 | return previewer
68 |
69 | def prepare_callback(model, steps, x0_output_dict=None):
70 | preview_format = "JPEG"
71 | if preview_format not in ["JPEG", "PNG"]:
72 | preview_format = "JPEG"
73 |
74 | previewer = get_previewer()
75 |
76 | pbar = comfy.utils.ProgressBar(steps)
77 | def callback(step, x0, x, total_steps):
78 | if x0_output_dict is not None:
79 | x0_output_dict["x0"] = x0
80 | preview_bytes = None
81 | if previewer:
82 | preview_bytes = previewer.decode_latent_to_preview_image(preview_format, x0)
83 | pbar.update_absolute(step + 1, total_steps, preview_bytes)
84 | return callback
85 |
86 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ComfyUI-HunyuanLoom (WIP)
2 | A set of nodes to edit videos using the Hunyuan Video model
3 |
4 | ## Installation
5 | These nodes are for the Hunyuan Video model. If you haven't installed it yet, you can follow [these examples](https://comfyanonymous.github.io/ComfyUI_examples/hunyuan_video/).
6 |
7 |
8 | ## FlowEdit
9 |
10 | This is an implementation of [FlowEdit](https://github.com/fallenshock/FlowEdit).
11 |
12 | Use [this workflow](https://github.com/logtd/ComfyUI-HunyuanLoom/blob/main/example_workflows/example_hy_flowedit.json) to get started.
13 |
14 | https://github.com/user-attachments/assets/91e38df0-1725-4a6f-9d7d-214baa0758ab
15 |
16 | ### Settings Overview
17 |
18 |
19 | Note I took some liberties in naming these settings as the original research called them `n_min`, `n_max`, etc.
20 | There are three kinds of steps in FlowEdit:
21 | 1. skip steps -- these come at the beginning and are literally skipping steps
22 | 2. diff steps -- in these settings they are unnamed and are the remaining steps from `total - skip_steps - drift_steps`
23 | 3. drift steps -- these steps come at the end. They can essentially be thought of as normal steps that you'd use in sampling. They are named `drift` because there's nothing controlling them from drifting away from the input video.
24 |
25 | #### Skip Steps
26 | The more steps you skip, the less overall power sampling has from changing the source input. Increasing these will significantly impact how much can be changed.
27 |
28 | #### Diff Steps (the middle unnamed steps)
29 | These steps do a comparison between the source prompt and target prompt and attempt to only take the smallest difference needed to make the input video go to the target video. Admittedly, these have very little affect on Hunyuan compared to Flux and LTX, but are still needed.
30 |
31 | When using these steps in Hunyuan not a lot changes, but it does help the sampling move towards the target without going too far from the source. These steps help seed the direction of the generation so that it incorporates the input and the target prompt change.
32 |
33 | #### Drift Steps
34 | These steps come at the end and are essentially normal steps in a sampler. They help remove blur that can happen and "refine" the video. Also in Hunyuan cause the biggest changes to the input video.
35 |
36 | ## Regional Prompting (Experimental)
37 |
38 | > [!IMPORTANT]
39 | > These nodes are experimental in their current state. They require some tuning to make work right and you should not expect quality results on your first try.
40 |
41 | Regional prompting allows you to prompt specific areas of the video over time. Due to this, you can also give different prompts over time (more nodes to make this easier coming).
42 | The root implementation is based on [InstantX's Regional Prompting for Flux](https://github.com/instantX-research/Regional-Prompting-FLUX/tree/main).
43 |
44 | Use [this workflow](https://github.com/logtd/ComfyUI-HunyuanLoom/blob/main/example_workflows/example_hy_regional_prompting_t2v.json) to get started.
45 |
46 | Example using regional prompts on left and right sides.
47 |
48 | https://github.com/user-attachments/assets/37e34c3e-b85b-416a-a0a6-107a238a1783
49 |
50 | Example using regional prompts for first half of frames and second half of frames.
51 |
52 | https://github.com/user-attachments/assets/f24415b4-5c99-4bef-a5bc-7589b5f8a606
53 |
54 |
55 | ## Acknowledgements
56 |
57 | FlowEdit
58 | ```
59 | @article{kulikov2024flowedit,
60 | title = {FlowEdit: Inversion-Free Text-Based Editing Using Pre-Trained Flow Models},
61 | author = {Kulikov, Vladimir and Kleiner, Matan and Huberman-Spiegelglas, Inbar and Michaeli, Tomer},
62 | journal = {arXiv preprint arXiv:2412.08629},
63 | year = {2024}
64 | }
65 | ```
66 |
67 | Regional Prompting
68 | ```
69 | @article{chen2024training,
70 | title={Training-free Regional Prompting for Diffusion Transformers},
71 | author={Chen, Anthony and Xu, Jianjin and Zheng, Wenzhao and Dai, Gaole and Wang, Yida and Zhang, Renrui and Wang, Haofan and Zhang, Shanghang},
72 | journal={arXiv preprint arXiv:2411.02395},
73 | year={2024}
74 | }
75 | ```
76 |
--------------------------------------------------------------------------------
/modules/hy_layers.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from torch import Tensor
3 |
4 | from comfy.ldm.flux.math import apply_rope
5 | from comfy.ldm.flux.layers import SingleStreamBlock, DoubleStreamBlock
6 | from comfy.ldm.modules.attention import optimized_attention
7 |
8 | from ..utils.feta_enhance_utils import get_feta_scores
9 |
10 |
11 | def attention(q: Tensor, k: Tensor, v: Tensor, pe: Tensor, mask=None, skip_rope=False) -> Tensor:
12 | if not skip_rope:
13 | q, k = apply_rope(q, k, pe)
14 |
15 | heads = q.shape[1]
16 | x = optimized_attention(q, k, v, heads, skip_reshape=True, mask=mask)
17 | return x
18 |
19 |
20 | class ModifiedDoubleStreamBlock(DoubleStreamBlock):
21 | def forward(self, img: Tensor, txt: Tensor, vec: Tensor, pe: Tensor, attn_mask=None, transformer_options={}):
22 | img_mod1, img_mod2 = self.img_mod(vec)
23 | txt_mod1, txt_mod2 = self.txt_mod(vec)
24 |
25 | # prepare image for attention
26 | img_modulated = self.img_norm1(img)
27 | img_modulated = (1 + img_mod1.scale) * img_modulated + img_mod1.shift
28 | img_qkv = self.img_attn.qkv(img_modulated)
29 | img_q, img_k, img_v = img_qkv.view(img_qkv.shape[0], img_qkv.shape[1], 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
30 | img_q, img_k = self.img_attn.norm(img_q, img_k, img_v)
31 |
32 | # prepare txt for attention
33 | txt_modulated = self.txt_norm1(txt)
34 | txt_modulated = (1 + txt_mod1.scale) * txt_modulated + txt_mod1.shift
35 | txt_qkv = self.txt_attn.qkv(txt_modulated)
36 | txt_q, txt_k, txt_v = txt_qkv.view(txt_qkv.shape[0], txt_qkv.shape[1], 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
37 | txt_q, txt_k = self.txt_attn.norm(txt_q, txt_k, txt_v)
38 |
39 | mask_fn = transformer_options.get('patches_replace', {}).get(f'double', {}).get(('mask_fn', self.idx), None)
40 | if mask_fn is not None:
41 | attn_mask = mask_fn(None, transformer_options, txt.shape[1])
42 |
43 | skip_rope = False
44 | q = torch.cat((img_q, txt_q), dim=2)
45 | k = torch.cat((img_k, txt_k), dim=2)
46 | feta_scores = None
47 | if transformer_options.get('feta_weight', 0) > 0 and self.idx in transformer_options['feta_layers']['double']:
48 | skip_rope = True
49 | q, k = apply_rope(q, k, pe)
50 | txt_size = transformer_options['txt_size']
51 | img_q = q[:,:,:-txt_size]
52 | img_k = k[:,:,:-txt_size]
53 | feta_scores = get_feta_scores(img_q, img_k, transformer_options)
54 |
55 | # run actual attention
56 | attn = attention(q, k, torch.cat((img_v, txt_v), dim=2),pe=pe, mask=attn_mask, skip_rope=skip_rope)
57 |
58 | img_attn, txt_attn = attn[:, : img.shape[1]], attn[:, img.shape[1]:]
59 |
60 | if feta_scores is not None:
61 | img_attn *= feta_scores
62 |
63 | # calculate the img bloks
64 | img = img + img_mod1.gate * self.img_attn.proj(img_attn)
65 | img = img + img_mod2.gate * self.img_mlp((1 + img_mod2.scale) * self.img_norm2(img) + img_mod2.shift)
66 |
67 | # calculate the txt bloks
68 | txt += txt_mod1.gate * self.txt_attn.proj(txt_attn)
69 | txt += txt_mod2.gate * self.txt_mlp((1 + txt_mod2.scale) * self.txt_norm2(txt) + txt_mod2.shift)
70 |
71 | if txt.dtype == torch.float16:
72 | txt = torch.nan_to_num(txt, nan=0.0, posinf=65504, neginf=-65504)
73 |
74 | return img, txt
75 |
76 |
77 | class ModifiedSingleStreamBlock(SingleStreamBlock):
78 | def forward(self, x: Tensor, vec: Tensor, pe: Tensor, attn_mask=None, transformer_options={}) -> Tensor:
79 | mod, _ = self.modulation(vec)
80 | x_mod = (1 + mod.scale) * self.pre_norm(x) + mod.shift
81 | qkv, mlp = torch.split(self.linear1(x_mod), [3 * self.hidden_size, self.mlp_hidden_dim], dim=-1)
82 |
83 | q, k, v = qkv.view(qkv.shape[0], qkv.shape[1], 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
84 | q, k = self.norm(q, k, v)
85 |
86 | mask_fn = transformer_options.get('patches_replace', {}).get(f'single', {}).get(('mask_fn', self.idx), None)
87 | if mask_fn is not None:
88 | attn_mask = mask_fn(q, transformer_options, None)
89 |
90 | skip_rope = False
91 | feta_scores = None
92 | txt_size = transformer_options['txt_size']
93 | if transformer_options.get('feta_weight', 0) > 0 and self.idx in transformer_options['feta_layers']['single']:
94 | skip_rope = True
95 | q, k = apply_rope(q, k, pe)
96 | img_q = q[:,:,:-txt_size]
97 | img_k = k[:,:,:-txt_size]
98 | feta_scores = get_feta_scores(img_q, img_k, transformer_options)
99 |
100 | # compute attention
101 | attn = attention(q, k, v, pe=pe, mask=attn_mask, skip_rope=skip_rope)
102 |
103 | if feta_scores is not None:
104 | attn[:,:-txt_size] *= feta_scores
105 |
106 | # compute activation in mlp stream, cat again and run second linear layer
107 | output = self.linear2(torch.cat((attn, self.mlp_act(mlp)), 2))
108 | x += mod.gate * output
109 | if x.dtype == torch.float16:
110 | x = torch.nan_to_num(x, nan=0.0, posinf=65504, neginf=-65504)
111 |
112 | return x
113 |
114 |
115 |
116 | def inject_blocks(diffusion_model):
117 | for i, block in enumerate(diffusion_model.double_blocks):
118 | block.__class__ = ModifiedDoubleStreamBlock
119 | block.idx = i
120 |
121 | for i, block in enumerate(diffusion_model.single_blocks):
122 | block.__class__ = ModifiedSingleStreamBlock
123 | block.idx = i
124 |
125 | return diffusion_model
--------------------------------------------------------------------------------
/modules/hy_model.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from einops import repeat
3 | from torch import Tensor
4 |
5 | from comfy.ldm.flux.layers import (
6 | timestep_embedding
7 | )
8 | from comfy.ldm.hunyuan_video.model import HunyuanVideo
9 |
10 |
11 | class ModifiedHunyuanVideo(HunyuanVideo):
12 | def forward_orig(
13 | self,
14 | img: Tensor,
15 | img_ids: Tensor,
16 | txt: Tensor,
17 | txt_ids: Tensor,
18 | txt_mask: Tensor,
19 | timesteps: Tensor,
20 | y: Tensor,
21 | guidance: Tensor = None,
22 | control=None,
23 | transformer_options={},
24 | ) -> Tensor:
25 | patches_replace = transformer_options.get("patches_replace", {})
26 |
27 | initial_shape = list(img.shape)
28 | transformer_options['original_shape'] = initial_shape
29 | # running on sequences img
30 | img = self.img_in(img)
31 | vec = self.time_in(timestep_embedding(timesteps, 256, time_factor=1.0).to(img.dtype))
32 |
33 | vec = vec + self.vector_in(y[:, :self.params.vec_in_dim])
34 |
35 | if self.params.guidance_embed:
36 | if guidance is None:
37 | raise ValueError("Didn't get guidance strength for guidance distilled model.")
38 | vec = vec + self.guidance_in(timestep_embedding(guidance, 256).to(img.dtype))
39 |
40 | if txt_mask is not None and not torch.is_floating_point(txt_mask):
41 | txt_mask = (txt_mask - 1).to(img.dtype) * torch.finfo(img.dtype).max
42 |
43 | transformer_options['txt_size'] = txt.shape[1]
44 | txt = self.txt_in(txt, timesteps, txt_mask)
45 |
46 | ids = torch.cat((img_ids, txt_ids), dim=1)
47 | pe = self.pe_embedder(ids)
48 |
49 | img_len = img.shape[1]
50 | if txt_mask is not None:
51 | attn_mask_len = img_len + txt.shape[1]
52 | attn_mask = torch.zeros((1, 1, attn_mask_len), dtype=img.dtype, device=img.device)
53 | attn_mask[:, 0, img_len:] = txt_mask
54 | else:
55 | attn_mask = None
56 |
57 | blocks_replace = patches_replace.get("dit", {})
58 | for i, block in enumerate(self.double_blocks):
59 | if ("double_block", i) in blocks_replace:
60 | def block_wrap(args):
61 | out = {}
62 | out["img"], out["txt"] = block(img=args["img"], txt=args["txt"], vec=args["vec"], pe=args["pe"], attn_mask=args["attention_mask"])
63 | return out
64 |
65 | out = blocks_replace[("double_block", i)]({"img": img, "txt": txt, "vec": vec, "pe": pe, "attention_mask": attn_mask}, {"original_block": block_wrap})
66 | txt = out["txt"]
67 | img = out["img"]
68 | else:
69 | img, txt = block(img=img, txt=txt, vec=vec, pe=pe, attn_mask=attn_mask, transformer_options=transformer_options)
70 |
71 | if control is not None: # Controlnet
72 | control_i = control.get("input")
73 | if i < len(control_i):
74 | add = control_i[i]
75 | if add is not None:
76 | img += add
77 |
78 | img = torch.cat((img, txt), 1)
79 |
80 | for i, block in enumerate(self.single_blocks):
81 | if ("single_block", i) in blocks_replace:
82 | def block_wrap(args):
83 | out = {}
84 | out["img"] = block(args["img"], vec=args["vec"], pe=args["pe"], attn_mask=args["attention_mask"])
85 | return out
86 |
87 | out = blocks_replace[("single_block", i)]({"img": img, "vec": vec, "pe": pe, "attention_mask": attn_mask}, {"original_block": block_wrap})
88 | img = out["img"]
89 | else:
90 | img = block(img, vec=vec, pe=pe, attn_mask=attn_mask, transformer_options=transformer_options)
91 |
92 | if control is not None: # Controlnet
93 | control_o = control.get("output")
94 | if i < len(control_o):
95 | add = control_o[i]
96 | if add is not None:
97 | img[:, : img_len] += add
98 |
99 | img = img[:, : img_len]
100 |
101 | img = self.final_layer(img, vec) # (N, T, patch_size ** 2 * out_channels)
102 |
103 | shape = initial_shape[-3:]
104 | for i in range(len(shape)):
105 | shape[i] = shape[i] // self.patch_size[i]
106 | img = img.reshape([img.shape[0]] + shape + [self.out_channels] + self.patch_size)
107 | img = img.permute(0, 4, 1, 5, 2, 6, 3, 7)
108 | img = img.reshape(initial_shape[0], self.out_channels, initial_shape[2], initial_shape[3], initial_shape[4])
109 | return img
110 |
111 | def forward(self, x, timestep, context, y, guidance, attention_mask=None, control=None, transformer_options={}, **kwargs):
112 | bs, c, t, h, w = x.shape
113 | patch_size = self.patch_size
114 | t_len = ((t + (patch_size[0] // 2)) // patch_size[0])
115 | h_len = ((h + (patch_size[1] // 2)) // patch_size[1])
116 | w_len = ((w + (patch_size[2] // 2)) // patch_size[2])
117 | img_ids = torch.zeros((t_len, h_len, w_len, 3), device=x.device, dtype=x.dtype)
118 | img_ids[:, :, :, 0] = img_ids[:, :, :, 0] + torch.linspace(0, t_len - 1, steps=t_len, device=x.device, dtype=x.dtype).reshape(-1, 1, 1)
119 | img_ids[:, :, :, 1] = img_ids[:, :, :, 1] + torch.linspace(0, h_len - 1, steps=h_len, device=x.device, dtype=x.dtype).reshape(1, -1, 1)
120 | img_ids[:, :, :, 2] = img_ids[:, :, :, 2] + torch.linspace(0, w_len - 1, steps=w_len, device=x.device, dtype=x.dtype).reshape(1, 1, -1)
121 | img_ids = repeat(img_ids, "t h w c -> b (t h w) c", b=bs)
122 |
123 | regional_conditioning = transformer_options.get('patches', {}).get('regional_conditioning', None)
124 | if regional_conditioning is not None:
125 | context = regional_conditioning[0](context, transformer_options)
126 |
127 | txt_ids = torch.zeros((bs, context.shape[1], 3), device=x.device, dtype=x.dtype)
128 | out = self.forward_orig(x, img_ids, context, txt_ids, attention_mask, timestep, y, guidance, control, transformer_options)
129 | return out
130 |
131 |
132 | def inject_model(diffusion_model):
133 | diffusion_model.__class__ = ModifiedHunyuanVideo
134 | return diffusion_model
135 |
--------------------------------------------------------------------------------
/nodes/rectified_sampler_nodes.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from tqdm import trange
3 |
4 | from comfy.samplers import KSAMPLER
5 |
6 |
7 | def generate_eta_values(steps, start_time, end_time, eta, eta_trend):
8 | eta_values = [0] * steps
9 |
10 | if eta_trend == 'constant':
11 | for i in range(start_time, end_time):
12 | eta_values[i] = eta
13 | elif eta_trend == 'linear_increase':
14 | for i in range(start_time, end_time):
15 | progress = (i - start_time) / (end_time - start_time - 1)
16 | eta_values[i] = eta * progress
17 | elif eta_trend == 'linear_decrease':
18 | for i in range(start_time, end_time):
19 | progress = 1 - (i - start_time) / (end_time - start_time - 1)
20 | eta_values[i] = eta * progress
21 |
22 | return eta_values
23 |
24 |
25 |
26 | def get_sample_forward(gamma, start_step, end_step, gamma_trend, seed):
27 | # Controlled Forward ODE (Algorithm 1)
28 |
29 | @torch.no_grad()
30 | def sample_forward(model, y0, sigmas, extra_args=None, callback=None, disable=None):
31 | generator = torch.Generator()
32 | generator.manual_seed(seed)
33 | extra_args = {} if extra_args is None else extra_args
34 | Y = y0.clone()
35 | y1 = torch.randn(Y.shape, generator=generator).to(y0.device)
36 | N = len(sigmas)-1
37 | s_in = y0.new_ones([y0.shape[0]])
38 | gamma_values = generate_eta_values(N, start_step, end_step, gamma, gamma_trend)
39 | for i in trange(N, disable=disable):
40 | # t_i = model.inner_model.inner_model.model_sampling.timestep(sigmas[i]) - old code
41 | t_i = sigmas[i] / max(sigmas) # - new code
42 |
43 | # 6. Unconditional Vector field uti(Yti) = u(Yti, ti, Φ(“”); φ)
44 | unconditional_vector_field = model(Y, s_in * sigmas[i], **extra_args) # this implementation takes sigma instead of timestep
45 |
46 | # 7.Conditional Vector field uti(Yti|y1) = (y1−Yti)/1−ti
47 | conditional_vector_field = (y1-Y)/(1-t_i)
48 |
49 | # 8. Controlled Vector field ti(Yti) = uti(Yti) + γ (uti(Yti|y1) − uti(Yti))
50 | controlled_vector_field = unconditional_vector_field + gamma_values[i] * (conditional_vector_field - unconditional_vector_field)
51 |
52 | # 9. Next state Yti+1 = Yti + ˆuti(Yti) (σ(ti+1) − σ(ti))
53 | Y = Y + controlled_vector_field * (sigmas[i+1] - sigmas[i])
54 |
55 | if callback is not None:
56 | callback({'x': Y, 'denoised': Y, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigmas[i]})
57 |
58 | return Y
59 |
60 | return sample_forward
61 |
62 |
63 |
64 | def get_sample_reverse(latent_image, eta, start_time, end_time, eta_trend):
65 | # Controlled Reverse ODE (Algorithm 2)
66 | @torch.no_grad()
67 | def sample_reverse(model, y1, sigmas, extra_args=None, callback=None, disable=None):
68 | extra_args = {} if extra_args is None else extra_args
69 | X = y1.clone()
70 | N = len(sigmas)-1
71 | y0 = latent_image.clone().to(y1.device)
72 | s_in = y0.new_ones([y0.shape[0]])
73 | eta_values = generate_eta_values(N, start_time, end_time, eta, eta_trend)
74 | for i in trange(N, disable=disable):
75 | # t_i = 1-model.inner_model.inner_model.model_sampling.timestep(sigmas[i]) # TODO: figure out which one to use
76 | t_i = i/N # Empiracally better results
77 | sigma = sigmas[i]
78 |
79 | # 5. Unconditional Vector field uti(Xti) = -u(Xti, 1-ti, Φ(“prompt”); φ)
80 | unconditional_vector_field = -model(X, sigma*s_in, **extra_args) # this implementation takes sigma instead of timestep
81 |
82 | # 6.Conditional Vector field uti(Xti|y0) = (y0−Xti)/(1−ti)
83 | conditional_vector_field = (y0-X)/(1-t_i)
84 |
85 | # 7. Controlled Vector field ti(Yti) = uti(Yti) + γ (uti(Yti|y1) − uti(Yti))
86 | controlled_vector_field = unconditional_vector_field + eta_values[i] * (conditional_vector_field - unconditional_vector_field)
87 |
88 | # 8. Next state Yti+1 = Yti + ˆuti(Yti) (σ(ti+1) − σ(ti))
89 | X = X + controlled_vector_field * (sigmas[i] - sigmas[i+1])
90 |
91 | if callback is not None:
92 | callback({'x': X, 'denoised': X, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigmas[i]})
93 |
94 | return X
95 |
96 | return sample_reverse
97 |
98 |
99 | class HYForwardODESamplerNode:
100 | @classmethod
101 | def INPUT_TYPES(s):
102 | return {"required": {
103 | "gamma": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 100.0, "step": 0.01}),
104 | "start_step": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
105 | "end_step": ("INT", {"default": 5, "min": 0, "max": 1000, "step": 1}),
106 | "gamma_trend": (['constant', 'linear_increase', 'linear_decrease'],)
107 | }, "optional": {
108 | "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff }),
109 | }}
110 | RETURN_TYPES = ("SAMPLER",)
111 | FUNCTION = "build"
112 |
113 | CATEGORY = "hunyuanloom"
114 |
115 | def build(self, gamma, start_step, end_step, gamma_trend, seed=0):
116 | sampler = KSAMPLER(get_sample_forward(gamma, start_step, end_step, gamma_trend, seed))
117 |
118 | return (sampler, )
119 |
120 |
121 | class HYReverseODESamplerNode:
122 | @classmethod
123 | def INPUT_TYPES(s):
124 | return {"required": {
125 | "model": ("MODEL",),
126 | "latent_image": ("LATENT",),
127 | "eta": ("FLOAT", {"default": 0.8, "min": 0.0, "max": 100.0, "step": 0.01}),
128 | "start_step": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
129 | "end_step": ("INT", {"default": 5, "min": 0, "max": 1000, "step": 1}),
130 | }, "optional": {
131 | "eta_trend": (['constant', 'linear_increase', 'linear_decrease'],)
132 | }}
133 | RETURN_TYPES = ("SAMPLER",)
134 | FUNCTION = "build"
135 |
136 | CATEGORY = "hunyuanloom"
137 |
138 | def build(self, model, latent_image, eta, start_step, end_step, eta_trend='constant'):
139 | process_latent_in = model.get_model_object("process_latent_in")
140 | latent_image = process_latent_in(latent_image['samples'])
141 | sampler = KSAMPLER(get_sample_reverse(latent_image, eta, start_step, end_step, eta_trend))
142 |
143 | return (sampler, )
144 |
--------------------------------------------------------------------------------
/nodes/hy_regional_cond_nodes.py:
--------------------------------------------------------------------------------
1 | import torch
2 |
3 | import comfy.model_sampling
4 |
5 | from ..utils.mask_utils import consolidate_masks
6 |
7 |
8 | DEFAULT_REGIONAL_ATTN = {
9 | 'double': [i for i in range(1, 100, 1)],#[0,1,2,3,4,5,6,7,9,11,13,15,17,19,21,23,25],
10 | 'single': [i for i in range(1, 100, 2)]
11 | }
12 |
13 |
14 | class RegionalMask(torch.nn.Module):
15 | def __init__(self, mask: torch.Tensor, start_percent: float, end_percent: float) -> None:
16 | super().__init__()
17 | self.register_buffer('mask', mask)
18 | self.start_percent = start_percent
19 | self.end_percent = end_percent
20 |
21 | def __call__(self, q, transformer_options, *args, **kwargs):
22 | if self.start_percent <= 1 - transformer_options['sigmas'][0] < self.end_percent:
23 | return self.mask
24 |
25 | return None
26 |
27 |
28 | class RegionalConditioning(torch.nn.Module):
29 | def __init__(self, region_cond: torch.Tensor, start_percent: float, end_percent: float, main_cond_strength: float, always_included: bool) -> None:
30 | super().__init__()
31 | self.register_buffer('region_cond', region_cond)
32 | self.start_percent = start_percent
33 | self.end_percent = end_percent
34 | self.main_cond_strength = main_cond_strength
35 | self.always_included = always_included
36 |
37 | def __call__(self, context, transformer_options, *args, **kwargs):
38 | if self.start_percent <= 1 - transformer_options['sigmas'][0] < self.end_percent or self.always_included:
39 | return torch.cat([context*self.main_cond_strength, self.region_cond.to(context.dtype)], dim=1)
40 | return context
41 |
42 |
43 | class HYCreateRegionalCondNode:
44 | @classmethod
45 | def INPUT_TYPES(s):
46 | return {"required": {
47 | "cond": ("CONDITIONING",),
48 | "mask": ("MASK",),
49 | "cond_strength": ("FLOAT", {"default": 1, "min": 0.0, "max": 10.0, "step": 0.01, "round": 0.01}),
50 | "mask_consolidation": (["first_only", "select_first", "select_last", "union"], { "tooltip": "How to choose the masking when they are compressed for the latents temporally."}),
51 | }, "optional": {
52 | "prev_regions": ("REGION_COND",),
53 | }}
54 |
55 | RETURN_TYPES = ("REGION_COND",)
56 | FUNCTION = "create"
57 |
58 | CATEGORY = "hunyuanloom"
59 |
60 | def create(self, cond, mask, cond_strength, mask_consolidation, prev_regions=[]):
61 | prev_regions = [*prev_regions]
62 | prev_regions.append({
63 | 'mask': mask,
64 | 'cond': cond[0][0] * cond_strength,
65 | 'mask_consolidation': mask_consolidation,
66 | })
67 |
68 | return (prev_regions,)
69 |
70 |
71 | class HYApplyRegionalCondsNode:
72 | @classmethod
73 | def INPUT_TYPES(s):
74 | return {"required": {
75 | "model": ("MODEL",),
76 | "cond": ("CONDITIONING",),
77 | "region_conds": ("REGION_COND",),
78 | "latent": ("LATENT",),
79 | "start_percent": ("FLOAT", {"default": 0, "min": 0.0, "max": 1.0, "step": 0.01, "round": 0.01}),
80 | "end_percent": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01, "round": 0.01}),
81 | "main_cond_strength": ("FLOAT", {"default": 1, "min": 0.0, "max": 10.0, "step": 0.01, "round": 0.01}),
82 | "always_included": ("BOOLEAN", { "default": False, "tooltip": "Whether to keep the prompts always but allow them to affect the entire video (unmasked) outside of end/start percents." }),
83 | }, "optional": {
84 | "attn_override": ("ATTN_OVERRIDE",)
85 | }}
86 |
87 | RETURN_TYPES = ("MODEL",)
88 | FUNCTION = "patch"
89 |
90 | CATEGORY = "hunyuanloom"
91 |
92 | def patch(self, model, cond, region_conds, latent, start_percent, end_percent, main_cond_strength, always_included, attn_override=DEFAULT_REGIONAL_ATTN):
93 | model = model.clone()
94 |
95 | latent = latent['samples']
96 | b, c, f, h, w = latent.shape
97 | h //=2
98 | w //=2
99 |
100 | img_len = h*w*f
101 |
102 | main_cond = cond[0][0]
103 | main_cond_size = main_cond.shape[1]
104 |
105 | regional_conditioning = torch.cat([region_cond['cond'] for region_cond in region_conds], dim=1)
106 | text_len = main_cond_size + regional_conditioning.shape[1]
107 |
108 | regional_mask = torch.zeros((text_len + img_len, text_len + img_len), dtype=torch.bool)
109 |
110 | self_attend_masks = torch.zeros((img_len, img_len), dtype=torch.bool)
111 | union_masks = torch.zeros((img_len, img_len), dtype=torch.bool)
112 |
113 | main_mask = torch.zeros((f, h, w), dtype=torch.float16)
114 | if main_cond_strength == 0:
115 | main_mask = torch.ones((f, h, w), dtype=torch.float16)
116 |
117 | region_conds = [
118 | {
119 | 'mask': main_mask,
120 | 'cond': torch.ones((1, main_cond_size, 4096), dtype=torch.float16),
121 | 'mask_consolidation': 'first_only',
122 | },
123 | *region_conds
124 | ]
125 |
126 | current_seq_len = 0
127 | for region_cond_dict in region_conds:
128 | region_cond = region_cond_dict['cond']
129 | region_mask = region_cond_dict['mask']
130 | region_mask = consolidate_masks(region_mask, f, region_cond_dict['mask_consolidation'])
131 | region_mask = 1 - region_mask
132 | region_mask = torch.nn.functional.interpolate(region_mask[None, :, :, :], (h, w), mode='nearest-exact').flatten().unsqueeze(1).repeat(1, region_cond.size(1))
133 | next_seq_len = current_seq_len + region_cond.shape[1]
134 |
135 | # txt attends to itself
136 | regional_mask[current_seq_len:next_seq_len, current_seq_len:next_seq_len] = True
137 |
138 | # txt attends to corresponding regional img
139 | regional_mask[current_seq_len:next_seq_len, text_len:] = region_mask.transpose(-1, -2)
140 |
141 | # regional img attends to corresponding txt
142 | regional_mask[text_len:, current_seq_len:next_seq_len] = region_mask
143 |
144 | # regional img attends to corresponding regional img
145 | img_size_masks = region_mask[:, :1].repeat(1, img_len)
146 | img_size_masks_transpose = img_size_masks.transpose(-1, -2)
147 | self_attend_masks = torch.logical_or(self_attend_masks,
148 | torch.logical_and(img_size_masks, img_size_masks_transpose))
149 |
150 | # update union
151 | union_masks = torch.logical_or(union_masks,
152 | torch.logical_or(img_size_masks, img_size_masks_transpose))
153 |
154 | current_seq_len = next_seq_len
155 |
156 | background_masks = torch.logical_not(union_masks)
157 | background_and_self_attend_masks = torch.logical_or(background_masks, self_attend_masks)
158 | regional_mask[text_len:, text_len:] = background_and_self_attend_masks
159 |
160 | # Split rows into text and image
161 | text_rows, img_rows = regional_mask.split([text_len, img_len], dim=0)
162 |
163 | # Now split each part into text and image columns
164 | text_rows_text_cols, text_rows_img_cols = text_rows.split([text_len, img_len], dim=1)
165 | img_rows_text_cols, img_rows_img_cols = img_rows.split([text_len, img_len], dim=1)
166 |
167 | double_regional_mask = torch.cat([
168 | torch.cat([img_rows_img_cols, img_rows_text_cols], dim=1),
169 | torch.cat([text_rows_img_cols, text_rows_text_cols], dim=1)
170 | ], dim=0)
171 |
172 | # Patch
173 | double_regional_mask = RegionalMask(double_regional_mask, start_percent, end_percent)
174 | single_regional_mask = RegionalMask(regional_mask, start_percent, end_percent)
175 | regional_conditioning = RegionalConditioning(regional_conditioning, start_percent, end_percent, main_cond_strength, always_included)
176 |
177 |
178 | model.set_model_patch(regional_conditioning, 'regional_conditioning')
179 |
180 | for block_idx in attn_override['double']:
181 | model.set_model_patch_replace(double_regional_mask, f"double", "mask_fn", int(block_idx))
182 |
183 | for block_idx in attn_override['single']:
184 | model.set_model_patch_replace(single_regional_mask, f"single", "mask_fn", int(block_idx))
185 |
186 | return (model,)
187 |
--------------------------------------------------------------------------------
/nodes/flowedit_nodes.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from tqdm import trange
3 |
4 | from comfy.samplers import KSAMPLER, CFGGuider, sampling_function
5 |
6 |
7 | class FlowEditGuider(CFGGuider):
8 | def __init__(self, model_patcher):
9 | super().__init__(model_patcher)
10 | self.cfgs = {}
11 | self.num_repeats = 1
12 |
13 | def set_conds(self, **kwargs):
14 | self.inner_set_conds(kwargs)
15 |
16 | def set_cfgs(self, **kwargs):
17 | self.cfgs = {**kwargs}
18 |
19 | def set_num_repeats(self, num_repeats):
20 | self.num_repeats = num_repeats
21 |
22 | def predict_noise(self, x, timestep, model_options={}, seed=None):
23 | latent_type = model_options['transformer_options']['latent_type']
24 | positive = self.conds.get(f'{latent_type}_positive', None)
25 | negative = self.conds.get(f'{latent_type}_negative', None)
26 | cfg = self.cfgs.get(latent_type, self.cfg)
27 |
28 | if self.num_repeats == 1:
29 | return sampling_function(self.inner_model, x, timestep, negative, positive, cfg, model_options=model_options, seed=seed)
30 |
31 | # Multiple samples case
32 | predictions = None
33 | for i in range(self.num_repeats):
34 | current_seed = None if seed is None else seed + i
35 | current_pred = sampling_function(
36 | self.inner_model, x, timestep, negative, positive, cfg,
37 | model_options=model_options, seed=current_seed
38 | )
39 | if predictions is None:
40 | predictions = current_pred
41 | else:
42 | predictions += current_pred
43 |
44 | return predictions / self.num_repeats
45 |
46 |
47 | # Basic node for model compatibility
48 | class HYFlowEditGuiderNode:
49 | @classmethod
50 | def INPUT_TYPES(s):
51 | return {"required":
52 | {
53 | "model": ("MODEL",),
54 | "source_cond": ("CONDITIONING", ),
55 | "target_cond": ("CONDITIONING", ),
56 | }
57 | }
58 |
59 | RETURN_TYPES = ("GUIDER",)
60 | FUNCTION = "get_guider"
61 | CATEGORY = "hunyuanloom"
62 |
63 | def get_guider(self, model, source_cond, target_cond):
64 | guider = FlowEditGuider(model)
65 | guider.set_conds(source_positive=source_cond, target_positive=target_cond)
66 | guider.set_cfg(1.0)
67 | return (guider,)
68 |
69 | class HYFlowEditGuiderAdvNode:
70 | @classmethod
71 | def INPUT_TYPES(s):
72 | return {"required":
73 | {
74 | "model": ("MODEL",),
75 | "source_cond": ("CONDITIONING", ),
76 | "target_cond": ("CONDITIONING", ),
77 | "num_repeats": ("INT", {"default": 1, "min": 1, "max": 10}),
78 | }
79 | }
80 |
81 | RETURN_TYPES = ("GUIDER",)
82 | FUNCTION = "get_guider"
83 | CATEGORY = "hunyuanloom"
84 |
85 | def get_guider(self, model, source_cond, target_cond, num_repeats):
86 | guider = FlowEditGuider(model)
87 | guider.set_conds(source_positive=source_cond, target_positive=target_cond)
88 | guider.set_cfg(1.0)
89 | guider.set_num_repeats(num_repeats)
90 | return (guider,)
91 |
92 |
93 | class HYFlowEditGuiderCFGNode:
94 | @classmethod
95 | def INPUT_TYPES(s):
96 | return {"required":
97 | {
98 | "model": ("MODEL",),
99 | "source_cond": ("CONDITIONING", ),
100 | "source_uncond": ("CONDITIONING", ),
101 | "target_cond": ("CONDITIONING", ),
102 | "target_uncond": ("CONDITIONING", ),
103 | "source_cfg": ("FLOAT", {"default": 2, "min": 0, "max": 0xffffffffffffffff, "step": 0.01 }),
104 | "target_cfg": ("FLOAT", {"default": 4.5, "min": 0, "max": 0xffffffffffffffff, "step": 0.01 }),
105 | }
106 | }
107 |
108 | RETURN_TYPES = ("GUIDER",)
109 | FUNCTION = "get_guider"
110 | CATEGORY = "hunyuanloom"
111 |
112 | def get_guider(self, model, source_cond, source_uncond, target_cond, target_uncond, source_cfg, target_cfg):
113 | guider = FlowEditGuider(model)
114 | guider.set_conds(source_positive=source_cond, source_negative=source_uncond,
115 | target_positive=target_cond, target_negative=target_uncond)
116 | guider.set_cfgs(source=source_cfg, target=target_cfg)
117 | return (guider,)
118 |
119 |
120 | class HYFlowEditGuiderCFGAdvNode:
121 | @classmethod
122 | def INPUT_TYPES(s):
123 | return {"required":
124 | {
125 | "model": ("MODEL",),
126 | "source_cond": ("CONDITIONING", ),
127 | "source_uncond": ("CONDITIONING", ),
128 | "target_cond": ("CONDITIONING", ),
129 | "target_uncond": ("CONDITIONING", ),
130 | "source_cfg": ("FLOAT", {"default": 2, "min": 0, "max": 0xffffffffffffffff, "step": 0.01 }),
131 | "target_cfg": ("FLOAT", {"default": 4.5, "min": 0, "max": 0xffffffffffffffff, "step": 0.01 }),
132 | "num_repeats": ("INT", {"default": 1, "min": 1, "max": 10}),
133 | }
134 | }
135 |
136 | RETURN_TYPES = ("GUIDER",)
137 | FUNCTION = "get_guider"
138 | CATEGORY = "hunyuanloom"
139 |
140 | def get_guider(self, model, source_cond, source_uncond, target_cond, target_uncond, source_cfg, target_cfg, num_repeats):
141 | guider = FlowEditGuider(model)
142 | guider.set_conds(source_positive=source_cond, source_negative=source_uncond,
143 | target_positive=target_cond, target_negative=target_uncond)
144 | guider.set_cfgs(source=source_cfg, target=target_cfg)
145 | guider.set_num_repeats(num_repeats)
146 | return (guider,)
147 |
148 | def get_flowedit_sample(skip_steps, refine_steps, generator):
149 | @torch.no_grad()
150 | def flowedit_sample(model, x_init, sigmas, extra_args=None, callback=None, disable=None):
151 | extra_args = {} if extra_args is None else extra_args
152 |
153 | model_options = extra_args.get('model_options', {})
154 | transformer_options = model_options.get('transformer_options', {})
155 | transformer_options = {**transformer_options}
156 | model_options['transformer_options'] = transformer_options
157 | extra_args['model_options'] = model_options
158 |
159 | source_extra_args = {**extra_args, 'model_options': { 'transformer_options': { 'latent_type': 'source'} }}
160 |
161 | sigmas = sigmas[skip_steps:]
162 |
163 | x_tgt = x_init.clone()
164 | N = len(sigmas)-1
165 | s_in = x_init.new_ones([x_init.shape[0]])
166 | noise_mask = extra_args.get('denoise_mask', None)
167 | if noise_mask is None:
168 | noise_mask = torch.ones_like(x_init)
169 | else:
170 | extra_args['denoise_mask'] = None
171 | source_extra_args['denoise_mask'] = None
172 |
173 | for i in trange(N, disable=disable):
174 | sigma = sigmas[i]
175 | noise = torch.randn(x_init.shape, generator=generator).to(x_init.device)
176 |
177 | zt_src = (1-sigma)*x_init + sigma*noise
178 |
179 | if i < N-refine_steps:
180 | zt_tgt = x_tgt + zt_src - x_init
181 | vt_src = model(zt_src, sigma*s_in, **source_extra_args)
182 | else:
183 | if i == N-refine_steps:
184 | zt_tgt = x_tgt + (zt_src - x_init)
185 | x_tgt = x_tgt + (zt_src - x_init) * noise_mask
186 | else:
187 | zt_tgt = x_tgt * (noise_mask) + (1-noise_mask) * ( (1-sigma)*x_tgt + sigma*noise )
188 | vt_src = 0
189 |
190 | transformer_options['latent_type'] = 'target'
191 | vt_tgt = model(zt_tgt, sigma*s_in, **extra_args)
192 |
193 | v_delta = vt_tgt - vt_src
194 | x_tgt += (sigmas[i+1] - sigmas[i]) * v_delta * noise_mask
195 |
196 | if callback is not None:
197 | callback({'x': x_tgt, 'denoised': x_tgt, 'i': i+skip_steps, 'sigma': sigmas[i], 'sigma_hat': sigmas[i]})
198 |
199 | return x_tgt
200 |
201 | return flowedit_sample
202 |
203 |
204 | class HYFlowEditSamplerNode:
205 | @classmethod
206 | def INPUT_TYPES(s):
207 | return {"required": {
208 | "skip_steps": ("INT", {"default": 4, "min": 0, "max": 0xffffffffffffffff }),
209 | "drift_steps": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff }),
210 | "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff }),
211 | }, "optional": {
212 | }}
213 | RETURN_TYPES = ("SAMPLER",)
214 | FUNCTION = "build"
215 |
216 | CATEGORY = "hunyuanloom"
217 |
218 | def build(self, skip_steps, drift_steps, seed):
219 | generator = torch.manual_seed(seed)
220 | sampler = KSAMPLER(get_flowedit_sample(skip_steps, drift_steps, generator))
221 | return (sampler, )
222 |
--------------------------------------------------------------------------------
/nodes/flow_edit_nodes.py:
--------------------------------------------------------------------------------
1 | import torch
2 | import gc
3 |
4 |
5 | from diffusers.utils.torch_utils import randn_tensor
6 | import comfy.model_management as mm
7 | from ..utils.rope_utils import get_rotary_pos_embed
8 | from ..utils.latent_preview import prepare_callback
9 |
10 |
11 | class HyVideoFlowEditSamplerNode:
12 | @classmethod
13 | def INPUT_TYPES(s):
14 | return {
15 | "required": {
16 | "model": ("HYVIDEOMODEL",),
17 | "source_embeds": ("HYVIDEMBEDS", ),
18 | "target_embeds": ("HYVIDEMBEDS", ),
19 | "samples": ("LATENT", {"tooltip": "init Latents to use for video2video process"} ),
20 | "steps": ("INT", {"default": 30, "min": 1}),
21 | "skip_steps": ("INT", {"default": 4, "min": 0}),
22 | "drift_steps": ("INT", {"default": 0, "min": 0}),
23 | "source_guidance_scale": ("FLOAT", {"default": 6.0, "min": 0.0, "max": 30.0, "step": 0.01}),
24 | "target_guidance_scale": ("FLOAT", {"default": 12.0, "min": 0.0, "max": 30.0, "step": 0.01}),
25 | "flow_shift": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 30.0, "step": 0.01}),
26 | "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
27 | "force_offload": ("BOOLEAN", {"default": True}),
28 | },
29 | }
30 |
31 | RETURN_TYPES = ("LATENT",)
32 | RETURN_NAMES = ("samples",)
33 | FUNCTION = "process"
34 | CATEGORY = "hunyuanloom"
35 |
36 | def process(self,
37 | model,
38 | source_embeds,
39 | target_embeds,
40 | flow_shift,
41 | steps,
42 | skip_steps,
43 | drift_steps,
44 | source_guidance_scale,
45 | target_guidance_scale,
46 | seed,
47 | samples,
48 | force_offload):
49 | model = model.model
50 | device = mm.get_torch_device()
51 | offload_device = mm.unet_offload_device()
52 | dtype = model["dtype"]
53 | transformer = model["pipe"].transformer
54 | pipeline = model["pipe"]
55 |
56 | generator = torch.Generator(device=torch.device("cpu")).manual_seed(seed)
57 |
58 | latents = samples["samples"] if samples is not None else None
59 | batch_size, num_channels_latents, latent_num_frames, latent_height, latent_width = latents.shape
60 | height = latent_height * pipeline.vae_scale_factor
61 | width = latent_width * pipeline.vae_scale_factor
62 | num_frames = (latent_num_frames - 1) * 4 + 1
63 |
64 | if width <= 0 or height <= 0 or num_frames <= 0:
65 | raise ValueError(
66 | f"`height` and `width` and `video_length` must be positive integers, got height={height}, width={width}, video_length={num_frames}"
67 | )
68 | if (num_frames - 1) % 4 != 0:
69 | raise ValueError(
70 | f"`video_length-1` must be a multiple of 4, got {num_frames}"
71 | )
72 |
73 | freqs_cos, freqs_sin = get_rotary_pos_embed(transformer, num_frames, height, width)
74 |
75 | pipeline.scheduler.shift = flow_shift
76 |
77 | if model["block_swap_args"] is not None:
78 | for name, param in transformer.named_parameters():
79 | #print(name, param.data.device)
80 | if "single" not in name and "double" not in name:
81 | param.data = param.data.to(device)
82 |
83 | transformer.block_swap(
84 | model["block_swap_args"]["double_blocks_to_swap"] - 1 ,
85 | model["block_swap_args"]["single_blocks_to_swap"] - 1,
86 | offload_txt_in = model["block_swap_args"]["offload_txt_in"],
87 | offload_img_in = model["block_swap_args"]["offload_img_in"],
88 | )
89 | elif model["manual_offloading"]:
90 | transformer.to(device)
91 |
92 | mm.soft_empty_cache()
93 | gc.collect()
94 |
95 | try:
96 | torch.cuda.reset_peak_memory_stats(device)
97 | except:
98 | pass
99 |
100 | pipeline.scheduler.set_timesteps(steps, device=device)
101 | timesteps = pipeline.scheduler.timesteps
102 | timesteps = torch.cat([timesteps, torch.tensor([0]).to(timesteps.device)]).to(timesteps.device)
103 |
104 | latent_video_length = (num_frames - 1) // 4 + 1
105 |
106 | # 5. Prepare latent variables
107 | num_channels_latents = transformer.config.in_channels
108 |
109 | latents = latents.to(device)
110 |
111 | shape = (
112 | 1,
113 | num_channels_latents,
114 | latent_video_length,
115 | int(height) // pipeline.vae_scale_factor,
116 | int(width) // pipeline.vae_scale_factor,
117 | )
118 | noise = randn_tensor(shape, generator=generator, device=device, dtype=torch.float32)
119 |
120 | frames_needed = noise.shape[1]
121 | current_frames = latents.shape[1]
122 |
123 | if frames_needed > current_frames:
124 | repeat_factor = frames_needed - current_frames
125 | additional_frame = torch.randn((latents.size(0), repeat_factor, latents.size(2), latents.size(3), latents.size(4)), dtype=latents.dtype, device=latents.device)
126 | latents = torch.cat((additional_frame, latents), dim=1)
127 | self.additional_frames = repeat_factor
128 | elif frames_needed < current_frames:
129 | latents = latents[:, :frames_needed, :, :, :]
130 |
131 |
132 | # 7. Denoising loop
133 | self._num_timesteps = len(timesteps)
134 |
135 | callback = prepare_callback(transformer, steps)
136 |
137 | x_init = latents.clone()
138 |
139 | from comfy.utils import ProgressBar
140 | from tqdm import tqdm
141 | comfy_pbar = ProgressBar(len(timesteps))
142 | N = len(timesteps)
143 |
144 | x_tgt = latents
145 |
146 | with tqdm(total=len(timesteps)) as progress_bar:
147 | for idx, (t, t_prev) in enumerate(zip(timesteps[:-1], timesteps[1:])):
148 | if idx < skip_steps:
149 | continue
150 | t_expand = t.repeat(x_init.shape[0])
151 | source_guidance_expand = (
152 | torch.tensor(
153 | [source_guidance_scale] * x_init.shape[0],
154 | dtype=torch.float32,
155 | device=device,
156 | ).to(pipeline.base_dtype)
157 | * 1000.0
158 | if source_guidance_scale is not None
159 | else None
160 | )
161 |
162 | target_guidance_expand = (
163 | torch.tensor(
164 | [target_guidance_scale] * x_init.shape[0],
165 | dtype=torch.float32,
166 | device=device,
167 | ).to(pipeline.base_dtype)
168 | * 1000.0
169 | if target_guidance_scale is not None
170 | else None
171 | )
172 |
173 | # predict the noise residual
174 | with torch.autocast(
175 | device_type="cuda", dtype=pipeline.base_dtype, enabled=True
176 | ):
177 |
178 | noise = torch.randn(x_init.shape, generator=generator).to(x_init.device)
179 |
180 | sigma = t / 1000.0
181 | sigma_prev = t_prev / 1000.0
182 |
183 | zt_src = (1-sigma)*x_init + sigma*noise
184 |
185 | if idx < N-drift_steps:
186 | zt_tgt = x_tgt + zt_src - x_init
187 | vt_src = transformer( # For an input image (129, 192, 336) (1, 256, 256)
188 | zt_src, # [2, 16, 33, 24, 42]
189 | t_expand, # [2]
190 | text_states=source_embeds["prompt_embeds"], # [2, 256, 4096]
191 | text_mask=source_embeds["attention_mask"], # [2, 256]
192 | text_states_2=source_embeds["prompt_embeds_2"], # [2, 768]
193 | freqs_cos=freqs_cos, # [seqlen, head_dim]
194 | freqs_sin=freqs_sin, # [seqlen, head_dim]
195 | guidance=source_guidance_expand,
196 | stg_block_idx=-1,
197 | stg_mode=None,
198 | return_dict=True,
199 | )["x"]
200 | else:
201 | if idx == N - drift_steps:
202 | x_tgt = x_tgt + zt_src - x_init
203 | zt_tgt = x_tgt
204 | vt_src = 0
205 |
206 | vt_tgt = transformer( # For an input image (129, 192, 336) (1, 256, 256)
207 | zt_tgt, # [2, 16, 33, 24, 42]
208 | t_expand, # [2]
209 | text_states=target_embeds["prompt_embeds"], # [2, 256, 4096]
210 | text_mask=target_embeds["attention_mask"], # [2, 256]
211 | text_states_2=target_embeds["prompt_embeds_2"], # [2, 768]
212 | freqs_cos=freqs_cos, # [seqlen, head_dim]
213 | freqs_sin=freqs_sin, # [seqlen, head_dim]
214 | guidance=target_guidance_expand,
215 | stg_block_idx=-1,
216 | stg_mode=None,
217 | return_dict=True,
218 | )["x"]
219 |
220 | v_delta = vt_tgt - vt_src
221 |
222 | x_tgt = x_tgt.to(torch.float32)
223 | v_delta = v_delta.to(torch.float32)
224 |
225 |
226 | x_tgt = x_tgt + (sigma_prev - sigma) * v_delta
227 | x_tgt = x_tgt.to(torch.bfloat16)
228 |
229 | # compute the previous noisy sample x_t -> x_t-1
230 | #latents = pipeline.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
231 |
232 |
233 | progress_bar.update()
234 | if callback is not None:
235 | callback(idx, latents.detach()[-1].permute(1,0,2,3), None, steps)
236 | else:
237 | comfy_pbar.update(1)
238 |
239 | try:
240 | torch.cuda.reset_peak_memory_stats(device)
241 | except:
242 | pass
243 |
244 | if force_offload:
245 | if model["manual_offloading"]:
246 | transformer.to(offload_device)
247 | mm.soft_empty_cache()
248 | gc.collect()
249 |
250 | return ({
251 | "samples": x_tgt
252 | },)
253 |
254 |
255 |
--------------------------------------------------------------------------------
/nodes/wrapper_flow_edit_nodes.py:
--------------------------------------------------------------------------------
1 | import torch
2 | import gc
3 |
4 |
5 | from diffusers.utils.torch_utils import randn_tensor
6 | import comfy.model_management as mm
7 | from ..utils.rope_utils import get_rotary_pos_embed
8 | from ..utils.latent_preview import prepare_callback
9 |
10 | VAE_SCALING_FACTOR = 0.476986
11 |
12 | class HyVideoFlowEditSamplerNode:
13 | @classmethod
14 | def INPUT_TYPES(s):
15 | return {
16 | "required": {
17 | "model": ("HYVIDEOMODEL",),
18 | "source_embeds": ("HYVIDEMBEDS", ),
19 | "target_embeds": ("HYVIDEMBEDS", ),
20 | "samples": ("LATENT", {"tooltip": "init Latents to use for video2video process"} ),
21 | "steps": ("INT", {"default": 30, "min": 1}),
22 | "skip_steps": ("INT", {"default": 4, "min": 0}),
23 | "drift_steps": ("INT", {"default": 0, "min": 0}),
24 | "source_guidance_scale": ("FLOAT", {"default": 6.0, "min": 0.0, "max": 30.0, "step": 0.01}),
25 | "target_guidance_scale": ("FLOAT", {"default": 12.0, "min": 0.0, "max": 30.0, "step": 0.01}),
26 | "drift_guidance_scale": ("FLOAT", {"default": 6.0, "min": 0.0, "max": 30.0, "step": 0.01}),
27 | "flow_shift": ("FLOAT", {"default": 6.0, "min": 1.0, "max": 30.0, "step": 0.01}),
28 | "drift_flow_shift": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 30.0, "step": 0.01}),
29 | "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
30 | "force_offload": ("BOOLEAN", {"default": True}),
31 | },
32 | }
33 |
34 | RETURN_TYPES = ("LATENT",)
35 | RETURN_NAMES = ("samples",)
36 | FUNCTION = "process"
37 | CATEGORY = "hunyuanloom"
38 |
39 | def process(self,
40 | model,
41 | source_embeds,
42 | target_embeds,
43 | flow_shift,
44 | drift_flow_shift,
45 | steps,
46 | skip_steps,
47 | drift_steps,
48 | source_guidance_scale,
49 | target_guidance_scale,
50 | drift_guidance_scale,
51 | seed,
52 | samples,
53 | force_offload):
54 | model = model.model
55 |
56 | device = mm.get_torch_device()
57 | offload_device = mm.unet_offload_device()
58 | transformer = model["pipe"].transformer
59 | pipeline = model["pipe"]
60 |
61 | generator = torch.Generator(device=torch.device("cpu")).manual_seed(seed)
62 |
63 | latents = samples["samples"] * VAE_SCALING_FACTOR if samples is not None else None
64 | batch_size, num_channels_latents, latent_num_frames, latent_height, latent_width = latents.shape
65 | height = latent_height * pipeline.vae_scale_factor
66 | width = latent_width * pipeline.vae_scale_factor
67 | num_frames = (latent_num_frames - 1) * 4 + 1
68 |
69 | if width <= 0 or height <= 0 or num_frames <= 0:
70 | raise ValueError(
71 | f"`height` and `width` and `video_length` must be positive integers, got height={height}, width={width}, video_length={num_frames}"
72 | )
73 | if (num_frames - 1) % 4 != 0:
74 | raise ValueError(
75 | f"`video_length-1` must be a multiple of 4, got {num_frames}"
76 | )
77 |
78 | freqs_cos, freqs_sin = get_rotary_pos_embed(transformer, num_frames, height, width)
79 | freqs_cos = freqs_cos.to(device)
80 | freqs_sin = freqs_sin.to(device)
81 |
82 | if model["block_swap_args"] is not None:
83 | for name, param in transformer.named_parameters():
84 | #print(name, param.data.device)
85 | if "single" not in name and "double" not in name:
86 | param.data = param.data.to(device)
87 |
88 | transformer.block_swap(
89 | model["block_swap_args"]["double_blocks_to_swap"] - 1 ,
90 | model["block_swap_args"]["single_blocks_to_swap"] - 1,
91 | offload_txt_in = model["block_swap_args"]["offload_txt_in"],
92 | offload_img_in = model["block_swap_args"]["offload_img_in"],
93 | )
94 | elif model["manual_offloading"]:
95 | transformer.to(device)
96 |
97 | mm.soft_empty_cache()
98 | gc.collect()
99 |
100 | try:
101 | torch.cuda.reset_peak_memory_stats(device)
102 | except:
103 | pass
104 |
105 | # drift_flow_shift
106 |
107 | pipeline.scheduler.flow_shift = flow_shift
108 | pipeline.scheduler.set_timesteps(steps, device=device)
109 | timesteps = pipeline.scheduler.timesteps
110 | timesteps = torch.cat([timesteps, torch.tensor([0]).to(timesteps.device)]).to(timesteps.device)
111 |
112 | pipeline.scheduler.flow_shift = drift_flow_shift
113 | pipeline.scheduler.set_timesteps(steps, device=device)
114 | drift_timesteps = pipeline.scheduler.timesteps
115 | drift_timesteps = torch.cat([drift_timesteps, torch.tensor([0]).to(drift_timesteps.device)]).to(drift_timesteps.device)
116 |
117 | timesteps[-drift_steps:] = drift_timesteps[-drift_steps:]
118 |
119 | latent_video_length = (num_frames - 1) // 4 + 1
120 |
121 | # 5. Prepare latent variables
122 | num_channels_latents = transformer.config.in_channels
123 |
124 | latents = latents.to(device)
125 |
126 | shape = (
127 | 1,
128 | num_channels_latents,
129 | latent_video_length,
130 | int(height) // pipeline.vae_scale_factor,
131 | int(width) // pipeline.vae_scale_factor,
132 | )
133 | noise = randn_tensor(shape, generator=generator, device=device, dtype=torch.float32)
134 |
135 | frames_needed = noise.shape[1]
136 | current_frames = latents.shape[1]
137 |
138 | if frames_needed > current_frames:
139 | repeat_factor = frames_needed - current_frames
140 | additional_frame = torch.randn((latents.size(0), repeat_factor, latents.size(2), latents.size(3), latents.size(4)), dtype=latents.dtype, device=latents.device)
141 | latents = torch.cat((additional_frame, latents), dim=1)
142 | self.additional_frames = repeat_factor
143 | elif frames_needed < current_frames:
144 | latents = latents[:, :frames_needed, :, :, :]
145 |
146 |
147 | # 7. Denoising loop
148 | callback = prepare_callback(transformer, steps)
149 |
150 | x_init = latents.clone()
151 |
152 | from comfy.utils import ProgressBar
153 | from tqdm import tqdm
154 | comfy_pbar = ProgressBar(len(timesteps))
155 | N = len(timesteps)
156 |
157 | x_tgt = latents
158 |
159 | with tqdm(total=len(timesteps)) as progress_bar:
160 | for idx, (t, t_prev) in enumerate(zip(timesteps[:-1], timesteps[1:])):
161 | if idx < skip_steps:
162 | continue
163 | t_expand = t.repeat(x_init.shape[0])
164 | source_guidance_expand = (
165 | torch.tensor(
166 | [source_guidance_scale] * x_init.shape[0],
167 | dtype=torch.float32,
168 | device=device,
169 | ).to(pipeline.base_dtype)
170 | * 1000.0
171 | if source_guidance_scale is not None
172 | else None
173 | )
174 |
175 | if idx < N-drift_steps:
176 | current_guidance_scale = target_guidance_scale
177 | else:
178 | current_guidance_scale = drift_guidance_scale
179 |
180 | target_guidance_expand = (
181 | torch.tensor(
182 | [current_guidance_scale] * x_init.shape[0],
183 | dtype=torch.float32,
184 | device=device,
185 | ).to(pipeline.base_dtype)
186 | * 1000.0
187 | if target_guidance_scale is not None
188 | else None
189 | )
190 |
191 | with torch.autocast(
192 | device_type="cuda", dtype=pipeline.base_dtype, enabled=True
193 | ):
194 | noise = torch.randn(x_init.shape, generator=generator).to(x_init.device)
195 |
196 | sigma = t / 1000.0
197 | sigma_prev = t_prev / 1000.0
198 |
199 | zt_src = (1-sigma) * x_init + sigma * noise
200 | zt_tgt = x_tgt + zt_src - x_init
201 |
202 | if idx < N-drift_steps:
203 | vt_src = transformer( # For an input image (129, 192, 336) (1, 256, 256)
204 | zt_src, # [2, 16, 33, 24, 42]
205 | t_expand, # [2]
206 | text_states=source_embeds["prompt_embeds"], # [2, 256, 4096]
207 | text_mask=source_embeds["attention_mask"], # [2, 256]
208 | text_states_2=source_embeds["prompt_embeds_2"], # [2, 768]
209 | freqs_cos=freqs_cos, # [seqlen, head_dim]
210 | freqs_sin=freqs_sin, # [seqlen, head_dim]
211 | guidance=source_guidance_expand,
212 | stg_block_idx=-1,
213 | stg_mode=None,
214 | return_dict=True,
215 | )["x"]
216 | else:
217 | if idx == N - drift_steps:
218 | x_tgt = zt_tgt
219 | zt_tgt = x_tgt
220 | vt_src = 0
221 |
222 | vt_tgt = transformer( # For an input image (129, 192, 336) (1, 256, 256)
223 | zt_tgt, # [2, 16, 33, 24, 42]
224 | t_expand, # [2]
225 | text_states=target_embeds["prompt_embeds"], # [2, 256, 4096]
226 | text_mask=target_embeds["attention_mask"], # [2, 256]
227 | text_states_2=target_embeds["prompt_embeds_2"], # [2, 768]
228 | freqs_cos=freqs_cos, # [seqlen, head_dim]
229 | freqs_sin=freqs_sin, # [seqlen, head_dim]
230 | guidance=target_guidance_expand,
231 | stg_block_idx=-1,
232 | stg_mode=None,
233 | return_dict=True,
234 | )["x"]
235 |
236 | v_delta = vt_tgt - vt_src
237 |
238 | x_tgt = x_tgt.to(torch.float32)
239 | v_delta = v_delta.to(torch.float32)
240 |
241 | x_tgt = x_tgt + (sigma_prev - sigma) * v_delta
242 | x_tgt = x_tgt.to(torch.bfloat16)
243 |
244 | progress_bar.update()
245 | if callback is not None:
246 | callback(idx, (zt_tgt - vt_tgt * sigma).detach()[-1].permute(1,0,2,3), None, steps)
247 | else:
248 | comfy_pbar.update(1)
249 |
250 | try:
251 | torch.cuda.reset_peak_memory_stats(device)
252 | except:
253 | pass
254 |
255 | if force_offload:
256 | if model["manual_offloading"]:
257 | transformer.to(offload_device)
258 | mm.soft_empty_cache()
259 | gc.collect()
260 |
261 | return ({
262 | "samples": x_tgt / VAE_SCALING_FACTOR
263 | },)
264 |
265 |
266 |
--------------------------------------------------------------------------------
/utils/rope_utils.py:
--------------------------------------------------------------------------------
1 | import torch
2 |
3 | import torch
4 | from typing import Union, Tuple, List
5 |
6 |
7 | def _to_tuple(x, dim=2):
8 | if isinstance(x, int):
9 | return (x,) * dim
10 | elif len(x) == dim:
11 | return x
12 | else:
13 | raise ValueError(f"Expected length {dim} or int, but got {x}")
14 |
15 |
16 | def get_meshgrid_nd(start, *args, dim=2):
17 | """
18 | Get n-D meshgrid with start, stop and num.
19 |
20 | Args:
21 | start (int or tuple): If len(args) == 0, start is num; If len(args) == 1, start is start, args[0] is stop,
22 | step is 1; If len(args) == 2, start is start, args[0] is stop, args[1] is num. For n-dim, start/stop/num
23 | should be int or n-tuple. If n-tuple is provided, the meshgrid will be stacked following the dim order in
24 | n-tuples.
25 | *args: See above.
26 | dim (int): Dimension of the meshgrid. Defaults to 2.
27 |
28 | Returns:
29 | grid (np.ndarray): [dim, ...]
30 | """
31 | if len(args) == 0:
32 | # start is grid_size
33 | num = _to_tuple(start, dim=dim)
34 | start = (0,) * dim
35 | stop = num
36 | elif len(args) == 1:
37 | # start is start, args[0] is stop, step is 1
38 | start = _to_tuple(start, dim=dim)
39 | stop = _to_tuple(args[0], dim=dim)
40 | num = [stop[i] - start[i] for i in range(dim)]
41 | elif len(args) == 2:
42 | # start is start, args[0] is stop, args[1] is num
43 | start = _to_tuple(start, dim=dim) # Left-Top eg: 12,0
44 | stop = _to_tuple(args[0], dim=dim) # Right-Bottom eg: 20,32
45 | num = _to_tuple(args[1], dim=dim) # Target Size eg: 32,124
46 | else:
47 | raise ValueError(f"len(args) should be 0, 1 or 2, but got {len(args)}")
48 |
49 | # PyTorch implement of np.linspace(start[i], stop[i], num[i], endpoint=False)
50 | axis_grid = []
51 | for i in range(dim):
52 | a, b, n = start[i], stop[i], num[i]
53 | g = torch.linspace(a, b, n + 1, dtype=torch.float32)[:n]
54 | axis_grid.append(g)
55 | grid = torch.meshgrid(*axis_grid, indexing="ij") # dim x [W, H, D]
56 | grid = torch.stack(grid, dim=0) # [dim, W, H, D]
57 |
58 | return grid
59 |
60 |
61 | #################################################################################
62 | # Rotary Positional Embedding Functions #
63 | #################################################################################
64 | # https://github.com/meta-llama/llama/blob/be327c427cc5e89cc1d3ab3d3fec4484df771245/llama/model.py#L80
65 |
66 |
67 | def reshape_for_broadcast(
68 | freqs_cis: Union[torch.Tensor, Tuple[torch.Tensor]],
69 | x: torch.Tensor,
70 | head_first=False,
71 | ):
72 | """
73 | Reshape frequency tensor for broadcasting it with another tensor.
74 |
75 | This function reshapes the frequency tensor to have the same shape as the target tensor 'x'
76 | for the purpose of broadcasting the frequency tensor during element-wise operations.
77 |
78 | Notes:
79 | When using FlashMHAModified, head_first should be False.
80 | When using Attention, head_first should be True.
81 |
82 | Args:
83 | freqs_cis (Union[torch.Tensor, Tuple[torch.Tensor]]): Frequency tensor to be reshaped.
84 | x (torch.Tensor): Target tensor for broadcasting compatibility.
85 | head_first (bool): head dimension first (except batch dim) or not.
86 |
87 | Returns:
88 | torch.Tensor: Reshaped frequency tensor.
89 |
90 | Raises:
91 | AssertionError: If the frequency tensor doesn't match the expected shape.
92 | AssertionError: If the target tensor 'x' doesn't have the expected number of dimensions.
93 | """
94 | ndim = x.ndim
95 | assert 0 <= 1 < ndim
96 |
97 | if isinstance(freqs_cis, tuple):
98 | # freqs_cis: (cos, sin) in real space
99 | if head_first:
100 | assert freqs_cis[0].shape == (
101 | x.shape[-2],
102 | x.shape[-1],
103 | ), f"freqs_cis shape {freqs_cis[0].shape} does not match x shape {x.shape}"
104 | shape = [
105 | d if i == ndim - 2 or i == ndim - 1 else 1
106 | for i, d in enumerate(x.shape)
107 | ]
108 | else:
109 | assert freqs_cis[0].shape == (
110 | x.shape[1],
111 | x.shape[-1],
112 | ), f"freqs_cis shape {freqs_cis[0].shape} does not match x shape {x.shape}"
113 | shape = [d if i == 1 or i == ndim - 1 else 1 for i, d in enumerate(x.shape)]
114 | return freqs_cis[0].view(*shape), freqs_cis[1].view(*shape)
115 | else:
116 | # freqs_cis: values in complex space
117 | if head_first:
118 | assert freqs_cis.shape == (
119 | x.shape[-2],
120 | x.shape[-1],
121 | ), f"freqs_cis shape {freqs_cis.shape} does not match x shape {x.shape}"
122 | shape = [
123 | d if i == ndim - 2 or i == ndim - 1 else 1
124 | for i, d in enumerate(x.shape)
125 | ]
126 | else:
127 | assert freqs_cis.shape == (
128 | x.shape[1],
129 | x.shape[-1],
130 | ), f"freqs_cis shape {freqs_cis.shape} does not match x shape {x.shape}"
131 | shape = [d if i == 1 or i == ndim - 1 else 1 for i, d in enumerate(x.shape)]
132 | return freqs_cis.view(*shape)
133 |
134 |
135 | def rotate_half(x):
136 | x_real, x_imag = (
137 | x.float().reshape(*x.shape[:-1], -1, 2).unbind(-1)
138 | ) # [B, S, H, D//2]
139 | return torch.stack([-x_imag, x_real], dim=-1).flatten(3)
140 |
141 |
142 | def apply_rotary_emb(
143 | xq: torch.Tensor,
144 | xk: torch.Tensor,
145 | freqs_cis: Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]],
146 | head_first: bool = False,
147 | ) -> Tuple[torch.Tensor, torch.Tensor]:
148 | """
149 | Apply rotary embeddings to input tensors using the given frequency tensor.
150 |
151 | This function applies rotary embeddings to the given query 'xq' and key 'xk' tensors using the provided
152 | frequency tensor 'freqs_cis'. The input tensors are reshaped as complex numbers, and the frequency tensor
153 | is reshaped for broadcasting compatibility. The resulting tensors contain rotary embeddings and are
154 | returned as real tensors.
155 |
156 | Args:
157 | xq (torch.Tensor): Query tensor to apply rotary embeddings. [B, S, H, D]
158 | xk (torch.Tensor): Key tensor to apply rotary embeddings. [B, S, H, D]
159 | freqs_cis (torch.Tensor or tuple): Precomputed frequency tensor for complex exponential.
160 | head_first (bool): head dimension first (except batch dim) or not.
161 |
162 | Returns:
163 | Tuple[torch.Tensor, torch.Tensor]: Tuple of modified query tensor and key tensor with rotary embeddings.
164 |
165 | """
166 | xk_out = None
167 | if isinstance(freqs_cis, tuple):
168 | cos, sin = reshape_for_broadcast(freqs_cis, xq, head_first) # [S, D]
169 | cos, sin = cos.to(xq.device), sin.to(xq.device)
170 | # real * cos - imag * sin
171 | # imag * cos + real * sin
172 | xq_out = (xq.float() * cos + rotate_half(xq.float()) * sin).type_as(xq)
173 | xk_out = (xk.float() * cos + rotate_half(xk.float()) * sin).type_as(xk)
174 | else:
175 | # view_as_complex will pack [..., D/2, 2](real) to [..., D/2](complex)
176 | xq_ = torch.view_as_complex(
177 | xq.float().reshape(*xq.shape[:-1], -1, 2)
178 | ) # [B, S, H, D//2]
179 | freqs_cis = reshape_for_broadcast(freqs_cis, xq_, head_first).to(
180 | xq.device
181 | ) # [S, D//2] --> [1, S, 1, D//2]
182 | # (real, imag) * (cos, sin) = (real * cos - imag * sin, imag * cos + real * sin)
183 | # view_as_real will expand [..., D/2](complex) to [..., D/2, 2](real)
184 | xq_out = torch.view_as_real(xq_ * freqs_cis).flatten(3).type_as(xq)
185 | xk_ = torch.view_as_complex(
186 | xk.float().reshape(*xk.shape[:-1], -1, 2)
187 | ) # [B, S, H, D//2]
188 | xk_out = torch.view_as_real(xk_ * freqs_cis).flatten(3).type_as(xk)
189 |
190 | return xq_out, xk_out
191 |
192 |
193 | def get_nd_rotary_pos_embed(
194 | rope_dim_list,
195 | start,
196 | *args,
197 | theta=10000.0,
198 | use_real=False,
199 | theta_rescale_factor: Union[float, List[float]] = 1.0,
200 | interpolation_factor: Union[float, List[float]] = 1.0,
201 | ):
202 | """
203 | This is a n-d version of precompute_freqs_cis, which is a RoPE for tokens with n-d structure.
204 |
205 | Args:
206 | rope_dim_list (list of int): Dimension of each rope. len(rope_dim_list) should equal to n.
207 | sum(rope_dim_list) should equal to head_dim of attention layer.
208 | start (int | tuple of int | list of int): If len(args) == 0, start is num; If len(args) == 1, start is start,
209 | args[0] is stop, step is 1; If len(args) == 2, start is start, args[0] is stop, args[1] is num.
210 | *args: See above.
211 | theta (float): Scaling factor for frequency computation. Defaults to 10000.0.
212 | use_real (bool): If True, return real part and imaginary part separately. Otherwise, return complex numbers.
213 | Some libraries such as TensorRT does not support complex64 data type. So it is useful to provide a real
214 | part and an imaginary part separately.
215 | theta_rescale_factor (float): Rescale factor for theta. Defaults to 1.0.
216 |
217 | Returns:
218 | pos_embed (torch.Tensor): [HW, D/2]
219 | """
220 |
221 | grid = get_meshgrid_nd(
222 | start, *args, dim=len(rope_dim_list)
223 | ) # [3, W, H, D] / [2, W, H]
224 |
225 | if isinstance(theta_rescale_factor, int) or isinstance(theta_rescale_factor, float):
226 | theta_rescale_factor = [theta_rescale_factor] * len(rope_dim_list)
227 | elif isinstance(theta_rescale_factor, list) and len(theta_rescale_factor) == 1:
228 | theta_rescale_factor = [theta_rescale_factor[0]] * len(rope_dim_list)
229 | assert len(theta_rescale_factor) == len(
230 | rope_dim_list
231 | ), "len(theta_rescale_factor) should equal to len(rope_dim_list)"
232 |
233 | if isinstance(interpolation_factor, int) or isinstance(interpolation_factor, float):
234 | interpolation_factor = [interpolation_factor] * len(rope_dim_list)
235 | elif isinstance(interpolation_factor, list) and len(interpolation_factor) == 1:
236 | interpolation_factor = [interpolation_factor[0]] * len(rope_dim_list)
237 | assert len(interpolation_factor) == len(
238 | rope_dim_list
239 | ), "len(interpolation_factor) should equal to len(rope_dim_list)"
240 |
241 | # use 1/ndim of dimensions to encode grid_axis
242 | embs = []
243 | for i in range(len(rope_dim_list)):
244 | emb = get_1d_rotary_pos_embed(
245 | rope_dim_list[i],
246 | grid[i].reshape(-1),
247 | theta,
248 | use_real=use_real,
249 | theta_rescale_factor=theta_rescale_factor[i],
250 | interpolation_factor=interpolation_factor[i],
251 | ) # 2 x [WHD, rope_dim_list[i]]
252 | embs.append(emb)
253 |
254 | if use_real:
255 | cos = torch.cat([emb[0] for emb in embs], dim=1) # (WHD, D/2)
256 | sin = torch.cat([emb[1] for emb in embs], dim=1) # (WHD, D/2)
257 | return cos, sin
258 | else:
259 | emb = torch.cat(embs, dim=1) # (WHD, D/2)
260 | return emb
261 |
262 |
263 | def get_1d_rotary_pos_embed(
264 | dim: int,
265 | pos: Union[torch.FloatTensor, int],
266 | theta: float = 10000.0,
267 | use_real: bool = False,
268 | theta_rescale_factor: float = 1.0,
269 | interpolation_factor: float = 1.0,
270 | ) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
271 | """
272 | Precompute the frequency tensor for complex exponential (cis) with given dimensions.
273 | (Note: `cis` means `cos + i * sin`, where i is the imaginary unit.)
274 |
275 | This function calculates a frequency tensor with complex exponential using the given dimension 'dim'
276 | and the end index 'end'. The 'theta' parameter scales the frequencies.
277 | The returned tensor contains complex values in complex64 data type.
278 |
279 | Args:
280 | dim (int): Dimension of the frequency tensor.
281 | pos (int or torch.FloatTensor): Position indices for the frequency tensor. [S] or scalar
282 | theta (float, optional): Scaling factor for frequency computation. Defaults to 10000.0.
283 | use_real (bool, optional): If True, return real part and imaginary part separately.
284 | Otherwise, return complex numbers.
285 | theta_rescale_factor (float, optional): Rescale factor for theta. Defaults to 1.0.
286 |
287 | Returns:
288 | freqs_cis: Precomputed frequency tensor with complex exponential. [S, D/2]
289 | freqs_cos, freqs_sin: Precomputed frequency tensor with real and imaginary parts separately. [S, D]
290 | """
291 | if isinstance(pos, int):
292 | pos = torch.arange(pos).float()
293 |
294 | # proposed by reddit user bloc97, to rescale rotary embeddings to longer sequence length without fine-tuning
295 | # has some connection to NTK literature
296 | if theta_rescale_factor != 1.0:
297 | theta *= theta_rescale_factor ** (dim / (dim - 2))
298 |
299 | freqs = 1.0 / (
300 | theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim)
301 | ) # [D/2]
302 | # assert interpolation_factor == 1.0, f"interpolation_factor: {interpolation_factor}"
303 | freqs = torch.outer(pos * interpolation_factor, freqs) # [S, D/2]
304 | if use_real:
305 | freqs_cos = freqs.cos().repeat_interleave(2, dim=1) # [S, D]
306 | freqs_sin = freqs.sin().repeat_interleave(2, dim=1) # [S, D]
307 | return freqs_cos, freqs_sin
308 | else:
309 | freqs_cis = torch.polar(
310 | torch.ones_like(freqs), freqs
311 | ) # complex64 # [S, D/2]
312 | return freqs_cis
313 |
314 |
315 | def get_rotary_pos_embed(transformer, video_length, height, width):
316 | target_ndim = 3
317 | ndim = 5 - 2
318 | rope_theta = 225
319 | patch_size = transformer.patch_size
320 | rope_dim_list = transformer.rope_dim_list
321 | hidden_size = transformer.hidden_size
322 | heads_num = transformer.heads_num
323 | head_dim = hidden_size // heads_num
324 |
325 | # 884
326 | latents_size = [(video_length - 1) // 4 + 1, height // 8, width // 8]
327 |
328 | if isinstance(patch_size, int):
329 | assert all(s % patch_size == 0 for s in latents_size), (
330 | f"Latent size(last {ndim} dimensions) should be divisible by patch size({patch_size}), "
331 | f"but got {latents_size}."
332 | )
333 | rope_sizes = [s // patch_size for s in latents_size]
334 | elif isinstance(patch_size, list):
335 | assert all(
336 | s % patch_size[idx] == 0
337 | for idx, s in enumerate(latents_size)
338 | ), (
339 | f"Latent size(last {ndim} dimensions) should be divisible by patch size({patch_size}), "
340 | f"but got {latents_size}."
341 | )
342 | rope_sizes = [
343 | s // patch_size[idx] for idx, s in enumerate(latents_size)
344 | ]
345 |
346 | if len(rope_sizes) != target_ndim:
347 | rope_sizes = [1] * (target_ndim - len(rope_sizes)) + rope_sizes # time axis
348 |
349 | if rope_dim_list is None:
350 | rope_dim_list = [head_dim // target_ndim for _ in range(target_ndim)]
351 | assert (
352 | sum(rope_dim_list) == head_dim
353 | ), "sum(rope_dim_list) should equal to head_dim of attention layer"
354 | freqs_cos, freqs_sin = get_nd_rotary_pos_embed(
355 | rope_dim_list,
356 | rope_sizes,
357 | theta=rope_theta,
358 | use_real=True,
359 | theta_rescale_factor=1,
360 | )
361 | return freqs_cos, freqs_sin
362 |
--------------------------------------------------------------------------------
/example_workflows/example_hy_flowedit.json:
--------------------------------------------------------------------------------
1 | {
2 | "last_node_id": 89,
3 | "last_link_id": 231,
4 | "nodes": [
5 | {
6 | "id": 73,
7 | "type": "VAEDecodeTiled",
8 | "pos": [
9 | 1470.9056396484375,
10 | 171.9037322998047
11 | ],
12 | "size": [
13 | 210,
14 | 102
15 | ],
16 | "flags": {},
17 | "order": 16,
18 | "mode": 0,
19 | "inputs": [
20 | {
21 | "name": "samples",
22 | "type": "LATENT",
23 | "link": 210
24 | },
25 | {
26 | "name": "vae",
27 | "type": "VAE",
28 | "link": 211
29 | }
30 | ],
31 | "outputs": [
32 | {
33 | "name": "IMAGE",
34 | "type": "IMAGE",
35 | "links": [
36 | 216
37 | ],
38 | "slot_index": 0
39 | }
40 | ],
41 | "properties": {
42 | "Node name for S&R": "VAEDecodeTiled"
43 | },
44 | "widgets_values": [
45 | 256,
46 | 64
47 | ]
48 | },
49 | {
50 | "id": 13,
51 | "type": "SamplerCustomAdvanced",
52 | "pos": [
53 | 1163.367431640625,
54 | 168.47523498535156
55 | ],
56 | "size": [
57 | 272.3617858886719,
58 | 124.53733825683594
59 | ],
60 | "flags": {},
61 | "order": 15,
62 | "mode": 0,
63 | "inputs": [
64 | {
65 | "name": "noise",
66 | "type": "NOISE",
67 | "link": 217,
68 | "slot_index": 0
69 | },
70 | {
71 | "name": "guider",
72 | "type": "GUIDER",
73 | "link": 218,
74 | "slot_index": 1
75 | },
76 | {
77 | "name": "sampler",
78 | "type": "SAMPLER",
79 | "link": 231,
80 | "slot_index": 2
81 | },
82 | {
83 | "name": "sigmas",
84 | "type": "SIGMAS",
85 | "link": 20,
86 | "slot_index": 3
87 | },
88 | {
89 | "name": "latent_image",
90 | "type": "LATENT",
91 | "link": 230,
92 | "slot_index": 4
93 | }
94 | ],
95 | "outputs": [
96 | {
97 | "name": "output",
98 | "type": "LATENT",
99 | "links": [
100 | 210
101 | ],
102 | "slot_index": 0,
103 | "shape": 3
104 | },
105 | {
106 | "name": "denoised_output",
107 | "type": "LATENT",
108 | "links": null,
109 | "shape": 3
110 | }
111 | ],
112 | "properties": {
113 | "Node name for S&R": "SamplerCustomAdvanced"
114 | },
115 | "widgets_values": []
116 | },
117 | {
118 | "id": 79,
119 | "type": "DisableNoise",
120 | "pos": [
121 | 1169.6798095703125,
122 | 124.1329345703125
123 | ],
124 | "size": [
125 | 210,
126 | 26
127 | ],
128 | "flags": {
129 | "collapsed": true
130 | },
131 | "order": 0,
132 | "mode": 0,
133 | "inputs": [],
134 | "outputs": [
135 | {
136 | "name": "NOISE",
137 | "type": "NOISE",
138 | "links": [
139 | 217
140 | ],
141 | "slot_index": 0
142 | }
143 | ],
144 | "properties": {
145 | "Node name for S&R": "DisableNoise"
146 | },
147 | "widgets_values": []
148 | },
149 | {
150 | "id": 44,
151 | "type": "CLIPTextEncode",
152 | "pos": [
153 | 420,
154 | 200
155 | ],
156 | "size": [
157 | 422.84503173828125,
158 | 164.31304931640625
159 | ],
160 | "flags": {},
161 | "order": 6,
162 | "mode": 0,
163 | "inputs": [
164 | {
165 | "name": "clip",
166 | "type": "CLIP",
167 | "link": 205
168 | }
169 | ],
170 | "outputs": [
171 | {
172 | "name": "CONDITIONING",
173 | "type": "CONDITIONING",
174 | "links": [
175 | 175
176 | ],
177 | "slot_index": 0
178 | }
179 | ],
180 | "title": "CLIP Text Encode (Positive Prompt)",
181 | "properties": {
182 | "Node name for S&R": "CLIPTextEncode"
183 | },
184 | "widgets_values": [
185 | "a hippo walking across concrete at the zoo"
186 | ],
187 | "color": "#232",
188 | "bgcolor": "#353"
189 | },
190 | {
191 | "id": 83,
192 | "type": "CLIPTextEncode",
193 | "pos": [
194 | 417.337890625,
195 | 411.0529479980469
196 | ],
197 | "size": [
198 | 422.84503173828125,
199 | 164.31304931640625
200 | ],
201 | "flags": {},
202 | "order": 7,
203 | "mode": 0,
204 | "inputs": [
205 | {
206 | "name": "clip",
207 | "type": "CLIP",
208 | "link": 223
209 | }
210 | ],
211 | "outputs": [
212 | {
213 | "name": "CONDITIONING",
214 | "type": "CONDITIONING",
215 | "links": [
216 | 224
217 | ],
218 | "slot_index": 0
219 | }
220 | ],
221 | "title": "CLIP Text Encode (Positive Prompt)",
222 | "properties": {
223 | "Node name for S&R": "CLIPTextEncode"
224 | },
225 | "widgets_values": [
226 | "a dragon walking across concrete at the zoo"
227 | ],
228 | "color": "#232",
229 | "bgcolor": "#353"
230 | },
231 | {
232 | "id": 10,
233 | "type": "VAELoader",
234 | "pos": [
235 | -240,
236 | 340
237 | ],
238 | "size": [
239 | 210,
240 | 58
241 | ],
242 | "flags": {},
243 | "order": 1,
244 | "mode": 0,
245 | "inputs": [],
246 | "outputs": [
247 | {
248 | "name": "VAE",
249 | "type": "VAE",
250 | "links": [
251 | 211,
252 | 229
253 | ],
254 | "slot_index": 0,
255 | "shape": 3
256 | }
257 | ],
258 | "properties": {
259 | "Node name for S&R": "VAELoader"
260 | },
261 | "widgets_values": [
262 | "hunyuan_video_vae_bf16.safetensors"
263 | ]
264 | },
265 | {
266 | "id": 11,
267 | "type": "DualCLIPLoader",
268 | "pos": [
269 | -240,
270 | 170
271 | ],
272 | "size": [
273 | 210,
274 | 106
275 | ],
276 | "flags": {},
277 | "order": 2,
278 | "mode": 0,
279 | "inputs": [],
280 | "outputs": [
281 | {
282 | "name": "CLIP",
283 | "type": "CLIP",
284 | "links": [
285 | 205,
286 | 223
287 | ],
288 | "slot_index": 0,
289 | "shape": 3
290 | }
291 | ],
292 | "properties": {
293 | "Node name for S&R": "DualCLIPLoader"
294 | },
295 | "widgets_values": [
296 | "clip_l.safetensors",
297 | "llava_llama3_fp8_scaled.safetensors",
298 | "hunyuan_video"
299 | ]
300 | },
301 | {
302 | "id": 12,
303 | "type": "UNETLoader",
304 | "pos": [
305 | -250,
306 | 30
307 | ],
308 | "size": [
309 | 210,
310 | 82
311 | ],
312 | "flags": {},
313 | "order": 3,
314 | "mode": 0,
315 | "inputs": [],
316 | "outputs": [
317 | {
318 | "name": "MODEL",
319 | "type": "MODEL",
320 | "links": [
321 | 190,
322 | 221
323 | ],
324 | "slot_index": 0,
325 | "shape": 3
326 | }
327 | ],
328 | "properties": {
329 | "Node name for S&R": "UNETLoader"
330 | },
331 | "widgets_values": [
332 | "hunyuan_video_t2v_720p_bf16.safetensors",
333 | "fp8_e4m3fn"
334 | ],
335 | "color": "#223",
336 | "bgcolor": "#335"
337 | },
338 | {
339 | "id": 87,
340 | "type": "VAEEncode",
341 | "pos": [
342 | 605.8049926757812,
343 | 661.6065063476562
344 | ],
345 | "size": [
346 | 210,
347 | 46
348 | ],
349 | "flags": {},
350 | "order": 13,
351 | "mode": 0,
352 | "inputs": [
353 | {
354 | "name": "pixels",
355 | "type": "IMAGE",
356 | "link": 228
357 | },
358 | {
359 | "name": "vae",
360 | "type": "VAE",
361 | "link": 229
362 | }
363 | ],
364 | "outputs": [
365 | {
366 | "name": "LATENT",
367 | "type": "LATENT",
368 | "links": [
369 | 230
370 | ],
371 | "slot_index": 0
372 | }
373 | ],
374 | "properties": {
375 | "Node name for S&R": "VAEEncode"
376 | },
377 | "widgets_values": []
378 | },
379 | {
380 | "id": 78,
381 | "type": "VHS_VideoCombine",
382 | "pos": [
383 | 1724.373046875,
384 | 172.32327270507812
385 | ],
386 | "size": [
387 | 950.9851684570312,
388 | 1046.2388916015625
389 | ],
390 | "flags": {},
391 | "order": 17,
392 | "mode": 0,
393 | "inputs": [
394 | {
395 | "name": "images",
396 | "type": "IMAGE",
397 | "link": 216
398 | },
399 | {
400 | "name": "audio",
401 | "type": "AUDIO",
402 | "link": null,
403 | "shape": 7
404 | },
405 | {
406 | "name": "meta_batch",
407 | "type": "VHS_BatchManager",
408 | "link": null,
409 | "shape": 7
410 | },
411 | {
412 | "name": "vae",
413 | "type": "VAE",
414 | "link": null,
415 | "shape": 7
416 | }
417 | ],
418 | "outputs": [
419 | {
420 | "name": "Filenames",
421 | "type": "VHS_FILENAMES",
422 | "links": null
423 | }
424 | ],
425 | "properties": {
426 | "Node name for S&R": "VHS_VideoCombine"
427 | },
428 | "widgets_values": {
429 | "frame_rate": 24,
430 | "loop_count": 0,
431 | "filename_prefix": "hyloom",
432 | "format": "video/h264-mp4",
433 | "pix_fmt": "yuv420p",
434 | "crf": 19,
435 | "save_metadata": false,
436 | "trim_to_audio": false,
437 | "pingpong": false,
438 | "save_output": false,
439 | "videopreview": {
440 | "hidden": false,
441 | "paused": false,
442 | "params": {
443 | "filename": "hyloom_00007.mp4",
444 | "subfolder": "",
445 | "type": "temp",
446 | "format": "video/h264-mp4",
447 | "frame_rate": 24,
448 | "workflow": "hyloom_00007.png",
449 | "fullpath": "/workspace/ComfyUI/temp/hyloom_00007.mp4"
450 | },
451 | "muted": false
452 | }
453 | }
454 | },
455 | {
456 | "id": 85,
457 | "type": "VHS_LoadVideo",
458 | "pos": [
459 | -280,
460 | 470
461 | ],
462 | "size": [
463 | 252.056640625,
464 | 262
465 | ],
466 | "flags": {},
467 | "order": 4,
468 | "mode": 0,
469 | "inputs": [
470 | {
471 | "name": "meta_batch",
472 | "type": "VHS_BatchManager",
473 | "link": null,
474 | "shape": 7
475 | },
476 | {
477 | "name": "vae",
478 | "type": "VAE",
479 | "link": null,
480 | "shape": 7
481 | }
482 | ],
483 | "outputs": [
484 | {
485 | "name": "IMAGE",
486 | "type": "IMAGE",
487 | "links": [
488 | 227
489 | ],
490 | "slot_index": 0
491 | },
492 | {
493 | "name": "frame_count",
494 | "type": "INT",
495 | "links": null
496 | },
497 | {
498 | "name": "audio",
499 | "type": "AUDIO",
500 | "links": null
501 | },
502 | {
503 | "name": "video_info",
504 | "type": "VHS_VIDEOINFO",
505 | "links": null
506 | }
507 | ],
508 | "properties": {
509 | "Node name for S&R": "VHS_LoadVideo"
510 | },
511 | "widgets_values": {
512 | "video": "15448669-hd_1920_1080_60fps (1).mp4",
513 | "force_rate": 0,
514 | "force_size": "Disabled",
515 | "custom_width": 512,
516 | "custom_height": 512,
517 | "frame_load_cap": 49,
518 | "skip_first_frames": 0,
519 | "select_every_nth": 6,
520 | "choose video to upload": "image",
521 | "videopreview": {
522 | "hidden": false,
523 | "paused": false,
524 | "params": {
525 | "force_rate": 0,
526 | "frame_load_cap": 49,
527 | "skip_first_frames": 0,
528 | "select_every_nth": 6,
529 | "filename": "15448669-hd_1920_1080_60fps (1).mp4",
530 | "type": "input",
531 | "format": "video/mp4"
532 | },
533 | "muted": false
534 | }
535 | }
536 | },
537 | {
538 | "id": 86,
539 | "type": "ImageScale",
540 | "pos": [
541 | 9.297161102294922,
542 | 476.7259521484375
543 | ],
544 | "size": [
545 | 210,
546 | 130
547 | ],
548 | "flags": {},
549 | "order": 10,
550 | "mode": 0,
551 | "inputs": [
552 | {
553 | "name": "image",
554 | "type": "IMAGE",
555 | "link": 227
556 | }
557 | ],
558 | "outputs": [
559 | {
560 | "name": "IMAGE",
561 | "type": "IMAGE",
562 | "links": [
563 | 228
564 | ],
565 | "slot_index": 0
566 | }
567 | ],
568 | "properties": {
569 | "Node name for S&R": "ImageScale"
570 | },
571 | "widgets_values": [
572 | "nearest-exact",
573 | 640,
574 | 480,
575 | "center"
576 | ]
577 | },
578 | {
579 | "id": 26,
580 | "type": "FluxGuidance",
581 | "pos": [
582 | 852.5541381835938,
583 | 192.33192443847656
584 | ],
585 | "size": [
586 | 211.60000610351562,
587 | 58
588 | ],
589 | "flags": {},
590 | "order": 11,
591 | "mode": 0,
592 | "inputs": [
593 | {
594 | "name": "conditioning",
595 | "type": "CONDITIONING",
596 | "link": 175
597 | }
598 | ],
599 | "outputs": [
600 | {
601 | "name": "CONDITIONING",
602 | "type": "CONDITIONING",
603 | "links": [
604 | 225
605 | ],
606 | "slot_index": 0,
607 | "shape": 3
608 | }
609 | ],
610 | "properties": {
611 | "Node name for S&R": "FluxGuidance"
612 | },
613 | "widgets_values": [
614 | 1
615 | ],
616 | "color": "#233",
617 | "bgcolor": "#355"
618 | },
619 | {
620 | "id": 84,
621 | "type": "FluxGuidance",
622 | "pos": [
623 | 853.2695922851562,
624 | 425.6966857910156
625 | ],
626 | "size": [
627 | 211.60000610351562,
628 | 58
629 | ],
630 | "flags": {},
631 | "order": 12,
632 | "mode": 0,
633 | "inputs": [
634 | {
635 | "name": "conditioning",
636 | "type": "CONDITIONING",
637 | "link": 224
638 | }
639 | ],
640 | "outputs": [
641 | {
642 | "name": "CONDITIONING",
643 | "type": "CONDITIONING",
644 | "links": [
645 | 226
646 | ],
647 | "slot_index": 0,
648 | "shape": 3
649 | }
650 | ],
651 | "properties": {
652 | "Node name for S&R": "FluxGuidance"
653 | },
654 | "widgets_values": [
655 | 7
656 | ],
657 | "color": "#233",
658 | "bgcolor": "#355"
659 | },
660 | {
661 | "id": 81,
662 | "type": "HYFlowEditGuider",
663 | "pos": [
664 | 1173.615478515625,
665 | 16.504831314086914
666 | ],
667 | "size": [
668 | 203.2571258544922,
669 | 69.3235855102539
670 | ],
671 | "flags": {},
672 | "order": 14,
673 | "mode": 0,
674 | "inputs": [
675 | {
676 | "name": "model",
677 | "type": "MODEL",
678 | "link": 222
679 | },
680 | {
681 | "name": "source_cond",
682 | "type": "CONDITIONING",
683 | "link": 225
684 | },
685 | {
686 | "name": "target_cond",
687 | "type": "CONDITIONING",
688 | "link": 226
689 | }
690 | ],
691 | "outputs": [
692 | {
693 | "name": "GUIDER",
694 | "type": "GUIDER",
695 | "links": [
696 | 218
697 | ],
698 | "slot_index": 0
699 | }
700 | ],
701 | "properties": {
702 | "Node name for S&R": "HYFlowEditGuider"
703 | },
704 | "widgets_values": []
705 | },
706 | {
707 | "id": 89,
708 | "type": "HYFlowEditSampler",
709 | "pos": [
710 | 1160.8524169921875,
711 | 349.7723693847656
712 | ],
713 | "size": [
714 | 219.18406677246094,
715 | 130
716 | ],
717 | "flags": {},
718 | "order": 5,
719 | "mode": 0,
720 | "inputs": [],
721 | "outputs": [
722 | {
723 | "name": "SAMPLER",
724 | "type": "SAMPLER",
725 | "links": [
726 | 231
727 | ],
728 | "slot_index": 0
729 | }
730 | ],
731 | "properties": {
732 | "Node name for S&R": "HYFlowEditSampler"
733 | },
734 | "widgets_values": [
735 | 2,
736 | 8,
737 | 0,
738 | "fixed"
739 | ]
740 | },
741 | {
742 | "id": 17,
743 | "type": "BasicScheduler",
744 | "pos": [
745 | 1162.681640625,
746 | 528.71142578125
747 | ],
748 | "size": [
749 | 210,
750 | 106
751 | ],
752 | "flags": {},
753 | "order": 8,
754 | "mode": 0,
755 | "inputs": [
756 | {
757 | "name": "model",
758 | "type": "MODEL",
759 | "link": 190,
760 | "slot_index": 0
761 | }
762 | ],
763 | "outputs": [
764 | {
765 | "name": "SIGMAS",
766 | "type": "SIGMAS",
767 | "links": [
768 | 20
769 | ],
770 | "shape": 3
771 | }
772 | ],
773 | "properties": {
774 | "Node name for S&R": "BasicScheduler"
775 | },
776 | "widgets_values": [
777 | "simple",
778 | 30,
779 | 1
780 | ]
781 | },
782 | {
783 | "id": 82,
784 | "type": "HYReverseModelSamplingPred",
785 | "pos": [
786 | 448.6692199707031,
787 | 58.04368209838867
788 | ],
789 | "size": [
790 | 218.39999389648438,
791 | 58
792 | ],
793 | "flags": {},
794 | "order": 9,
795 | "mode": 0,
796 | "inputs": [
797 | {
798 | "name": "model",
799 | "type": "MODEL",
800 | "link": 221
801 | }
802 | ],
803 | "outputs": [
804 | {
805 | "name": "MODEL",
806 | "type": "MODEL",
807 | "links": [
808 | 222
809 | ],
810 | "slot_index": 0
811 | }
812 | ],
813 | "properties": {
814 | "Node name for S&R": "HYReverseModelSamplingPred"
815 | },
816 | "widgets_values": [
817 | 7
818 | ]
819 | }
820 | ],
821 | "links": [
822 | [
823 | 20,
824 | 17,
825 | 0,
826 | 13,
827 | 3,
828 | "SIGMAS"
829 | ],
830 | [
831 | 175,
832 | 44,
833 | 0,
834 | 26,
835 | 0,
836 | "CONDITIONING"
837 | ],
838 | [
839 | 190,
840 | 12,
841 | 0,
842 | 17,
843 | 0,
844 | "MODEL"
845 | ],
846 | [
847 | 205,
848 | 11,
849 | 0,
850 | 44,
851 | 0,
852 | "CLIP"
853 | ],
854 | [
855 | 210,
856 | 13,
857 | 0,
858 | 73,
859 | 0,
860 | "LATENT"
861 | ],
862 | [
863 | 211,
864 | 10,
865 | 0,
866 | 73,
867 | 1,
868 | "VAE"
869 | ],
870 | [
871 | 216,
872 | 73,
873 | 0,
874 | 78,
875 | 0,
876 | "IMAGE"
877 | ],
878 | [
879 | 217,
880 | 79,
881 | 0,
882 | 13,
883 | 0,
884 | "NOISE"
885 | ],
886 | [
887 | 218,
888 | 81,
889 | 0,
890 | 13,
891 | 1,
892 | "GUIDER"
893 | ],
894 | [
895 | 221,
896 | 12,
897 | 0,
898 | 82,
899 | 0,
900 | "MODEL"
901 | ],
902 | [
903 | 222,
904 | 82,
905 | 0,
906 | 81,
907 | 0,
908 | "MODEL"
909 | ],
910 | [
911 | 223,
912 | 11,
913 | 0,
914 | 83,
915 | 0,
916 | "CLIP"
917 | ],
918 | [
919 | 224,
920 | 83,
921 | 0,
922 | 84,
923 | 0,
924 | "CONDITIONING"
925 | ],
926 | [
927 | 225,
928 | 26,
929 | 0,
930 | 81,
931 | 1,
932 | "CONDITIONING"
933 | ],
934 | [
935 | 226,
936 | 84,
937 | 0,
938 | 81,
939 | 2,
940 | "CONDITIONING"
941 | ],
942 | [
943 | 227,
944 | 85,
945 | 0,
946 | 86,
947 | 0,
948 | "IMAGE"
949 | ],
950 | [
951 | 228,
952 | 86,
953 | 0,
954 | 87,
955 | 0,
956 | "IMAGE"
957 | ],
958 | [
959 | 229,
960 | 10,
961 | 0,
962 | 87,
963 | 1,
964 | "VAE"
965 | ],
966 | [
967 | 230,
968 | 87,
969 | 0,
970 | 13,
971 | 4,
972 | "LATENT"
973 | ],
974 | [
975 | 231,
976 | 89,
977 | 0,
978 | 13,
979 | 2,
980 | "SAMPLER"
981 | ]
982 | ],
983 | "groups": [],
984 | "config": {},
985 | "extra": {
986 | "ds": {
987 | "scale": 0.391425130122103,
988 | "offset": [
989 | 952.7087289433513,
990 | 499.0369677684153
991 | ]
992 | },
993 | "groupNodes": {}
994 | },
995 | "version": 0.4
996 | }
--------------------------------------------------------------------------------
/example_workflows/wrapper_example_hunyuan_flowedit.json:
--------------------------------------------------------------------------------
1 | {
2 | "last_node_id": 86,
3 | "last_link_id": 167,
4 | "nodes": [
5 | {
6 | "id": 65,
7 | "type": "HyVideoTextEncode",
8 | "pos": [
9 | 569.6162109375,
10 | -855.2640991210938
11 | ],
12 | "size": [
13 | 459.8385009765625,
14 | 345.2080383300781
15 | ],
16 | "flags": {},
17 | "order": 6,
18 | "mode": 0,
19 | "inputs": [
20 | {
21 | "name": "text_encoders",
22 | "type": "HYVIDTEXTENCODER",
23 | "link": 102
24 | },
25 | {
26 | "name": "custom_prompt_template",
27 | "type": "PROMPT_TEMPLATE",
28 | "link": null,
29 | "shape": 7
30 | },
31 | {
32 | "name": "clip_l",
33 | "type": "CLIP",
34 | "link": 103,
35 | "shape": 7
36 | },
37 | {
38 | "name": "hyvid_cfg",
39 | "type": "HYVID_CFG",
40 | "link": null,
41 | "shape": 7
42 | }
43 | ],
44 | "outputs": [
45 | {
46 | "name": "hyvid_embeds",
47 | "type": "HYVIDEMBEDS",
48 | "links": [
49 | 164
50 | ],
51 | "slot_index": 0
52 | }
53 | ],
54 | "properties": {
55 | "Node name for S&R": "HyVideoTextEncode"
56 | },
57 | "widgets_values": [
58 | "Main content and theme: cinematic and photorealistic video of a helicopter hovering in place while resting on the platform of a helipad \nObject details: \na helicopter \nRainforest background \nThe video style is very cinematic and has dramatic lighting \nActions and movements: a helicopter's rotor blades are spinning \nBackground and atmosphere: \nThe background is a peaceful rainforest, which creates a serene, calm atmosphere \nmasterpiece, best quality ",
59 | true,
60 | "video"
61 | ]
62 | },
63 | {
64 | "id": 85,
65 | "type": "HyVideoTextEncode",
66 | "pos": [
67 | 572.2459716796875,
68 | -1254.3387451171875
69 | ],
70 | "size": [
71 | 459.8385009765625,
72 | 345.2080383300781
73 | ],
74 | "flags": {},
75 | "order": 7,
76 | "mode": 0,
77 | "inputs": [
78 | {
79 | "name": "text_encoders",
80 | "type": "HYVIDTEXTENCODER",
81 | "link": 158
82 | },
83 | {
84 | "name": "custom_prompt_template",
85 | "type": "PROMPT_TEMPLATE",
86 | "link": null,
87 | "shape": 7
88 | },
89 | {
90 | "name": "clip_l",
91 | "type": "CLIP",
92 | "link": 157,
93 | "shape": 7
94 | },
95 | {
96 | "name": "hyvid_cfg",
97 | "type": "HYVID_CFG",
98 | "link": null,
99 | "shape": 7
100 | }
101 | ],
102 | "outputs": [
103 | {
104 | "name": "hyvid_embeds",
105 | "type": "HYVIDEMBEDS",
106 | "links": [
107 | 163
108 | ],
109 | "slot_index": 0
110 | }
111 | ],
112 | "properties": {
113 | "Node name for S&R": "HyVideoTextEncode"
114 | },
115 | "widgets_values": [
116 | "Main content and theme: cinematic and photorealistic video of a parrot flapping its wings while perched on the hand of a woman\nObject details:\na parrot\nRainforest background\nThe video style is very cinematic and has dramatic lighting\nActions and movements: a parrot is flapping its wings\nBackground and atmosphere:\nThe background is a peaceful rainforest, which creates a serene, calm atmosphere\nmasterpiece, best quality",
117 | true,
118 | "video"
119 | ]
120 | },
121 | {
122 | "id": 71,
123 | "type": "GetImageSizeAndCount",
124 | "pos": [
125 | 438.6930236816406,
126 | -58.08594512939453
127 | ],
128 | "size": [
129 | 277.20001220703125,
130 | 86
131 | ],
132 | "flags": {},
133 | "order": 10,
134 | "mode": 0,
135 | "inputs": [
136 | {
137 | "name": "image",
138 | "type": "IMAGE",
139 | "link": 120
140 | }
141 | ],
142 | "outputs": [
143 | {
144 | "name": "image",
145 | "type": "IMAGE",
146 | "links": [
147 | 117
148 | ],
149 | "slot_index": 0
150 | },
151 | {
152 | "name": "960 width",
153 | "type": "INT",
154 | "links": [],
155 | "slot_index": 1
156 | },
157 | {
158 | "name": "544 height",
159 | "type": "INT",
160 | "links": [],
161 | "slot_index": 2
162 | },
163 | {
164 | "name": "49 count",
165 | "type": "INT",
166 | "links": [],
167 | "slot_index": 3
168 | }
169 | ],
170 | "properties": {
171 | "Node name for S&R": "GetImageSizeAndCount"
172 | },
173 | "widgets_values": []
174 | },
175 | {
176 | "id": 72,
177 | "type": "SetNode",
178 | "pos": [
179 | 449.2713317871094,
180 | 97.60063934326172
181 | ],
182 | "size": [
183 | 210,
184 | 58
185 | ],
186 | "flags": {
187 | "collapsed": true
188 | },
189 | "order": 9,
190 | "mode": 0,
191 | "inputs": [
192 | {
193 | "name": "IMAGE",
194 | "type": "IMAGE",
195 | "link": 119
196 | }
197 | ],
198 | "outputs": [
199 | {
200 | "name": "IMAGE",
201 | "type": "IMAGE",
202 | "links": [
203 | 120
204 | ],
205 | "slot_index": 0
206 | }
207 | ],
208 | "title": "Set_InputVideo",
209 | "properties": {
210 | "previousName": "InputVideo"
211 | },
212 | "widgets_values": [
213 | "InputVideo"
214 | ],
215 | "color": "#2a363b",
216 | "bgcolor": "#3f5159"
217 | },
218 | {
219 | "id": 62,
220 | "type": "ImageResizeKJ",
221 | "pos": [
222 | 96.65345764160156,
223 | -54.70817947387695
224 | ],
225 | "size": [
226 | 315,
227 | 266
228 | ],
229 | "flags": {},
230 | "order": 8,
231 | "mode": 0,
232 | "inputs": [
233 | {
234 | "name": "image",
235 | "type": "IMAGE",
236 | "link": 75
237 | },
238 | {
239 | "name": "get_image_size",
240 | "type": "IMAGE",
241 | "link": null,
242 | "shape": 7
243 | },
244 | {
245 | "name": "width_input",
246 | "type": "INT",
247 | "link": null,
248 | "widget": {
249 | "name": "width_input"
250 | },
251 | "shape": 7
252 | },
253 | {
254 | "name": "height_input",
255 | "type": "INT",
256 | "link": null,
257 | "widget": {
258 | "name": "height_input"
259 | },
260 | "shape": 7
261 | }
262 | ],
263 | "outputs": [
264 | {
265 | "name": "IMAGE",
266 | "type": "IMAGE",
267 | "links": [
268 | 119
269 | ],
270 | "slot_index": 0
271 | },
272 | {
273 | "name": "width",
274 | "type": "INT",
275 | "links": [],
276 | "slot_index": 1
277 | },
278 | {
279 | "name": "height",
280 | "type": "INT",
281 | "links": [],
282 | "slot_index": 2
283 | }
284 | ],
285 | "properties": {
286 | "Node name for S&R": "ImageResizeKJ"
287 | },
288 | "widgets_values": [
289 | 960,
290 | 544,
291 | "lanczos",
292 | false,
293 | 16,
294 | 0,
295 | 0,
296 | "center"
297 | ]
298 | },
299 | {
300 | "id": 16,
301 | "type": "DownloadAndLoadHyVideoTextEncoder",
302 | "pos": [
303 | -310.33868408203125,
304 | -1085.5028076171875
305 | ],
306 | "size": [
307 | 429.6711730957031,
308 | 178
309 | ],
310 | "flags": {},
311 | "order": 0,
312 | "mode": 0,
313 | "inputs": [],
314 | "outputs": [
315 | {
316 | "name": "hyvid_text_encoder",
317 | "type": "HYVIDTEXTENCODER",
318 | "links": [
319 | 102,
320 | 158
321 | ],
322 | "slot_index": 0
323 | }
324 | ],
325 | "properties": {
326 | "Node name for S&R": "DownloadAndLoadHyVideoTextEncoder"
327 | },
328 | "widgets_values": [
329 | "Kijai/llava-llama-3-8b-text-encoder-tokenizer",
330 | "disabled",
331 | "fp16",
332 | false,
333 | 2,
334 | "disabled"
335 | ]
336 | },
337 | {
338 | "id": 43,
339 | "type": "CLIPLoader",
340 | "pos": [
341 | -190.31114196777344,
342 | -834.338134765625
343 | ],
344 | "size": [
345 | 267.4123840332031,
346 | 82
347 | ],
348 | "flags": {},
349 | "order": 1,
350 | "mode": 0,
351 | "inputs": [],
352 | "outputs": [
353 | {
354 | "name": "CLIP",
355 | "type": "CLIP",
356 | "links": [
357 | 103,
358 | 157
359 | ],
360 | "slot_index": 0
361 | }
362 | ],
363 | "properties": {
364 | "Node name for S&R": "CLIPLoader"
365 | },
366 | "widgets_values": [
367 | "clip_l.safetensors",
368 | "stable_diffusion",
369 | "default"
370 | ]
371 | },
372 | {
373 | "id": 86,
374 | "type": "HyVideoFlowEditSamplerWrapper",
375 | "pos": [
376 | 1153.6915283203125,
377 | -219.83078002929688
378 | ],
379 | "size": [
380 | 400.9231262207031,
381 | 570
382 | ],
383 | "flags": {},
384 | "order": 12,
385 | "mode": 0,
386 | "inputs": [
387 | {
388 | "name": "model",
389 | "type": "HYVIDEOMODEL",
390 | "link": 167
391 | },
392 | {
393 | "name": "source_embeds",
394 | "type": "HYVIDEMBEDS",
395 | "link": 163
396 | },
397 | {
398 | "name": "target_embeds",
399 | "type": "HYVIDEMBEDS",
400 | "link": 164
401 | },
402 | {
403 | "name": "samples",
404 | "type": "LATENT",
405 | "link": 165
406 | }
407 | ],
408 | "outputs": [
409 | {
410 | "name": "samples",
411 | "type": "LATENT",
412 | "links": [
413 | 166
414 | ]
415 | }
416 | ],
417 | "properties": {
418 | "Node name for S&R": "HyVideoFlowEditSamplerWrapper"
419 | },
420 | "widgets_values": [
421 | 30,
422 | 4,
423 | 0,
424 | 6,
425 | 12,
426 | 6,
427 | 6,
428 | 3,
429 | 0,
430 | "fixed",
431 | true
432 | ]
433 | },
434 | {
435 | "id": 7,
436 | "type": "HyVideoVAELoader",
437 | "pos": [
438 | -399.6872253417969,
439 | -457.69366455078125
440 | ],
441 | "size": [
442 | 466.5,
443 | 82
444 | ],
445 | "flags": {},
446 | "order": 2,
447 | "mode": 0,
448 | "inputs": [
449 | {
450 | "name": "compile_args",
451 | "type": "COMPILEARGS",
452 | "link": null,
453 | "shape": 7
454 | }
455 | ],
456 | "outputs": [
457 | {
458 | "name": "vae",
459 | "type": "VAE",
460 | "links": [
461 | 73,
462 | 105
463 | ],
464 | "slot_index": 0
465 | }
466 | ],
467 | "properties": {
468 | "Node name for S&R": "HyVideoVAELoader"
469 | },
470 | "widgets_values": [
471 | "hyvid\\hunyuan_video_vae_bf16.safetensors",
472 | "bf16"
473 | ]
474 | },
475 | {
476 | "id": 1,
477 | "type": "HyVideoModelLoader",
478 | "pos": [
479 | -431.7147521972656,
480 | -310.651123046875
481 | ],
482 | "size": [
483 | 509.7506103515625,
484 | 218
485 | ],
486 | "flags": {},
487 | "order": 3,
488 | "mode": 0,
489 | "inputs": [
490 | {
491 | "name": "compile_args",
492 | "type": "COMPILEARGS",
493 | "link": null,
494 | "shape": 7
495 | },
496 | {
497 | "name": "block_swap_args",
498 | "type": "BLOCKSWAPARGS",
499 | "link": null,
500 | "shape": 7
501 | },
502 | {
503 | "name": "lora",
504 | "type": "HYVIDLORA",
505 | "link": null,
506 | "shape": 7
507 | }
508 | ],
509 | "outputs": [
510 | {
511 | "name": "model",
512 | "type": "HYVIDEOMODEL",
513 | "links": [
514 | 167
515 | ],
516 | "slot_index": 0
517 | }
518 | ],
519 | "properties": {
520 | "Node name for S&R": "HyVideoModelLoader"
521 | },
522 | "widgets_values": [
523 | "hyvideo\\hunyuan_video_720_fp8_e4m3fn.safetensors",
524 | "bf16",
525 | "fp8_e4m3fn",
526 | "offload_device",
527 | "sageattn_varlen",
528 | false
529 | ]
530 | },
531 | {
532 | "id": 60,
533 | "type": "VHS_LoadVideo",
534 | "pos": [
535 | -215.327880859375,
536 | -22.302289962768555
537 | ],
538 | "size": [
539 | 252.056640625,
540 | 508.056640625
541 | ],
542 | "flags": {},
543 | "order": 4,
544 | "mode": 0,
545 | "inputs": [
546 | {
547 | "name": "meta_batch",
548 | "type": "VHS_BatchManager",
549 | "link": null,
550 | "shape": 7
551 | },
552 | {
553 | "name": "vae",
554 | "type": "VAE",
555 | "link": null,
556 | "shape": 7
557 | }
558 | ],
559 | "outputs": [
560 | {
561 | "name": "IMAGE",
562 | "type": "IMAGE",
563 | "links": [
564 | 75
565 | ],
566 | "slot_index": 0
567 | },
568 | {
569 | "name": "frame_count",
570 | "type": "INT",
571 | "links": [],
572 | "slot_index": 1
573 | },
574 | {
575 | "name": "audio",
576 | "type": "AUDIO",
577 | "links": null
578 | },
579 | {
580 | "name": "video_info",
581 | "type": "VHS_VIDEOINFO",
582 | "links": null
583 | }
584 | ],
585 | "properties": {
586 | "Node name for S&R": "VHS_LoadVideo"
587 | },
588 | "widgets_values": {
589 | "video": "wolf_interpolated.mp4",
590 | "force_rate": 0,
591 | "force_size": "Disabled",
592 | "custom_width": 512,
593 | "custom_height": 512,
594 | "frame_load_cap": 49,
595 | "skip_first_frames": 0,
596 | "select_every_nth": 1,
597 | "choose video to upload": "image",
598 | "videopreview": {
599 | "hidden": false,
600 | "paused": false,
601 | "params": {
602 | "frame_load_cap": 49,
603 | "skip_first_frames": 0,
604 | "force_rate": 0,
605 | "filename": "wolf_interpolated.mp4",
606 | "type": "input",
607 | "format": "video/mp4",
608 | "select_every_nth": 1
609 | },
610 | "muted": false
611 | }
612 | }
613 | },
614 | {
615 | "id": 61,
616 | "type": "HyVideoEncode",
617 | "pos": [
618 | 772.994140625,
619 | -137.0120849609375
620 | ],
621 | "size": [
622 | 315,
623 | 150
624 | ],
625 | "flags": {},
626 | "order": 11,
627 | "mode": 0,
628 | "inputs": [
629 | {
630 | "name": "vae",
631 | "type": "VAE",
632 | "link": 73
633 | },
634 | {
635 | "name": "image",
636 | "type": "IMAGE",
637 | "link": 117
638 | }
639 | ],
640 | "outputs": [
641 | {
642 | "name": "samples",
643 | "type": "LATENT",
644 | "links": [
645 | 165
646 | ],
647 | "slot_index": 0
648 | }
649 | ],
650 | "properties": {
651 | "Node name for S&R": "HyVideoEncode"
652 | },
653 | "widgets_values": [
654 | true,
655 | 64,
656 | 256,
657 | true
658 | ]
659 | },
660 | {
661 | "id": 66,
662 | "type": "HyVideoDecode",
663 | "pos": [
664 | 1228.44970703125,
665 | -446.55419921875
666 | ],
667 | "size": [
668 | 292.81866455078125,
669 | 150
670 | ],
671 | "flags": {},
672 | "order": 13,
673 | "mode": 0,
674 | "inputs": [
675 | {
676 | "name": "vae",
677 | "type": "VAE",
678 | "link": 105
679 | },
680 | {
681 | "name": "samples",
682 | "type": "LATENT",
683 | "link": 166
684 | }
685 | ],
686 | "outputs": [
687 | {
688 | "name": "images",
689 | "type": "IMAGE",
690 | "links": [
691 | 113
692 | ],
693 | "slot_index": 0
694 | }
695 | ],
696 | "properties": {
697 | "Node name for S&R": "HyVideoDecode"
698 | },
699 | "widgets_values": [
700 | true,
701 | 64,
702 | 128,
703 | true
704 | ]
705 | },
706 | {
707 | "id": 68,
708 | "type": "ImageConcatMulti",
709 | "pos": [
710 | 1544.142578125,
711 | -461.7588806152344
712 | ],
713 | "size": [
714 | 210,
715 | 150
716 | ],
717 | "flags": {},
718 | "order": 14,
719 | "mode": 0,
720 | "inputs": [
721 | {
722 | "name": "image_1",
723 | "type": "IMAGE",
724 | "link": 121
725 | },
726 | {
727 | "name": "image_2",
728 | "type": "IMAGE",
729 | "link": 113
730 | }
731 | ],
732 | "outputs": [
733 | {
734 | "name": "images",
735 | "type": "IMAGE",
736 | "links": [
737 | 114
738 | ],
739 | "slot_index": 0
740 | }
741 | ],
742 | "properties": {},
743 | "widgets_values": [
744 | 2,
745 | "right",
746 | false,
747 | null
748 | ]
749 | },
750 | {
751 | "id": 73,
752 | "type": "GetNode",
753 | "pos": [
754 | 1546.0333251953125,
755 | -527.7788696289062
756 | ],
757 | "size": [
758 | 210,
759 | 58
760 | ],
761 | "flags": {
762 | "collapsed": true
763 | },
764 | "order": 5,
765 | "mode": 0,
766 | "inputs": [],
767 | "outputs": [
768 | {
769 | "name": "IMAGE",
770 | "type": "IMAGE",
771 | "links": [
772 | 121
773 | ],
774 | "slot_index": 0
775 | }
776 | ],
777 | "title": "Get_InputVideo",
778 | "properties": {},
779 | "widgets_values": [
780 | "InputVideo"
781 | ],
782 | "color": "#2a363b",
783 | "bgcolor": "#3f5159"
784 | },
785 | {
786 | "id": 69,
787 | "type": "VHS_VideoCombine",
788 | "pos": [
789 | 1822.6951904296875,
790 | -464.15716552734375
791 | ],
792 | "size": [
793 | 1098.79248046875,
794 | 334
795 | ],
796 | "flags": {},
797 | "order": 15,
798 | "mode": 0,
799 | "inputs": [
800 | {
801 | "name": "images",
802 | "type": "IMAGE",
803 | "link": 114
804 | },
805 | {
806 | "name": "audio",
807 | "type": "AUDIO",
808 | "link": null,
809 | "shape": 7
810 | },
811 | {
812 | "name": "meta_batch",
813 | "type": "VHS_BatchManager",
814 | "link": null,
815 | "shape": 7
816 | },
817 | {
818 | "name": "vae",
819 | "type": "VAE",
820 | "link": null,
821 | "shape": 7
822 | }
823 | ],
824 | "outputs": [
825 | {
826 | "name": "Filenames",
827 | "type": "VHS_FILENAMES",
828 | "links": null
829 | }
830 | ],
831 | "properties": {
832 | "Node name for S&R": "VHS_VideoCombine"
833 | },
834 | "widgets_values": {
835 | "frame_rate": 24,
836 | "loop_count": 0,
837 | "filename_prefix": "hunyuanloom",
838 | "format": "video/h264-mp4",
839 | "pix_fmt": "yuv420p",
840 | "crf": 19,
841 | "save_metadata": false,
842 | "trim_to_audio": false,
843 | "pingpong": false,
844 | "save_output": true,
845 | "videopreview": {
846 | "hidden": false,
847 | "paused": false,
848 | "params": {
849 | "filename": "HunyuanVideo_00014.mp4",
850 | "subfolder": "",
851 | "type": "temp",
852 | "format": "video/h264-mp4",
853 | "frame_rate": 24,
854 | "workflow": "HunyuanVideo_00014.png",
855 | "fullpath": "/workspace/ComfyUI/temp/HunyuanVideo_00014.mp4"
856 | },
857 | "muted": false
858 | }
859 | }
860 | }
861 | ],
862 | "links": [
863 | [
864 | 73,
865 | 7,
866 | 0,
867 | 61,
868 | 0,
869 | "VAE"
870 | ],
871 | [
872 | 75,
873 | 60,
874 | 0,
875 | 62,
876 | 0,
877 | "IMAGE"
878 | ],
879 | [
880 | 102,
881 | 16,
882 | 0,
883 | 65,
884 | 0,
885 | "HYVIDTEXTENCODER"
886 | ],
887 | [
888 | 103,
889 | 43,
890 | 0,
891 | 65,
892 | 2,
893 | "CLIP"
894 | ],
895 | [
896 | 105,
897 | 7,
898 | 0,
899 | 66,
900 | 0,
901 | "VAE"
902 | ],
903 | [
904 | 113,
905 | 66,
906 | 0,
907 | 68,
908 | 1,
909 | "IMAGE"
910 | ],
911 | [
912 | 114,
913 | 68,
914 | 0,
915 | 69,
916 | 0,
917 | "IMAGE"
918 | ],
919 | [
920 | 117,
921 | 71,
922 | 0,
923 | 61,
924 | 1,
925 | "IMAGE"
926 | ],
927 | [
928 | 119,
929 | 62,
930 | 0,
931 | 72,
932 | 0,
933 | "*"
934 | ],
935 | [
936 | 120,
937 | 72,
938 | 0,
939 | 71,
940 | 0,
941 | "IMAGE"
942 | ],
943 | [
944 | 121,
945 | 73,
946 | 0,
947 | 68,
948 | 0,
949 | "IMAGE"
950 | ],
951 | [
952 | 157,
953 | 43,
954 | 0,
955 | 85,
956 | 2,
957 | "CLIP"
958 | ],
959 | [
960 | 158,
961 | 16,
962 | 0,
963 | 85,
964 | 0,
965 | "HYVIDTEXTENCODER"
966 | ],
967 | [
968 | 163,
969 | 85,
970 | 0,
971 | 86,
972 | 1,
973 | "HYVIDEMBEDS"
974 | ],
975 | [
976 | 164,
977 | 65,
978 | 0,
979 | 86,
980 | 2,
981 | "HYVIDEMBEDS"
982 | ],
983 | [
984 | 165,
985 | 61,
986 | 0,
987 | 86,
988 | 3,
989 | "LATENT"
990 | ],
991 | [
992 | 166,
993 | 86,
994 | 0,
995 | 66,
996 | 1,
997 | "LATENT"
998 | ],
999 | [
1000 | 167,
1001 | 1,
1002 | 0,
1003 | 86,
1004 | 0,
1005 | "HYVIDEOMODEL"
1006 | ]
1007 | ],
1008 | "groups": [],
1009 | "config": {},
1010 | "extra": {
1011 | "ds": {
1012 | "scale": 0.6402987863296646,
1013 | "offset": [
1014 | 485.09283743323897,
1015 | 1208.6430569039285
1016 | ]
1017 | },
1018 | "VHS_latentpreview": false,
1019 | "VHS_latentpreviewrate": 0
1020 | },
1021 | "version": 0.4
1022 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/example_workflows/example_hy_regional_prompting_t2v.json:
--------------------------------------------------------------------------------
1 | {
2 | "last_node_id": 101,
3 | "last_link_id": 277,
4 | "nodes": [
5 | {
6 | "id": 16,
7 | "type": "KSamplerSelect",
8 | "pos": [
9 | 484,
10 | 751
11 | ],
12 | "size": [
13 | 315,
14 | 58
15 | ],
16 | "flags": {},
17 | "order": 0,
18 | "mode": 0,
19 | "inputs": [],
20 | "outputs": [
21 | {
22 | "name": "SAMPLER",
23 | "type": "SAMPLER",
24 | "links": [
25 | 19
26 | ],
27 | "shape": 3
28 | }
29 | ],
30 | "properties": {
31 | "Node name for S&R": "KSamplerSelect"
32 | },
33 | "widgets_values": [
34 | "euler"
35 | ]
36 | },
37 | {
38 | "id": 10,
39 | "type": "VAELoader",
40 | "pos": [
41 | 0,
42 | 420
43 | ],
44 | "size": [
45 | 350,
46 | 60
47 | ],
48 | "flags": {},
49 | "order": 1,
50 | "mode": 0,
51 | "inputs": [],
52 | "outputs": [
53 | {
54 | "name": "VAE",
55 | "type": "VAE",
56 | "links": [
57 | 211
58 | ],
59 | "slot_index": 0,
60 | "shape": 3
61 | }
62 | ],
63 | "properties": {
64 | "Node name for S&R": "VAELoader"
65 | },
66 | "widgets_values": [
67 | "hunyuan_video_vae_bf16.safetensors"
68 | ]
69 | },
70 | {
71 | "id": 13,
72 | "type": "SamplerCustomAdvanced",
73 | "pos": [
74 | 1950,
75 | 190
76 | ],
77 | "size": [
78 | 272.3617858886719,
79 | 124.53733825683594
80 | ],
81 | "flags": {},
82 | "order": 30,
83 | "mode": 0,
84 | "inputs": [
85 | {
86 | "name": "noise",
87 | "type": "NOISE",
88 | "link": 37,
89 | "slot_index": 0
90 | },
91 | {
92 | "name": "guider",
93 | "type": "GUIDER",
94 | "link": 30,
95 | "slot_index": 1
96 | },
97 | {
98 | "name": "sampler",
99 | "type": "SAMPLER",
100 | "link": 19,
101 | "slot_index": 2
102 | },
103 | {
104 | "name": "sigmas",
105 | "type": "SIGMAS",
106 | "link": 20,
107 | "slot_index": 3
108 | },
109 | {
110 | "name": "latent_image",
111 | "type": "LATENT",
112 | "link": 180,
113 | "slot_index": 4
114 | }
115 | ],
116 | "outputs": [
117 | {
118 | "name": "output",
119 | "type": "LATENT",
120 | "links": [
121 | 210
122 | ],
123 | "slot_index": 0,
124 | "shape": 3
125 | },
126 | {
127 | "name": "denoised_output",
128 | "type": "LATENT",
129 | "links": null,
130 | "shape": 3
131 | }
132 | ],
133 | "properties": {
134 | "Node name for S&R": "SamplerCustomAdvanced"
135 | },
136 | "widgets_values": []
137 | },
138 | {
139 | "id": 22,
140 | "type": "BasicGuider",
141 | "pos": [
142 | 1637.3946533203125,
143 | 94.65210723876953
144 | ],
145 | "size": [
146 | 222.3482666015625,
147 | 46
148 | ],
149 | "flags": {},
150 | "order": 29,
151 | "mode": 0,
152 | "inputs": [
153 | {
154 | "name": "model",
155 | "type": "MODEL",
156 | "link": 224,
157 | "slot_index": 0
158 | },
159 | {
160 | "name": "conditioning",
161 | "type": "CONDITIONING",
162 | "link": 129,
163 | "slot_index": 1
164 | }
165 | ],
166 | "outputs": [
167 | {
168 | "name": "GUIDER",
169 | "type": "GUIDER",
170 | "links": [
171 | 30
172 | ],
173 | "slot_index": 0,
174 | "shape": 3
175 | }
176 | ],
177 | "properties": {
178 | "Node name for S&R": "BasicGuider"
179 | },
180 | "widgets_values": []
181 | },
182 | {
183 | "id": 82,
184 | "type": "ConfigureModifiedHY",
185 | "pos": [
186 | 385.38446044921875,
187 | -93.34419250488281
188 | ],
189 | "size": [
190 | 252,
191 | 26
192 | ],
193 | "flags": {},
194 | "order": 12,
195 | "mode": 0,
196 | "inputs": [
197 | {
198 | "name": "model",
199 | "type": "MODEL",
200 | "link": 221
201 | }
202 | ],
203 | "outputs": [
204 | {
205 | "name": "MODEL",
206 | "type": "MODEL",
207 | "links": [
208 | 222
209 | ],
210 | "slot_index": 0
211 | }
212 | ],
213 | "properties": {
214 | "Node name for S&R": "ConfigureModifiedHY"
215 | },
216 | "widgets_values": []
217 | },
218 | {
219 | "id": 26,
220 | "type": "FluxGuidance",
221 | "pos": [
222 | 520,
223 | 100
224 | ],
225 | "size": [
226 | 317.4000244140625,
227 | 58
228 | ],
229 | "flags": {},
230 | "order": 21,
231 | "mode": 0,
232 | "inputs": [
233 | {
234 | "name": "conditioning",
235 | "type": "CONDITIONING",
236 | "link": 175
237 | }
238 | ],
239 | "outputs": [
240 | {
241 | "name": "CONDITIONING",
242 | "type": "CONDITIONING",
243 | "links": [
244 | 129,
245 | 226
246 | ],
247 | "slot_index": 0,
248 | "shape": 3
249 | }
250 | ],
251 | "properties": {
252 | "Node name for S&R": "FluxGuidance"
253 | },
254 | "widgets_values": [
255 | 6
256 | ],
257 | "color": "#233",
258 | "bgcolor": "#355"
259 | },
260 | {
261 | "id": 12,
262 | "type": "UNETLoader",
263 | "pos": [
264 | 0,
265 | 150
266 | ],
267 | "size": [
268 | 350,
269 | 82
270 | ],
271 | "flags": {},
272 | "order": 2,
273 | "mode": 0,
274 | "inputs": [],
275 | "outputs": [
276 | {
277 | "name": "MODEL",
278 | "type": "MODEL",
279 | "links": [
280 | 190,
281 | 221
282 | ],
283 | "slot_index": 0,
284 | "shape": 3
285 | }
286 | ],
287 | "properties": {
288 | "Node name for S&R": "UNETLoader"
289 | },
290 | "widgets_values": [
291 | "hunyuan_video_t2v_720p_bf16.safetensors",
292 | "fp8_e4m3fn"
293 | ],
294 | "color": "#223",
295 | "bgcolor": "#335"
296 | },
297 | {
298 | "id": 73,
299 | "type": "VAEDecodeTiled",
300 | "pos": [
301 | 2240,
302 | 190
303 | ],
304 | "size": [
305 | 210,
306 | 102
307 | ],
308 | "flags": {},
309 | "order": 31,
310 | "mode": 0,
311 | "inputs": [
312 | {
313 | "name": "samples",
314 | "type": "LATENT",
315 | "link": 210
316 | },
317 | {
318 | "name": "vae",
319 | "type": "VAE",
320 | "link": 211
321 | }
322 | ],
323 | "outputs": [
324 | {
325 | "name": "IMAGE",
326 | "type": "IMAGE",
327 | "links": [
328 | 227
329 | ],
330 | "slot_index": 0
331 | }
332 | ],
333 | "properties": {
334 | "Node name for S&R": "VAEDecodeTiled"
335 | },
336 | "widgets_values": [
337 | 256,
338 | 64
339 | ]
340 | },
341 | {
342 | "id": 11,
343 | "type": "DualCLIPLoader",
344 | "pos": [
345 | 0,
346 | 270
347 | ],
348 | "size": [
349 | 350,
350 | 106
351 | ],
352 | "flags": {},
353 | "order": 3,
354 | "mode": 0,
355 | "inputs": [],
356 | "outputs": [
357 | {
358 | "name": "CLIP",
359 | "type": "CLIP",
360 | "links": [
361 | 205,
362 | 225,
363 | 242,
364 | 243
365 | ],
366 | "slot_index": 0,
367 | "shape": 3
368 | }
369 | ],
370 | "properties": {
371 | "Node name for S&R": "DualCLIPLoader"
372 | },
373 | "widgets_values": [
374 | "clip_l.safetensors",
375 | "llava_llama3_fp8_scaled.safetensors",
376 | "hunyuan_video"
377 | ]
378 | },
379 | {
380 | "id": 67,
381 | "type": "ModelSamplingSD3",
382 | "pos": [
383 | 751.6845703125,
384 | -31.64067268371582
385 | ],
386 | "size": [
387 | 210,
388 | 58
389 | ],
390 | "flags": {},
391 | "order": 20,
392 | "mode": 0,
393 | "inputs": [
394 | {
395 | "name": "model",
396 | "type": "MODEL",
397 | "link": 222
398 | }
399 | ],
400 | "outputs": [
401 | {
402 | "name": "MODEL",
403 | "type": "MODEL",
404 | "links": [
405 | 223
406 | ],
407 | "slot_index": 0
408 | }
409 | ],
410 | "properties": {
411 | "Node name for S&R": "ModelSamplingSD3"
412 | },
413 | "widgets_values": [
414 | 9
415 | ]
416 | },
417 | {
418 | "id": 17,
419 | "type": "BasicScheduler",
420 | "pos": [
421 | 478,
422 | 860
423 | ],
424 | "size": [
425 | 315,
426 | 106
427 | ],
428 | "flags": {},
429 | "order": 11,
430 | "mode": 0,
431 | "inputs": [
432 | {
433 | "name": "model",
434 | "type": "MODEL",
435 | "link": 190,
436 | "slot_index": 0
437 | }
438 | ],
439 | "outputs": [
440 | {
441 | "name": "SIGMAS",
442 | "type": "SIGMAS",
443 | "links": [
444 | 20
445 | ],
446 | "shape": 3
447 | }
448 | ],
449 | "properties": {
450 | "Node name for S&R": "BasicScheduler"
451 | },
452 | "widgets_values": [
453 | "simple",
454 | 30,
455 | 1
456 | ]
457 | },
458 | {
459 | "id": 84,
460 | "type": "VHS_VideoCombine",
461 | "pos": [
462 | 2509.404296875,
463 | 79.10501098632812
464 | ],
465 | "size": [
466 | 802.333984375,
467 | 790.83056640625
468 | ],
469 | "flags": {},
470 | "order": 32,
471 | "mode": 0,
472 | "inputs": [
473 | {
474 | "name": "images",
475 | "type": "IMAGE",
476 | "link": 227
477 | },
478 | {
479 | "name": "audio",
480 | "type": "AUDIO",
481 | "link": null,
482 | "shape": 7
483 | },
484 | {
485 | "name": "meta_batch",
486 | "type": "VHS_BatchManager",
487 | "link": null,
488 | "shape": 7
489 | },
490 | {
491 | "name": "vae",
492 | "type": "VAE",
493 | "link": null,
494 | "shape": 7
495 | }
496 | ],
497 | "outputs": [
498 | {
499 | "name": "Filenames",
500 | "type": "VHS_FILENAMES",
501 | "links": null
502 | }
503 | ],
504 | "properties": {
505 | "Node name for S&R": "VHS_VideoCombine"
506 | },
507 | "widgets_values": {
508 | "frame_rate": 24,
509 | "loop_count": 0,
510 | "filename_prefix": "AnimateDiff",
511 | "format": "video/h264-mp4",
512 | "pix_fmt": "yuv420p",
513 | "crf": 19,
514 | "save_metadata": false,
515 | "trim_to_audio": false,
516 | "pingpong": false,
517 | "save_output": false,
518 | "videopreview": {
519 | "hidden": false,
520 | "paused": false,
521 | "params": {
522 | "filename": "AnimateDiff_00011.mp4",
523 | "subfolder": "",
524 | "type": "temp",
525 | "format": "video/h264-mp4",
526 | "frame_rate": 24,
527 | "workflow": "AnimateDiff_00011.png",
528 | "fullpath": "/workspace/ComfyUI/temp/AnimateDiff_00011.mp4"
529 | },
530 | "muted": false
531 | }
532 | }
533 | },
534 | {
535 | "id": 45,
536 | "type": "EmptyHunyuanLatentVideo",
537 | "pos": [
538 | 475.540771484375,
539 | 432.673583984375
540 | ],
541 | "size": [
542 | 315,
543 | 130
544 | ],
545 | "flags": {},
546 | "order": 4,
547 | "mode": 0,
548 | "inputs": [],
549 | "outputs": [
550 | {
551 | "name": "LATENT",
552 | "type": "LATENT",
553 | "links": [
554 | 180,
555 | 220
556 | ],
557 | "slot_index": 0
558 | }
559 | ],
560 | "properties": {
561 | "Node name for S&R": "EmptyHunyuanLatentVideo"
562 | },
563 | "widgets_values": [
564 | 848,
565 | 480,
566 | 49,
567 | 1
568 | ]
569 | },
570 | {
571 | "id": 95,
572 | "type": "CLIPTextEncode",
573 | "pos": [
574 | 580,
575 | -1680
576 | ],
577 | "size": [
578 | 422.84503173828125,
579 | 164.31304931640625
580 | ],
581 | "flags": {},
582 | "order": 16,
583 | "mode": 0,
584 | "inputs": [
585 | {
586 | "name": "clip",
587 | "type": "CLIP",
588 | "link": 243
589 | }
590 | ],
591 | "outputs": [
592 | {
593 | "name": "CONDITIONING",
594 | "type": "CONDITIONING",
595 | "links": [
596 | 238
597 | ],
598 | "slot_index": 0
599 | }
600 | ],
601 | "title": "CLIP Text Encode (Positive Prompt)",
602 | "properties": {
603 | "Node name for S&R": "CLIPTextEncode"
604 | },
605 | "widgets_values": [
606 | "an hd video of a city street scene with flying ships in the sky"
607 | ],
608 | "color": "#232",
609 | "bgcolor": "#353"
610 | },
611 | {
612 | "id": 44,
613 | "type": "CLIPTextEncode",
614 | "pos": [
615 | 420,
616 | 200
617 | ],
618 | "size": [
619 | 422.84503173828125,
620 | 164.31304931640625
621 | ],
622 | "flags": {},
623 | "order": 13,
624 | "mode": 0,
625 | "inputs": [
626 | {
627 | "name": "clip",
628 | "type": "CLIP",
629 | "link": 205
630 | }
631 | ],
632 | "outputs": [
633 | {
634 | "name": "CONDITIONING",
635 | "type": "CONDITIONING",
636 | "links": [
637 | 175
638 | ],
639 | "slot_index": 0
640 | }
641 | ],
642 | "title": "CLIP Text Encode (Positive Prompt)",
643 | "properties": {
644 | "Node name for S&R": "CLIPTextEncode"
645 | },
646 | "widgets_values": [
647 | "a biblical scene"
648 | ],
649 | "color": "#232",
650 | "bgcolor": "#353"
651 | },
652 | {
653 | "id": 80,
654 | "type": "CLIPTextEncode",
655 | "pos": [
656 | 544.9306030273438,
657 | -578.5970458984375
658 | ],
659 | "size": [
660 | 422.84503173828125,
661 | 164.31304931640625
662 | ],
663 | "flags": {},
664 | "order": 14,
665 | "mode": 0,
666 | "inputs": [
667 | {
668 | "name": "clip",
669 | "type": "CLIP",
670 | "link": 225
671 | }
672 | ],
673 | "outputs": [
674 | {
675 | "name": "CONDITIONING",
676 | "type": "CONDITIONING",
677 | "links": [
678 | 216
679 | ],
680 | "slot_index": 0
681 | }
682 | ],
683 | "title": "CLIP Text Encode (Positive Prompt)",
684 | "properties": {
685 | "Node name for S&R": "CLIPTextEncode"
686 | },
687 | "widgets_values": [
688 | "An hd tracking video following a mystical figure sitting in a holy seashell, he is reaching his large arm and hand out to the left. The background features an angelic scene with the heavens opening up. The camera zooms in on his hand as it inches closer to the center"
689 | ],
690 | "color": "#232",
691 | "bgcolor": "#353"
692 | },
693 | {
694 | "id": 85,
695 | "type": "CLIPTextEncode",
696 | "pos": [
697 | 586.3402099609375,
698 | -1112.4017333984375
699 | ],
700 | "size": [
701 | 422.84503173828125,
702 | 164.31304931640625
703 | ],
704 | "flags": {},
705 | "order": 15,
706 | "mode": 0,
707 | "inputs": [
708 | {
709 | "name": "clip",
710 | "type": "CLIP",
711 | "link": 242
712 | }
713 | ],
714 | "outputs": [
715 | {
716 | "name": "CONDITIONING",
717 | "type": "CONDITIONING",
718 | "links": [
719 | 228
720 | ],
721 | "slot_index": 0
722 | }
723 | ],
724 | "title": "CLIP Text Encode (Positive Prompt)",
725 | "properties": {
726 | "Node name for S&R": "CLIPTextEncode"
727 | },
728 | "widgets_values": [
729 | "An hd tracking shot of a desperate man reaching up and to the right. The background features a hell opening up below trying to pull the man down. The camera zooms in on his hand as it inches closer to the center"
730 | ],
731 | "color": "#232",
732 | "bgcolor": "#353"
733 | },
734 | {
735 | "id": 25,
736 | "type": "RandomNoise",
737 | "pos": [
738 | 479,
739 | 618
740 | ],
741 | "size": [
742 | 315,
743 | 82
744 | ],
745 | "flags": {},
746 | "order": 5,
747 | "mode": 0,
748 | "inputs": [],
749 | "outputs": [
750 | {
751 | "name": "NOISE",
752 | "type": "NOISE",
753 | "links": [
754 | 37
755 | ],
756 | "shape": 3
757 | }
758 | ],
759 | "properties": {
760 | "Node name for S&R": "RandomNoise"
761 | },
762 | "widgets_values": [
763 | 4,
764 | "fixed"
765 | ],
766 | "color": "#2a363b",
767 | "bgcolor": "#3f5159"
768 | },
769 | {
770 | "id": 93,
771 | "type": "CreateShapeMask",
772 | "pos": [
773 | 630,
774 | -2000
775 | ],
776 | "size": [
777 | 315,
778 | 270
779 | ],
780 | "flags": {},
781 | "order": 6,
782 | "mode": 0,
783 | "inputs": [],
784 | "outputs": [
785 | {
786 | "name": "mask",
787 | "type": "MASK",
788 | "links": [
789 | 237
790 | ],
791 | "slot_index": 0
792 | },
793 | {
794 | "name": "mask_inverted",
795 | "type": "MASK",
796 | "links": [
797 | 251
798 | ],
799 | "slot_index": 1
800 | }
801 | ],
802 | "properties": {
803 | "Node name for S&R": "CreateShapeMask"
804 | },
805 | "widgets_values": [
806 | "square",
807 | 1,
808 | 48,
809 | 48,
810 | 0,
811 | 848,
812 | 480,
813 | 4000,
814 | 4000
815 | ]
816 | },
817 | {
818 | "id": 83,
819 | "type": "HYApplyRegionalConds",
820 | "pos": [
821 | 1190,
822 | -480
823 | ],
824 | "size": [
825 | 315,
826 | 210
827 | ],
828 | "flags": {},
829 | "order": 28,
830 | "mode": 0,
831 | "inputs": [
832 | {
833 | "name": "model",
834 | "type": "MODEL",
835 | "link": 223
836 | },
837 | {
838 | "name": "cond",
839 | "type": "CONDITIONING",
840 | "link": 226
841 | },
842 | {
843 | "name": "region_conds",
844 | "type": "REGION_COND",
845 | "link": 260
846 | },
847 | {
848 | "name": "latent",
849 | "type": "LATENT",
850 | "link": 220
851 | },
852 | {
853 | "name": "attn_override",
854 | "type": "ATTN_OVERRIDE",
855 | "link": 274,
856 | "shape": 7
857 | }
858 | ],
859 | "outputs": [
860 | {
861 | "name": "MODEL",
862 | "type": "MODEL",
863 | "links": [
864 | 224
865 | ],
866 | "slot_index": 0
867 | }
868 | ],
869 | "properties": {
870 | "Node name for S&R": "HYApplyRegionalConds"
871 | },
872 | "widgets_values": [
873 | 0,
874 | 0.5,
875 | 0,
876 | false
877 | ]
878 | },
879 | {
880 | "id": 101,
881 | "type": "HYAttnOverride",
882 | "pos": [
883 | 1610.6875,
884 | -444.72222900390625
885 | ],
886 | "size": [
887 | 400,
888 | 200
889 | ],
890 | "flags": {},
891 | "order": 7,
892 | "mode": 4,
893 | "inputs": [],
894 | "outputs": [
895 | {
896 | "name": "ATTN_OVERRIDE",
897 | "type": "ATTN_OVERRIDE",
898 | "links": [
899 | 274
900 | ],
901 | "slot_index": 0
902 | }
903 | ],
904 | "properties": {
905 | "Node name for S&R": "HYAttnOverride"
906 | },
907 | "widgets_values": [
908 | "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30",
909 | "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30"
910 | ]
911 | },
912 | {
913 | "id": 100,
914 | "type": "Note",
915 | "pos": [
916 | 2053.74267578125,
917 | -439.9007568359375
918 | ],
919 | "size": [
920 | 322.08740234375,
921 | 305.0302734375
922 | ],
923 | "flags": {},
924 | "order": 8,
925 | "mode": 0,
926 | "inputs": [],
927 | "outputs": [],
928 | "properties": {},
929 | "widgets_values": [
930 | "---- Attention Override (optional) ----\nYou can adjust the strength of the regions by adding attention overrides.\n\nToo strong and it becomes separate videos, but too weak and it has little change.\n\n\n---- main_cond_strength ----\nThe main prompt is very strong and can completely remove regions. Turn this very low or even to 0.\nAt 0 it is turned off completely.\n\nHowever, at 0 you need to make sure the regional prompts cover all areas of the video or you will get strange grid patterns in regions that are not prompted."
931 | ],
932 | "color": "#432",
933 | "bgcolor": "#653"
934 | },
935 | {
936 | "id": 86,
937 | "type": "CreateShapeMask",
938 | "pos": [
939 | 636.2345581054688,
940 | -1429.23583984375
941 | ],
942 | "size": [
943 | 315,
944 | 270
945 | ],
946 | "flags": {},
947 | "order": 9,
948 | "mode": 0,
949 | "inputs": [],
950 | "outputs": [
951 | {
952 | "name": "mask",
953 | "type": "MASK",
954 | "links": [
955 | 233
956 | ],
957 | "slot_index": 0
958 | },
959 | {
960 | "name": "mask_inverted",
961 | "type": "MASK",
962 | "links": [
963 | 276
964 | ],
965 | "slot_index": 1
966 | }
967 | ],
968 | "properties": {
969 | "Node name for S&R": "CreateShapeMask"
970 | },
971 | "widgets_values": [
972 | "square",
973 | 1,
974 | 848,
975 | 0,
976 | 0,
977 | 848,
978 | 480,
979 | 848,
980 | 4096
981 | ]
982 | },
983 | {
984 | "id": 81,
985 | "type": "CreateShapeMask",
986 | "pos": [
987 | 594.824951171875,
988 | -895.43115234375
989 | ],
990 | "size": [
991 | 315,
992 | 270
993 | ],
994 | "flags": {},
995 | "order": 10,
996 | "mode": 0,
997 | "inputs": [],
998 | "outputs": [
999 | {
1000 | "name": "mask",
1001 | "type": "MASK",
1002 | "links": [
1003 | 232
1004 | ],
1005 | "slot_index": 0
1006 | },
1007 | {
1008 | "name": "mask_inverted",
1009 | "type": "MASK",
1010 | "links": [
1011 | 277
1012 | ],
1013 | "slot_index": 1
1014 | }
1015 | ],
1016 | "properties": {
1017 | "Node name for S&R": "CreateShapeMask"
1018 | },
1019 | "widgets_values": [
1020 | "square",
1021 | 1,
1022 | 0,
1023 | 0,
1024 | 0,
1025 | 848,
1026 | 480,
1027 | 848,
1028 | 1000
1029 | ]
1030 | },
1031 | {
1032 | "id": 91,
1033 | "type": "PreviewImage",
1034 | "pos": [
1035 | 1550.2379150390625,
1036 | -856.0711059570312
1037 | ],
1038 | "size": [
1039 | 210,
1040 | 246
1041 | ],
1042 | "flags": {},
1043 | "order": 26,
1044 | "mode": 0,
1045 | "inputs": [
1046 | {
1047 | "name": "images",
1048 | "type": "IMAGE",
1049 | "link": 234
1050 | }
1051 | ],
1052 | "outputs": [],
1053 | "properties": {
1054 | "Node name for S&R": "PreviewImage"
1055 | },
1056 | "widgets_values": []
1057 | },
1058 | {
1059 | "id": 90,
1060 | "type": "PreviewImage",
1061 | "pos": [
1062 | 1696.442626953125,
1063 | -1371.86572265625
1064 | ],
1065 | "size": [
1066 | 210,
1067 | 246
1068 | ],
1069 | "flags": {},
1070 | "order": 25,
1071 | "mode": 0,
1072 | "inputs": [
1073 | {
1074 | "name": "images",
1075 | "type": "IMAGE",
1076 | "link": 235
1077 | }
1078 | ],
1079 | "outputs": [],
1080 | "properties": {
1081 | "Node name for S&R": "PreviewImage"
1082 | },
1083 | "widgets_values": []
1084 | },
1085 | {
1086 | "id": 87,
1087 | "type": "HYCreateRegionalCond",
1088 | "pos": [
1089 | 1169.326416015625,
1090 | -1032.211181640625
1091 | ],
1092 | "size": [
1093 | 304.79998779296875,
1094 | 122
1095 | ],
1096 | "flags": {},
1097 | "order": 22,
1098 | "mode": 0,
1099 | "inputs": [
1100 | {
1101 | "name": "cond",
1102 | "type": "CONDITIONING",
1103 | "link": 228
1104 | },
1105 | {
1106 | "name": "mask",
1107 | "type": "MASK",
1108 | "link": 276
1109 | },
1110 | {
1111 | "name": "prev_regions",
1112 | "type": "REGION_COND",
1113 | "link": null,
1114 | "shape": 7
1115 | }
1116 | ],
1117 | "outputs": [
1118 | {
1119 | "name": "REGION_COND",
1120 | "type": "REGION_COND",
1121 | "links": [
1122 | 236
1123 | ],
1124 | "slot_index": 0
1125 | }
1126 | ],
1127 | "properties": {
1128 | "Node name for S&R": "HYCreateRegionalCond"
1129 | },
1130 | "widgets_values": [
1131 | 1,
1132 | "first_only"
1133 | ]
1134 | },
1135 | {
1136 | "id": 89,
1137 | "type": "MaskToImage",
1138 | "pos": [
1139 | 1200.27490234375,
1140 | -848.5791625976562
1141 | ],
1142 | "size": [
1143 | 264.5999755859375,
1144 | 26
1145 | ],
1146 | "flags": {},
1147 | "order": 19,
1148 | "mode": 0,
1149 | "inputs": [
1150 | {
1151 | "name": "mask",
1152 | "type": "MASK",
1153 | "link": 232
1154 | }
1155 | ],
1156 | "outputs": [
1157 | {
1158 | "name": "IMAGE",
1159 | "type": "IMAGE",
1160 | "links": [
1161 | 234
1162 | ],
1163 | "slot_index": 0
1164 | }
1165 | ],
1166 | "properties": {
1167 | "Node name for S&R": "MaskToImage"
1168 | },
1169 | "widgets_values": []
1170 | },
1171 | {
1172 | "id": 88,
1173 | "type": "MaskToImage",
1174 | "pos": [
1175 | 1173.0250244140625,
1176 | -1133.0557861328125
1177 | ],
1178 | "size": [
1179 | 264.5999755859375,
1180 | 26
1181 | ],
1182 | "flags": {},
1183 | "order": 18,
1184 | "mode": 0,
1185 | "inputs": [
1186 | {
1187 | "name": "mask",
1188 | "type": "MASK",
1189 | "link": 233
1190 | }
1191 | ],
1192 | "outputs": [
1193 | {
1194 | "name": "IMAGE",
1195 | "type": "IMAGE",
1196 | "links": [
1197 | 235
1198 | ],
1199 | "slot_index": 0
1200 | }
1201 | ],
1202 | "properties": {
1203 | "Node name for S&R": "MaskToImage"
1204 | },
1205 | "widgets_values": []
1206 | },
1207 | {
1208 | "id": 94,
1209 | "type": "HYCreateRegionalCond",
1210 | "pos": [
1211 | 1130.186767578125,
1212 | -1657.6357421875
1213 | ],
1214 | "size": [
1215 | 304.79998779296875,
1216 | 122
1217 | ],
1218 | "flags": {},
1219 | "order": 23,
1220 | "mode": 0,
1221 | "inputs": [
1222 | {
1223 | "name": "cond",
1224 | "type": "CONDITIONING",
1225 | "link": 238
1226 | },
1227 | {
1228 | "name": "mask",
1229 | "type": "MASK",
1230 | "link": 251
1231 | },
1232 | {
1233 | "name": "prev_regions",
1234 | "type": "REGION_COND",
1235 | "link": null,
1236 | "shape": 7
1237 | }
1238 | ],
1239 | "outputs": [
1240 | {
1241 | "name": "REGION_COND",
1242 | "type": "REGION_COND",
1243 | "links": [],
1244 | "slot_index": 0
1245 | }
1246 | ],
1247 | "properties": {
1248 | "Node name for S&R": "HYCreateRegionalCond"
1249 | },
1250 | "widgets_values": [
1251 | 0.4,
1252 | "first_only"
1253 | ]
1254 | },
1255 | {
1256 | "id": 92,
1257 | "type": "MaskToImage",
1258 | "pos": [
1259 | 1159.6939697265625,
1260 | -1745.0765380859375
1261 | ],
1262 | "size": [
1263 | 264.5999755859375,
1264 | 26
1265 | ],
1266 | "flags": {},
1267 | "order": 17,
1268 | "mode": 0,
1269 | "inputs": [
1270 | {
1271 | "name": "mask",
1272 | "type": "MASK",
1273 | "link": 237
1274 | }
1275 | ],
1276 | "outputs": [
1277 | {
1278 | "name": "IMAGE",
1279 | "type": "IMAGE",
1280 | "links": [
1281 | 241
1282 | ],
1283 | "slot_index": 0
1284 | }
1285 | ],
1286 | "properties": {
1287 | "Node name for S&R": "MaskToImage"
1288 | },
1289 | "widgets_values": []
1290 | },
1291 | {
1292 | "id": 96,
1293 | "type": "PreviewImage",
1294 | "pos": [
1295 | 1502.1038818359375,
1296 | -1816.5303955078125
1297 | ],
1298 | "size": [
1299 | 210,
1300 | 246
1301 | ],
1302 | "flags": {},
1303 | "order": 24,
1304 | "mode": 0,
1305 | "inputs": [
1306 | {
1307 | "name": "images",
1308 | "type": "IMAGE",
1309 | "link": 241
1310 | }
1311 | ],
1312 | "outputs": [],
1313 | "properties": {
1314 | "Node name for S&R": "PreviewImage"
1315 | },
1316 | "widgets_values": []
1317 | },
1318 | {
1319 | "id": 78,
1320 | "type": "HYCreateRegionalCond",
1321 | "pos": [
1322 | 1192.2176513671875,
1323 | -760.3463745117188
1324 | ],
1325 | "size": [
1326 | 304.79998779296875,
1327 | 122
1328 | ],
1329 | "flags": {},
1330 | "order": 27,
1331 | "mode": 0,
1332 | "inputs": [
1333 | {
1334 | "name": "cond",
1335 | "type": "CONDITIONING",
1336 | "link": 216
1337 | },
1338 | {
1339 | "name": "mask",
1340 | "type": "MASK",
1341 | "link": 277
1342 | },
1343 | {
1344 | "name": "prev_regions",
1345 | "type": "REGION_COND",
1346 | "link": 236,
1347 | "shape": 7
1348 | }
1349 | ],
1350 | "outputs": [
1351 | {
1352 | "name": "REGION_COND",
1353 | "type": "REGION_COND",
1354 | "links": [
1355 | 260
1356 | ],
1357 | "slot_index": 0
1358 | }
1359 | ],
1360 | "properties": {
1361 | "Node name for S&R": "HYCreateRegionalCond"
1362 | },
1363 | "widgets_values": [
1364 | 1,
1365 | "first_only"
1366 | ]
1367 | }
1368 | ],
1369 | "links": [
1370 | [
1371 | 19,
1372 | 16,
1373 | 0,
1374 | 13,
1375 | 2,
1376 | "SAMPLER"
1377 | ],
1378 | [
1379 | 20,
1380 | 17,
1381 | 0,
1382 | 13,
1383 | 3,
1384 | "SIGMAS"
1385 | ],
1386 | [
1387 | 30,
1388 | 22,
1389 | 0,
1390 | 13,
1391 | 1,
1392 | "GUIDER"
1393 | ],
1394 | [
1395 | 37,
1396 | 25,
1397 | 0,
1398 | 13,
1399 | 0,
1400 | "NOISE"
1401 | ],
1402 | [
1403 | 129,
1404 | 26,
1405 | 0,
1406 | 22,
1407 | 1,
1408 | "CONDITIONING"
1409 | ],
1410 | [
1411 | 175,
1412 | 44,
1413 | 0,
1414 | 26,
1415 | 0,
1416 | "CONDITIONING"
1417 | ],
1418 | [
1419 | 180,
1420 | 45,
1421 | 0,
1422 | 13,
1423 | 4,
1424 | "LATENT"
1425 | ],
1426 | [
1427 | 190,
1428 | 12,
1429 | 0,
1430 | 17,
1431 | 0,
1432 | "MODEL"
1433 | ],
1434 | [
1435 | 205,
1436 | 11,
1437 | 0,
1438 | 44,
1439 | 0,
1440 | "CLIP"
1441 | ],
1442 | [
1443 | 210,
1444 | 13,
1445 | 0,
1446 | 73,
1447 | 0,
1448 | "LATENT"
1449 | ],
1450 | [
1451 | 211,
1452 | 10,
1453 | 0,
1454 | 73,
1455 | 1,
1456 | "VAE"
1457 | ],
1458 | [
1459 | 216,
1460 | 80,
1461 | 0,
1462 | 78,
1463 | 0,
1464 | "CONDITIONING"
1465 | ],
1466 | [
1467 | 220,
1468 | 45,
1469 | 0,
1470 | 83,
1471 | 3,
1472 | "LATENT"
1473 | ],
1474 | [
1475 | 221,
1476 | 12,
1477 | 0,
1478 | 82,
1479 | 0,
1480 | "MODEL"
1481 | ],
1482 | [
1483 | 222,
1484 | 82,
1485 | 0,
1486 | 67,
1487 | 0,
1488 | "MODEL"
1489 | ],
1490 | [
1491 | 223,
1492 | 67,
1493 | 0,
1494 | 83,
1495 | 0,
1496 | "MODEL"
1497 | ],
1498 | [
1499 | 224,
1500 | 83,
1501 | 0,
1502 | 22,
1503 | 0,
1504 | "MODEL"
1505 | ],
1506 | [
1507 | 225,
1508 | 11,
1509 | 0,
1510 | 80,
1511 | 0,
1512 | "CLIP"
1513 | ],
1514 | [
1515 | 226,
1516 | 26,
1517 | 0,
1518 | 83,
1519 | 1,
1520 | "CONDITIONING"
1521 | ],
1522 | [
1523 | 227,
1524 | 73,
1525 | 0,
1526 | 84,
1527 | 0,
1528 | "IMAGE"
1529 | ],
1530 | [
1531 | 228,
1532 | 85,
1533 | 0,
1534 | 87,
1535 | 0,
1536 | "CONDITIONING"
1537 | ],
1538 | [
1539 | 232,
1540 | 81,
1541 | 0,
1542 | 89,
1543 | 0,
1544 | "MASK"
1545 | ],
1546 | [
1547 | 233,
1548 | 86,
1549 | 0,
1550 | 88,
1551 | 0,
1552 | "MASK"
1553 | ],
1554 | [
1555 | 234,
1556 | 89,
1557 | 0,
1558 | 91,
1559 | 0,
1560 | "IMAGE"
1561 | ],
1562 | [
1563 | 235,
1564 | 88,
1565 | 0,
1566 | 90,
1567 | 0,
1568 | "IMAGE"
1569 | ],
1570 | [
1571 | 236,
1572 | 87,
1573 | 0,
1574 | 78,
1575 | 2,
1576 | "REGION_COND"
1577 | ],
1578 | [
1579 | 237,
1580 | 93,
1581 | 0,
1582 | 92,
1583 | 0,
1584 | "MASK"
1585 | ],
1586 | [
1587 | 238,
1588 | 95,
1589 | 0,
1590 | 94,
1591 | 0,
1592 | "CONDITIONING"
1593 | ],
1594 | [
1595 | 241,
1596 | 92,
1597 | 0,
1598 | 96,
1599 | 0,
1600 | "IMAGE"
1601 | ],
1602 | [
1603 | 242,
1604 | 11,
1605 | 0,
1606 | 85,
1607 | 0,
1608 | "CLIP"
1609 | ],
1610 | [
1611 | 243,
1612 | 11,
1613 | 0,
1614 | 95,
1615 | 0,
1616 | "CLIP"
1617 | ],
1618 | [
1619 | 251,
1620 | 93,
1621 | 1,
1622 | 94,
1623 | 1,
1624 | "MASK"
1625 | ],
1626 | [
1627 | 260,
1628 | 78,
1629 | 0,
1630 | 83,
1631 | 2,
1632 | "REGION_COND"
1633 | ],
1634 | [
1635 | 274,
1636 | 101,
1637 | 0,
1638 | 83,
1639 | 4,
1640 | "ATTN_OVERRIDE"
1641 | ],
1642 | [
1643 | 276,
1644 | 86,
1645 | 1,
1646 | 87,
1647 | 1,
1648 | "MASK"
1649 | ],
1650 | [
1651 | 277,
1652 | 81,
1653 | 1,
1654 | 78,
1655 | 1,
1656 | "MASK"
1657 | ]
1658 | ],
1659 | "groups": [],
1660 | "config": {},
1661 | "extra": {
1662 | "ds": {
1663 | "scale": 0.24304420967403448,
1664 | "offset": [
1665 | 1040.0007253377598,
1666 | 1536.193742700761
1667 | ]
1668 | },
1669 | "groupNodes": {}
1670 | },
1671 | "version": 0.4
1672 | }
--------------------------------------------------------------------------------