Skip to content

Commit

Permalink
Fix channel padding with new Comfy core API (#43)
Browse files Browse the repository at this point in the history
* Fix channel padding with new Comfy core API

* nit
  • Loading branch information
huchenlei authored Aug 27, 2024
1 parent 44046a1 commit cdc61bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ There are 2 models:

After you download these models, please put them under `ComfyUI/models/unet` and load them with `UNETLoader` node.

### [Important!] Required nodes
You MUST install following nodes first for IC light to work properly.
- [ComfyUI-layerdiffuse](https://github.com/huchenlei/ComfyUI-layerdiffuse): Although not used in the workflow, the patching of weight load in layerdiffuse is a dependency for IC-Light nodes to work properly.

### Recommended nodes

- [ComfyUI-KJNodes](https://github.com/kijai/ComfyUI-KJNodes): Provides various mask nodes to create light map.
- [ComfyUI-Easy-Use](https://github.com/yolain/ComfyUI-Easy-Use): A giant node pack of everything. The remove bg node used in workflow comes from this pack.
- [ComfyUI_essentials](https://github.com/cubiq/ComfyUI_essentials): Many useful tooling nodes. Image resize node used in the workflow comes from this pack.
Expand Down Expand Up @@ -61,12 +58,7 @@ Light from left

## Common Issues
IC-Light's unet is accepting extra inputs on top of the common noise input. FG model accepts extra 1 input (4 channels). BG model accepts 2 extra input (8 channels).
The original unet's input is 4 channels as well.

If you see following issue, it means IC-Light's unet is not properly loaded, and you need to install [ComfyUI-layerdiffuse](https://github.com/huchenlei/ComfyUI-layerdiffuse) first.
```
RuntimeError: Given groups=1, weight of size [320, 4, 3, 3], expected input[2, 8, 64, 64] to have 4 channels, but got 8 channels instead
```
The original unet's input is 4 channels as well.

If you see following error, it means you are using FG workflow but loaded the BG model.
```
Expand Down
9 changes: 8 additions & 1 deletion ic_light_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ def wrapper_func(unet_apply: Callable, params: UnetParams):
ic_model_state_dict = ic_model.model.diffusion_model.state_dict()
work_model.add_patches(
patches={
("diffusion_model." + key): (value.to(dtype=dtype, device=device),)
("diffusion_model." + key): (
"diff",
[
value.to(dtype=dtype, device=device),
# The extra flag to pad the weight if the diff's shape is larger than the weight
{"pad_weight": key == "input_blocks.0.0.weight"},
],
)
for key, value in ic_model_state_dict.items()
}
)
Expand Down

0 comments on commit cdc61bc

Please sign in to comment.