Skip to content

Commit

Permalink
Update nodes doc
Browse files Browse the repository at this point in the history
  • Loading branch information
CI/CD Bot committed Mar 7, 2024
1 parent d3e9b7b commit 0fa3b4e
Show file tree
Hide file tree
Showing 13 changed files with 1,062 additions and 24 deletions.
77 changes: 77 additions & 0 deletions docs/md/ComfyUI_experiments/ModelMergeBlockNumber.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# ModelMergeBlockNumber
## Documentation
- Class name: `ModelMergeBlockNumber`
- Category: `advanced/model_merging`
- Output node: `False`

This node specializes in merging two models by applying a weighted combination of their components. It allows for fine-grained control over the merging process by specifying weights for different parts of the models, such as time embeddings, label embeddings, input blocks, middle blocks, output blocks, and the output layer. This enables the creation of hybrid models that blend features from both input models according to specified ratios.
## Input types
- **`model1`**
- The first model to be merged. It serves as the base model for the merging process.
- Python dtype: `comfy.model_management.Model`
- Comfy dtype: `MODEL`
- **`model2`**
- The second model to be merged. Its components are selectively blended into the first model based on the specified weights.
- Python dtype: `comfy.model_management.Model`
- Comfy dtype: `MODEL`
- **`time_embed.`**
- Specifies the weight for merging the time embedding components of the two models. Allows for precise control over how time-related features are combined.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`label_emb.`**
- Determines the weight for merging the label embedding components. This parameter enables customization of how label-related features are integrated.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`input_blocks.i`**
- Controls the weight for merging the i-th input block, where i ranges from 0 to 11. This allows for detailed customization of the initial stages of the model.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`middle_block.i`**
- Sets the weight for merging the i-th middle block, where i ranges from 0 to 2. This parameter influences the blending of the models' intermediate processing stages.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`output_blocks.i`**
- Specifies the weight for merging the i-th output block, where i ranges from 0 to 11. It affects how the final stages of the models are combined.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`out.`**
- Determines the weight for merging the output layer components. This parameter finalizes the blending of the models' output features.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
## Output types
- **`model`**
- The resulting model after merging the specified components of the two input models.
- Python dtype: `comfy.model_management.Model`
- Comfy dtype: `MODEL`
## Usage tips
- Infra type: `CPU`
- Common nodes: unknown

The ModelMergeBlockNumber node is primarily utilized for creating hybrid AI models by merging two distinct models, allowing for the customization of the merging process through weighted parameters for different model components, including time and label embeddings, input, middle, and output blocks, and the output layer. This node takes two models as input and outputs a single model that combines features from both according to specified weights, making it ideal for experiments in model blending and performance enhancement.
## Source code
```python
class ModelMergeBlockNumber(comfy_extras.nodes_model_merging.ModelMergeBlocks):
@classmethod
def INPUT_TYPES(s):
arg_dict = { "model1": ("MODEL",),
"model2": ("MODEL",)}

argument = ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01})

arg_dict["time_embed."] = argument
arg_dict["label_emb."] = argument

for i in range(12):
arg_dict["input_blocks.{}.".format(i)] = argument

for i in range(3):
arg_dict["middle_block.{}.".format(i)] = argument

for i in range(12):
arg_dict["output_blocks.{}.".format(i)] = argument

arg_dict["out."] = argument

return {"required": arg_dict}

```
77 changes: 77 additions & 0 deletions docs/md/ComfyUI_experiments/ModelMergeSDXL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# ModelMergeSDXL
## Documentation
- Class name: `ModelMergeSDXL`
- Category: `advanced/model_merging`
- Output node: `False`

This node merges two models by blending their components based on specified ratios for different parts of the models. It allows for fine-tuned control over how much of each model's characteristics are retained in the merged model, by adjusting ratios for time embeddings, label embeddings, input blocks, middle blocks, output blocks, and the output layer.
## Input types
- **`model1`**
- The first model to be merged. It serves as the base model for the merging process.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
- **`model2`**
- The second model to be merged. Its components are blended with the first model based on the specified ratios.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
- **`time_embed.`**
- Specifies the blending ratio for the time embedding components of the models.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`label_emb.`**
- Specifies the blending ratio for the label embedding components of the models.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`input_blocks.i`**
- Specifies the blending ratio for the i-th input block of the models, where i ranges from 0 to 8.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`middle_block.i`**
- Specifies the blending ratio for the i-th middle block of the models, where i ranges from 0 to 2.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`output_blocks.i`**
- Specifies the blending ratio for the i-th output block of the models, where i ranges from 0 to 8.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`out.`**
- Specifies the blending ratio for the output layer of the models.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
## Output types
- **`model`**
- The resulting model after merging the two input models based on the specified blending ratios.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
## Usage tips
- Infra type: `GPU`
- Common nodes: unknown

