diff --git a/__init__.py b/__init__.py index 6c4f068..271276e 100644 --- a/__init__.py +++ b/__init__.py @@ -12,9 +12,10 @@ from .nodes.d2_nodes import NODE_CLASS_MAPPINGS as D2_CLASS_MAPPIGS from .nodes.d2_size_nodes import NODE_CLASS_MAPPINGS as D2_SIZE_CLASS_MAPPIGS from .nodes.d2_xy_nodes import NODE_CLASS_MAPPINGS as D2_XY_CLASS_MAPPIGS from .nodes.d2_refiner_nodes import NODE_CLASS_MAPPINGS as D2_REFINER_CLASS_MAPPIGS +from .nodes.d2_merge_nodes import NODE_CLASS_MAPPINGS as D2_MERGE_CLASS_MAPPIGS WEB_DIRECTORY = "./web" -NODE_CLASS_MAPPINGS = {**D2_CLASS_MAPPIGS, **D2_SIZE_CLASS_MAPPIGS, **D2_XY_CLASS_MAPPIGS, **D2_REFINER_CLASS_MAPPIGS} +NODE_CLASS_MAPPINGS = {**D2_CLASS_MAPPIGS, **D2_SIZE_CLASS_MAPPIGS, **D2_XY_CLASS_MAPPIGS, **D2_REFINER_CLASS_MAPPIGS, **D2_MERGE_CLASS_MAPPIGS} NODE_DISPLAY_NAME_MAPPINGS = [] __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"] diff --git a/docs/en/index.md b/docs/en/index.md index 38d44d7..7bb801a 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -130,6 +130,11 @@ If you have installed any of the following custom nodes previously, please remov - `D2 Refiner Steps Tester` - Node for checking steps +### Merge Node + +- `D2 Model and CLIP Merge SDXL` + - A node that combines ModelMergeSDXL and CLIPMergeSimple + ### Float Palet - `D2 Queue Button` @@ -142,6 +147,10 @@ If you have installed any of the following custom nodes previously, please remov ## :blossom: Changelog +**2025.02.23** + +- `D2 Model and CLIP Merge SDXL`: Added checkpoint merge nodes + **2025.01.20** - `D2 XY Seed2`: Added new node diff --git a/docs/en/node.md b/docs/en/node.md index 249973d..a6385b2 100644 --- a/docs/en/node.md +++ b/docs/en/node.md @@ -842,6 +842,25 @@ Output text - Node for checking steps + +--- + + +## :tomato: Merge Node + + +### D2 Model and CLIP Merge SDXL + +
+ +
+ +- A node that combines ModelMergeSDXL and CLIPMergeSimple +- Allows comma-separated weight specifications for easier use with XYPlot +- In this figure, `0.85,0.85,1,1,0.4,0.4,1,0.4,0.4,0.4,1,0.4,0.4,0.4,0,0.55,0.85,0.85,0.85,0.85,0.85,0.85,1,1,0.65` is specified + + + --- ## :tomato: Float Palet diff --git a/docs/img/merge_sdxl.png b/docs/img/merge_sdxl.png new file mode 100644 index 0000000..1667759 Binary files /dev/null and b/docs/img/merge_sdxl.png differ diff --git a/docs/ja/index.md b/docs/ja/index.md index 297316e..5b2bf67 100644 --- a/docs/ja/index.md +++ b/docs/ja/index.md @@ -133,6 +133,12 @@ D2 Nodes ComfyUI - `D2 Refiner Steps Tester` - steps を確認するためのノード +### Merge Node + +- `D2 Model and CLIP Merge SDXL` + - ModelMergeSDXL と CLIPMergeSimple を合体させたノード + + ### Float Palet - `D2 Queue Button` @@ -145,6 +151,10 @@ D2 Nodes ComfyUI ## :blossom: Changelog +**2025.02.23** + +- `D2 Model and CLIP Merge SDXL`: checkpointのマージノードを追加 + **2025.01.20** - `D2 XY Seed2`: 新規追加 diff --git a/docs/ja/node.md b/docs/ja/node.md index eecc5c3..b2e1fbe 100644 --- a/docs/ja/node.md +++ b/docs/ja/node.md @@ -935,6 +935,23 @@ Output text --- +## :tomato: Merge Node + + +### D2 Model and CLIP Merge SDXL + +
+ +
+ +- ModelMergeSDXL と CLIPMergeSimple を合体させたノード +- XYPlot で使いやすいように、各 weight をカンマ区切りで指定可能にした +- この図では `0.85,0.85,1,1,0.4,0.4,1,0.4,0.4,0.4,1,0.4,0.4,0.4,0,0.55,0.85,0.85,0.85,0.85,0.85,0.85,1,1,0.65` を指定している + + +--- + + ## :tomato: Float Palet diff --git a/docs/zh/index.md b/docs/zh/index.md index faa886e..03594c7 100644 --- a/docs/zh/index.md +++ b/docs/zh/index.md @@ -131,6 +131,13 @@ - `D2 Refiner Steps Tester` - 用於確認步數的節點 +### Merge Node + +- `D2 Model and CLIP Merge SDXL` + - 將 ModelMergeSDXL 和 CLIPMergeSimple 結合的節點 + + + ### 浮動面板 - `D2 Queue Button` @@ -141,6 +148,10 @@ ## :blossom: 更新日誌 +**2025.02.23** + +- `D2 Model and CLIP Merge SDXL`: 新增 checkpoint 合併節點 + **2025.01.20** - `D2 XY Seed2`: 新增節點 diff --git a/docs/zh/node.md b/docs/zh/node.md index c5eecf4..2192eb9 100644 --- a/docs/zh/node.md +++ b/docs/zh/node.md @@ -876,6 +876,24 @@ Output text - 用於確認步數的節點 +--- + +## :tomato: Merge Node + + +### D2 Model and CLIP Merge SDXL + +
+ +
+ +- 將 ModelMergeSDXL 和 CLIPMergeSimple 結合的節點 +- 為了便於在 XYPlot 中使用,可以用逗號分隔指定各個權重 +- 在此圖中指定了 `0.85,0.85,1,1,0.4,0.4,1,0.4,0.4,0.4,1,0.4,0.4,0.4,0,0.55,0.85,0.85,0.85,0.85,0.85,0.85,1,1,0.65` + + + + --- ## :tomato: Float Palet diff --git a/nodes/d2_merge_nodes.py b/nodes/d2_merge_nodes.py new file mode 100644 index 0000000..6d00f73 --- /dev/null +++ b/nodes/d2_merge_nodes.py @@ -0,0 +1,70 @@ +from typing import Optional +from comfy_extras.nodes_model_merging import ModelMergeBlocks, CLIPMergeSimple + +class D2_ModelAndCLIPMergeSDXL(): + CATEGORY = "advanced/model_merging/model_specific" + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "model1": ("MODEL",), + "model2": ("MODEL",), + "clip1": ("CLIP",), + "clip2": ("CLIP",), + "weights": ("STRING",), + } + } + + RETURN_TYPES = ("MODEL", "CLIP",) + FUNCTION = "merge" + CATEGORY = "D2/Merge" + + def merge(self, model1, model2, clip1, clip2, weights): + # Parse weights string into dictionary + weight_parts = [w.strip() for w in weights.split(",")] + weights_dict = {} + + # SDXL model structure components + components = [ + "time_embed.", + "label_emb.", + "input_blocks.0", "input_blocks.1", "input_blocks.2", "input_blocks.3", + "input_blocks.4", "input_blocks.5", "input_blocks.6", "input_blocks.7", "input_blocks.8", + "middle_block.0", "middle_block.1", "middle_block.2", + "output_blocks.0", "output_blocks.1", "output_blocks.2", "output_blocks.3", + "output_blocks.4", "output_blocks.5", "output_blocks.6", "output_blocks.7", "output_blocks.8", + "out" + ] + + # Map weights to components + for i, weight in enumerate(weight_parts): + if i < len(components): + try: + weight_float = float(weight) + weights_dict[components[i]] = weight_float + except ValueError: + weights_dict[components[i]] = 0.5 # Default to 0.5 if invalid weight + + # Fill remaining components with default weight + for comp in components: + if comp not in weights_dict: + weights_dict[comp] = 0.5 + + # Calculate CLIP merge ratio (last weight if provided, otherwise 0.5) + clip_ratio = float(weight_parts[-1]) if len(weight_parts) > len(components) else 0.5 + + # Merge models using ModelMergeBlocks + model_merger = ModelMergeBlocks() + merged_model = model_merger.merge(model1, model2, **weights_dict)[0] + + # Merge CLIP models + clip_merger = CLIPMergeSimple() + merged_clip = clip_merger.merge(clip1, clip2, clip_ratio)[0] + + return (merged_model, merged_clip,) + + +NODE_CLASS_MAPPINGS = { + "D2 Model and CLIP Merge SDXL": D2_ModelAndCLIPMergeSDXL, +} diff --git a/pyproject.toml b/pyproject.toml index e1f1415..e7ed719 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "d2-nodes-comfyui" description = "This is a collection of custom nodes that make ComfyUI slightly more convenient." -version = "10.0.0" +version = "11.0.0" license = { file = "LICENSE" } [project.urls]