Skip to content

Commit

Permalink
Merge pull request #1 from pauloday/tiling-to-padding
Browse files Browse the repository at this point in the history
Tiling to padding and upstream merge
  • Loading branch information
pauloday authored Sep 18, 2022
2 parents 1f23bf9 + 4149051 commit aa0acbb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions javascript/imageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function modalKeyHandler(event){
case "ArrowRight":
modalNextImage(event)
break;
case "Escape":
closeModal();
break;
}
}

Expand Down
9 changes: 7 additions & 2 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def js(self):
"prompt": self.prompt if type(self.prompt) != list else self.prompt[0],
"negative_prompt": self.negative_prompt if type(self.negative_prompt) != list else self.negative_prompt[0],
"seed": int(self.seed if type(self.seed) != list else self.seed[0]),
"subseed": int(self.subseed if type(self.subseed) != list else self.subseed[0]),
"subseed": int(self.subseed if type(self.subseed) != list else self.subseed[0]) if self.subseed is not None else -1,
"subseed_strength": self.subseed_strength,
"width": self.width,
"height": self.height,
Expand All @@ -117,7 +117,12 @@ def js(self):
def slerp(val, low, high):
low_norm = low/torch.norm(low, dim=1, keepdim=True)
high_norm = high/torch.norm(high, dim=1, keepdim=True)
omega = torch.acos((low_norm*high_norm).sum(1))
dot = (low_norm*high_norm).sum(1)

if dot.mean() > 0.9995:
return low * val + high * (1 - val)

omega = torch.acos(dot)
so = torch.sin(omega)
res = (torch.sin((1.0-val)*omega)/so).unsqueeze(1)*low + (torch.sin(val*omega)/so).unsqueeze(1) * high
return res
Expand Down
6 changes: 3 additions & 3 deletions modules/sd_hijack.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ def hijack(self, m):
model_embeddings.token_embedding = EmbeddingsWithFixes(model_embeddings.token_embedding, self)
m.cond_stage_model = FrozenCLIPEmbedderWithCustomWords(m.cond_stage_model, self)

if cmd_opts.opt_split_attention:
if cmd_opts.opt_split_attention_v1:
ldm.modules.attention.CrossAttention.forward = split_cross_attention_forward_v1
elif not cmd_opts.disable_opt_split_attention:
ldm.modules.attention.CrossAttention.forward = split_cross_attention_forward
ldm.modules.diffusionmodules.model.nonlinearity = nonlinearity_hijack
ldm.modules.diffusionmodules.model.AttnBlock.forward = cross_attention_attnblock_forward
elif cmd_opts.opt_split_attention_v1:
ldm.modules.attention.CrossAttention.forward = split_cross_attention_forward_v1

def flatten(el):
flattened = [flatten(children) for children in el.children()]
Expand Down
9 changes: 6 additions & 3 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
parser.add_argument("--precision", type=str, help="evaluate at this precision", choices=["full", "autocast"], default="autocast")
parser.add_argument("--share", action='store_true', help="use share=True for gradio and make the UI accessible through their site (doesn't work for me but you might have better luck)")
parser.add_argument("--esrgan-models-path", type=str, help="path to directory with ESRGAN models", default=os.path.join(script_path, 'ESRGAN'))
parser.add_argument("--opt-split-attention", action='store_true', help="enable optimization that reduce vram usage by a lot for about 10%% decrease in performance")
parser.add_argument("--opt-split-attention-v1", action='store_true', help="enable older version of --opt-split-attention optimization")
parser.add_argument("--opt-split-attention", action='store_true', help="does not do anything")
parser.add_argument("--disable-opt-split-attention", action='store_true', help="disable an optimization that reduces vram usage by a lot")
parser.add_argument("--opt-split-attention-v1", action='store_true', help="enable older version of split attention optimization that does not consaumes all the VRAM it can find")
parser.add_argument("--listen", action='store_true', help="launch gradio with 0.0.0.0 as server name, allowing to respond to network requests")
parser.add_argument("--port", type=int, help="launch gradio with given server port, you need root/admin rights for ports < 1024, defaults to 7860 if available", default=None)
parser.add_argument("--show-negative-prompt", action='store_true', help="does not do anything", default=False)
Expand All @@ -48,9 +49,11 @@
parser.add_argument("--gradio-auth", type=str, help='set gradio authentication like "username:password"; or comma-delimit multiple like "u1:p1,u2:p2,u3:p3"', default=None)
parser.add_argument("--opt-channelslast", action='store_true', help="change memory type for stable diffusion to channels last")
parser.add_argument("--styles-file", type=str, help="filename to use for styles", default=os.path.join(script_path, 'styles.csv'))

cmd_opts = parser.parse_args()

if cmd_opts.opt_split_attention:
print("Information: --opt-split-attention is now the default. To remove this message, remove --opt-split-attention from command line arguments. To disable the optimization, use --disable-opt-split-attention")

device = get_optimal_device()

batch_cond_uncond = cmd_opts.always_batch_cond_uncond or not (cmd_opts.lowvram or cmd_opts.medvram)
Expand Down

0 comments on commit aa0acbb

Please sign in to comment.