The ModelMergeSDXL node is primarily utilized for blending two AI models by adjusting the ratios for specific components like time embeddings, label embeddings, input, middle, and output blocks, and the output layer, making it ideal for creating hybrid models that combine the strengths of both input models. It requires two models as input and outputs a single model that embodies the merged characteristics based on the specified blending ratios.
## Source code
```python
class ModelMergeSDXL(comfy_extras.nodes_model_merging.ModelMergeBlocks):
@classmethod
def INPUT_TYPES(s):
arg_dict = { "model1": ("MODEL",),
"model2": ("MODEL",)}

argument = ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01})

arg_dict["time_embed."] = argument
arg_dict["label_emb."] = argument

for i in range(9):
arg_dict["input_blocks.{}".format(i)] = argument

for i in range(3):
arg_dict["middle_block.{}".format(i)] = argument

for i in range(9):
arg_dict["output_blocks.{}".format(i)] = argument

arg_dict["out."] = argument

return {"required": arg_dict}

```
96 changes: 96 additions & 0 deletions docs/md/ComfyUI_experiments/ModelMergeSDXLDetailedTransformers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ModelMergeSDXLDetailedTransformers
## Documentation
- Class name: `ModelMergeSDXLDetailedTransformers`
- Category: `advanced/model_merging`
- Output node: `False`

This node specializes in merging models with a detailed focus on transformer blocks. It inherits from a base model merging class and is designed to handle complex merging scenarios involving transformer components within models. The node likely incorporates advanced techniques to merge specific parts of models, such as transformer blocks, with precision, allowing for fine-tuned control over the merging process.
## Input types
- **`model1`**
- The first model to be merged. It is a crucial component of the merging process, serving as one of the primary sources of features or parameters to be combined.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
- **`model2`**
- The second model to be merged. It plays a significant role in the merging process, contributing its features or parameters to be combined with those of the first model.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
- **`time_embed.`**
- A floating-point parameter influencing the merging process, likely related to the timing embedding aspects of the models.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`label_emb.`**
- A floating-point parameter affecting the merging process, possibly related to the label embedding aspects of the models.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`input_blocks.i`**
- A series of floating-point parameters for each input block, allowing for fine-tuned control over how these blocks are merged. The index 'i' ranges from 0 to 8, with additional parameters for transformer blocks within certain input blocks.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`middle_block.i`**
- A series of floating-point parameters for each middle block, enabling precise adjustments in the merging of these blocks. The index 'i' ranges from 0 to 2, with additional parameters for transformer blocks within the middle block at index 1.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`output_blocks.i`**
- A series of floating-point parameters for each output block, facilitating detailed control over the merging of these blocks. The index 'i' ranges from 0 to 8, with additional parameters for transformer blocks within certain output blocks, based on a reverse index mapping.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`out.`**
- A floating-point parameter that likely influences the final output aspects of the merging process.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
## Output types
- **`model`**
- The result of the merging process, a single model that combines elements from both input models, with particular attention to transformer blocks.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
## Usage tips
- Infra type: `GPU`
- Common nodes: unknown

The ModelMergeSDXLDetailedTransformers node is designed for advanced scenarios where two AI models, particularly those with transformer blocks, need to be merged with high precision. It takes two models as input, along with various parameters to fine-tune the merging of transformer components, and outputs a single, integrated model that combines elements from both input models, focusing on transformer blocks. This node is often used in pipelines requiring the nuanced integration of transformer-based models for tasks like language processing or generative tasks.
## Source code
```python
class ModelMergeSDXLDetailedTransformers(comfy_extras.nodes_model_merging.ModelMergeBlocks):
@classmethod
def INPUT_TYPES(s):
arg_dict = { "model1": ("MODEL",),
"model2": ("MODEL",)}

argument = ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01})

arg_dict["time_embed."] = argument
arg_dict["label_emb."] = argument

transformers = {4: 2, 5:2, 7:10, 8:10}
transformers_args = ["norm1", "attn1.to_q", "attn1.to_k", "attn1.to_v", "attn1.to_out", "ff.net", "norm2", "attn2.to_q", "attn2.to_k", "attn2.to_v", "attn2.to_out", "norm3"]

for i in range(9):
arg_dict["input_blocks.{}.0.".format(i)] = argument
if i in transformers:
arg_dict["input_blocks.{}.1.".format(i)] = argument
for j in range(transformers[i]):
for x in transformers_args:
arg_dict["input_blocks.{}.1.transformer_blocks.{}.{}".format(i, j, x)] = argument

for i in range(3):
arg_dict["middle_block.{}.".format(i)] = argument
if i == 1:
for j in range(10):
for x in transformers_args:
arg_dict["middle_block.{}.transformer_blocks.{}.{}".format(i, j, x)] = argument

transformers = {3:2, 4: 2, 5:2, 6:10, 7:10, 8:10}
for i in range(9):
arg_dict["output_blocks.{}.0.".format(i)] = argument
t = 8 - i
if t in transformers:
arg_dict["output_blocks.{}.1.".format(i)] = argument
for j in range(transformers[t]):
for x in transformers_args:
arg_dict["output_blocks.{}.1.transformer_blocks.{}.{}".format(i, j, x)] = argument

arg_dict["out."] = argument

return {"required": arg_dict}

```
112 changes: 112 additions & 0 deletions docs/md/ComfyUI_experiments/ModelMergeSDXLTransformers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# ModelMergeSDXLTransformers
## Documentation
- Class name: `ModelMergeSDXLTransformers`
- Category: `advanced/model_merging`
- Output node: `False`

