From be7e884bae7400da8dcf4870a0942b69328cf88f Mon Sep 17 00:00:00 2001 From: nullquant Date: Fri, 31 May 2024 15:35:04 +0300 Subject: [PATCH] powerpaint save_memory option --- README.md | 1 + brushnet_nodes.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 42227d5..f5087d3 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,7 @@ You should try to add object description to negative prompt and describe empty s - `CLIP`: PowerPaint CLIP that should be passed from PowerPaintCLIPLoader node. - `fitting`: PowerPaint fitting degree. - `function`: PowerPaint function, see its [page](https://github.com/open-mmlab/PowerPaint) for details. +- `save_memory`: If this option is set to `max`, the attention module splits the input tensor in slices to compute attention in several steps. This is useful for saving some memory in exchange for a decrease in speed. When using certain network functions, the authors of PowerPaint recommend adding phrases to the prompt: diff --git a/brushnet_nodes.py b/brushnet_nodes.py index c6769b4..b2c190e 100644 --- a/brushnet_nodes.py +++ b/brushnet_nodes.py @@ -189,7 +189,7 @@ class PowerPaint: "scale": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0}), "start_at": ("INT", {"default": 0, "min": 0, "max": 10000}), "end_at": ("INT", {"default": 10000, "min": 0, "max": 10000}), - "debug": (['False', 'True'], ), + "save_memory": (['auto', 'max'], ), }, } @@ -199,7 +199,7 @@ class PowerPaint: FUNCTION = "model_update" - def model_update(self, model, vae, image, mask, powerpaint, clip, positive, negative, fitting, function, scale, start_at, end_at, debug): + def model_update(self, model, vae, image, mask, powerpaint, clip, positive, negative, fitting, function, scale, start_at, end_at, save_memory): is_SDXL, is_PP = check_compatibilty(model, powerpaint) if not is_PP: @@ -292,6 +292,8 @@ class PowerPaint: control_guidance_start = start_at control_guidance_end = end_at + powerpaint['brushnet'].set_attention_slice(save_memory) + add_brushnet_patch(model, powerpaint['brushnet'], torch_dtype, @@ -299,7 +301,7 @@ class PowerPaint: (brushnet_conditioning_scale, control_guidance_start, control_guidance_end), negative_prompt_embeds_pp, prompt_embeds_pp, None, None, None, - 'True' in debug) + False) latent = torch.zeros([batch, 4, conditioning_latents[0].shape[2], conditioning_latents[0].shape[3]], device=powerpaint['brushnet'].device) @@ -912,7 +914,7 @@ def brushnet_inference(x, timesteps, transformer_options, debug): ).to(torch_dtype).to(brushnet.device) if step == 0: - print('BrushNet inference: sample', x.shape, ', CL', conditioning_latents.shape) + print('BrushNet inference: sample', x.shape, ', CL', conditioning_latents.shape, 'dtype', torch_dtype) if debug: print('BrushNet: step =', step)