Skip to content

Commit

Permalink
Support GLIGEN.
Browse files Browse the repository at this point in the history
  • Loading branch information
shiimizu committed Jan 31, 2024
1 parent c435265 commit ec40acf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ This extension enables **large image drawing & upscaling with limited VRAM** via
- [x] Img2img upscale
- [x] Ultra-Large image generation

Some conditioning nodes like SetArea or GLIGEN aren't working at the moment.

## Tiled Diffusion

<div align="center">
Expand All @@ -35,7 +33,7 @@ Some conditioning nodes like SetArea or GLIGEN aren't working at the moment.
| Name | Description |
|-------------------|--------------------------------------------------------------|
| `method` | Tiling strategy. `MultiDiffusion` or `Mixture of Diffusers`. |
| `method` | Tiling [strategy](https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111/blob/fbb24736c9bc374c7f098f82b575fcd14a73936a/scripts/tilediffusion.py#L39-L46). `MultiDiffusion` or `Mixture of Diffusers`. |
| `tile_width` | Tile's width |
| `tile_height` | Tile's height |
| `tile_overlap` | Tile's overlap |
Expand Down
13 changes: 13 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ def find_outer_instance(target:str, target_type):
fn = inject_code(pre_run_control, payload)
return create_hook(fn, 'comfy.samplers')

def hook_gligen__set_position():
from comfy.gligen import Gligen
payload = [{
"target_line": "module = self.module_list[key]",
"code_to_insert": """
nonlocal objs
if x.shape[0] > objs.shape[0]:
objs = objs.repeat(-(x.shape[0] // -objs.shape[0]),1,1)
"""}]
fn = inject_code(Gligen._set_position, payload, 'a')
return create_hook(fn, 'comfy.gligen', 'Gligen._set_position', 'Gligen._set_position')

def create_hook(fn, module_name:str, target = None, orig_key = None):
if target is None: target = fn.__name__
if orig_key is None: orig_key = f'{target}_original'
Expand Down Expand Up @@ -131,6 +143,7 @@ def hook_all(restore=False, hooks=None):
hook_calc_cond_uncond_batch(),
hook_sag_create_blur_map(),
hook_samplers_pre_run_control(),
hook_gligen__set_position(),
]
for m in sys.modules:
for hook in hooks:
Expand Down

0 comments on commit ec40acf

Please sign in to comment.