This node is designed for merging two models by blending their components, specifically tailored for models with transformer blocks. It extends the functionality of a base model merging class to handle the intricacies of transformer-based models, allowing for detailed control over how different parts of the models are combined. This includes the ability to adjust the blending ratios of various components such as input, middle, and output blocks, as well as specific transformer elements within those blocks.
## Input types
- **`model1`**
- The first model to be merged. It serves as the base model onto which elements from the second model are blended.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
- **`model2`**
- The second model whose elements are to be blended into the first model. This allows for the creation of a new model that inherits characteristics from both input models.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
- **`time_embed.`**
- Adjusts the blending ratio specifically for the time embedding components of the models.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`label_emb.`**
- Sets the blending ratio for the label embedding components, allowing for customization of how label information is integrated between the two models.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`input_blocks.i.0.`**
- Specifies the blending ratio for the initial part of the input blocks. The 'i' ranges from 0 to 8, enabling customization at the beginning of each input block.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`input_blocks.i.1.`**
- Determines the blending ratio for the second part of the input blocks, applicable only to blocks with transformers. This allows for detailed control over the transformer sections within the input blocks.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`input_blocks.i.1.transformer_blocks.j.x`**
- Controls the blending ratio for specific transformer block components within the input blocks, offering granular control over the merging of transformer elements. 'i' ranges from 0 to 8, 'j' corresponds to the transformer block index, and 'x' represents the specific transformer component.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`middle_block.i.`**
- Sets the blending ratio for the middle blocks of the models, enabling precise adjustment of the core parts. 'i' ranges from 0 to 2, providing control over each middle block.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`middle_block.1.transformer_blocks.j.x`**
- Adjusts the blending ratio for specific transformer block components within the middle block, allowing for detailed customization of the transformer elements in the core part of the model. 'j' corresponds to the transformer block index, and 'x' represents the specific transformer component.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`output_blocks.i.0.`**
- Specifies the blending ratio for the initial part of the output blocks, enabling customization at the beginning of each output block. 'i' ranges from 0 to 8.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`output_blocks.i.1.`**
- Determines the blending ratio for the second part of the output blocks, applicable only to blocks with transformers. This allows for detailed control over the transformer sections within the output blocks.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`output_blocks.i.1.transformer_blocks.j.x`**
- Controls the blending ratio for specific transformer block components within the output blocks, offering granular control over the merging of transformer elements. 'i' ranges from 0 to 8, 'j' corresponds to the transformer block index, and 'x' represents the specific transformer component.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
- **`out.`**
- Sets the overall blending ratio for the models' output. This parameter provides a global control over the final output characteristics of the merged model.
- Python dtype: `float`
- Comfy dtype: `FLOAT`
## Output types
- **`model`**
- The resulting model after merging the input models according to the specified blending ratios. This model combines elements from both input models, creating a new model with characteristics of both.
- Python dtype: `torch.nn.Module`
- Comfy dtype: `MODEL`
## Usage tips
- Infra type: `CPU`
- Common nodes: unknown

Often used for blending transformer-based models `MODEL1` and `MODEL2` to create a new model that inherits characteristics from both, allowing for detailed customization of blending ratios across various components including input, middle, and output blocks, as well as specific transformer elements within those blocks.
## Source code
```python
class ModelMergeSDXLTransformers(comfy_extras.nodes_model_merging.ModelMergeBlocks):
@classmethod
def INPUT_TYPES(s):
arg_dict = { "model1": ("MODEL",),
"model2": ("MODEL",)}

argument = ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01})

arg_dict["time_embed."] = argument
arg_dict["label_emb."] = argument

transformers = {4: 2, 5:2, 7:10, 8:10}

for i in range(9):
arg_dict["input_blocks.{}.0.".format(i)] = argument
if i in transformers:
arg_dict["input_blocks.{}.1.".format(i)] = argument
for j in range(transformers[i]):
arg_dict["input_blocks.{}.1.transformer_blocks.{}.".format(i, j)] = argument

for i in range(3):
arg_dict["middle_block.{}.".format(i)] = argument
if i == 1:
for j in range(10):
arg_dict["middle_block.{}.transformer_blocks.{}.".format(i, j)] = argument

transformers = {3:2, 4: 2, 5:2, 6:10, 7:10, 8:10}
for i in range(9):
arg_dict["output_blocks.{}.0.".format(i)] = argument
t = 8 - i
if t in transformers:
arg_dict["output_blocks.{}.1.".format(i)] = argument
for j in range(transformers[t]):
arg_dict["output_blocks.{}.1.transformer_blocks.{}.".format(i, j)] = argument

arg_dict["out."] = argument

return {"required": arg_dict}

```
Loading

0 comments on commit 0fa3b4e

Please sign in to comment.