Skip to content

Commit bef51ae

Browse files
committed
Merge branch 'release_candidate'
2 parents cf2772f + 1398485 commit bef51ae

File tree

152 files changed

+5883
-5612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+5883
-5612
lines changed

.eslintrc.js

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ module.exports = {
8686
// imageviewer.js
8787
modalPrevImage: "readonly",
8888
modalNextImage: "readonly",
89-
// token-counters.js
90-
setupTokenCounters: "readonly",
9189
// localStorage.js
9290
localSet: "readonly",
9391
localGet: "readonly",

.github/workflows/run_tests.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
cache-dependency-path: |
2121
**/requirements*txt
2222
launch.py
23+
- name: Cache models
24+
id: cache-models
25+
uses: actions/cache@v3
26+
with:
27+
path: models
28+
key: "2023-12-30"
2329
- name: Install test dependencies
2430
run: pip install wait-for-it -r requirements-test.txt
2531
env:
@@ -33,6 +39,8 @@ jobs:
3339
TORCH_INDEX_URL: https://download.pytorch.org/whl/cpu
3440
WEBUI_LAUNCH_LIVE_OUTPUT: "1"
3541
PYTHONUNBUFFERED: "1"
42+
- name: Print installed packages
43+
run: pip freeze
3644
- name: Start test server
3745
run: >
3846
python -m coverage run
@@ -49,7 +57,7 @@ jobs:
4957
2>&1 | tee output.txt &
5058
- name: Run tests
5159
run: |
52-
wait-for-it --service 127.0.0.1:7860 -t 600
60+
wait-for-it --service 127.0.0.1:7860 -t 20
5361
python -m pytest -vv --junitxml=test/results.xml --cov . --cov-report=xml --verify-base-url test
5462
- name: Kill test server
5563
if: always()

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ notification.mp3
3737
/node_modules
3838
/package-lock.json
3939
/.coverage*
40+
/test/test_outputs

CHANGELOG.md

+132
Large diffs are not rendered by default.

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Stable Diffusion web UI
2-
A browser interface based on Gradio library for Stable Diffusion.
2+
A web interface for Stable Diffusion, implemented using Gradio library.
33

44
![](screenshot.png)
55

@@ -151,11 +151,12 @@ Licenses for borrowed code can be found in `Settings -> Licenses` screen, and al
151151

152152
- Stable Diffusion - https://github.com/Stability-AI/stablediffusion, https://github.com/CompVis/taming-transformers
153153
- k-diffusion - https://github.com/crowsonkb/k-diffusion.git
154-
- GFPGAN - https://github.com/TencentARC/GFPGAN.git
155-
- CodeFormer - https://github.com/sczhou/CodeFormer
156-
- ESRGAN - https://github.com/xinntao/ESRGAN
157-
- SwinIR - https://github.com/JingyunLiang/SwinIR
158-
- Swin2SR - https://github.com/mv-lab/swin2sr
154+
- Spandrel - https://github.com/chaiNNer-org/spandrel implementing
155+
- GFPGAN - https://github.com/TencentARC/GFPGAN.git
156+
- CodeFormer - https://github.com/sczhou/CodeFormer
157+
- ESRGAN - https://github.com/xinntao/ESRGAN
158+
- SwinIR - https://github.com/JingyunLiang/SwinIR
159+
- Swin2SR - https://github.com/mv-lab/swin2sr
159160
- LDSR - https://github.com/Hafiidz/latent-diffusion
160161
- MiDaS - https://github.com/isl-org/MiDaS
161162
- Ideas for optimizations - https://github.com/basujindal/stable-diffusion

configs/sd_xl_inpaint.yaml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
model:
2+
target: sgm.models.diffusion.DiffusionEngine
3+
params:
4+
scale_factor: 0.13025
5+
disable_first_stage_autocast: True
6+
7+
denoiser_config:
8+
target: sgm.modules.diffusionmodules.denoiser.DiscreteDenoiser
9+
params:
10+
num_idx: 1000
11+
12+
weighting_config:
13+
target: sgm.modules.diffusionmodules.denoiser_weighting.EpsWeighting
14+
scaling_config:
15+
target: sgm.modules.diffusionmodules.denoiser_scaling.EpsScaling
16+
discretization_config:
17+
target: sgm.modules.diffusionmodules.discretizer.LegacyDDPMDiscretization
18+
19+
network_config:
20+
target: sgm.modules.diffusionmodules.openaimodel.UNetModel
21+
params:
22+
adm_in_channels: 2816
23+
num_classes: sequential
24+
use_checkpoint: True
25+
in_channels: 9
26+
out_channels: 4
27+
model_channels: 320
28+
attention_resolutions: [4, 2]
29+
num_res_blocks: 2
30+
channel_mult: [1, 2, 4]
31+
num_head_channels: 64
32+
use_spatial_transformer: True
33+
use_linear_in_transformer: True
34+
transformer_depth: [1, 2, 10] # note: the first is unused (due to attn_res starting at 2) 32, 16, 8 --> 64, 32, 16
35+
context_dim: 2048
36+
spatial_transformer_attn_type: softmax-xformers
37+
legacy: False
38+
39+
conditioner_config:
40+
target: sgm.modules.GeneralConditioner
41+
params:
42+
emb_models:
43+
# crossattn cond
44+
- is_trainable: False
45+
input_key: txt
46+
target: sgm.modules.encoders.modules.FrozenCLIPEmbedder
47+
params:
48+
layer: hidden
49+
layer_idx: 11
50+
# crossattn and vector cond
51+
- is_trainable: False
52+
input_key: txt
53+
target: sgm.modules.encoders.modules.FrozenOpenCLIPEmbedder2
54+
params:
55+
arch: ViT-bigG-14
56+
version: laion2b_s39b_b160k
57+
freeze: True
58+
layer: penultimate
59+
always_return_pooled: True
60+
legacy: False
61+
# vector cond
62+
- is_trainable: False
63+
input_key: original_size_as_tuple
64+
target: sgm.modules.encoders.modules.ConcatTimestepEmbedderND
65+
params:
66+
outdim: 256 # multiplied by two
67+
# vector cond
68+
- is_trainable: False
69+
input_key: crop_coords_top_left
70+
target: sgm.modules.encoders.modules.ConcatTimestepEmbedderND
71+
params:
72+
outdim: 256 # multiplied by two
73+
# vector cond
74+
- is_trainable: False
75+
input_key: target_size_as_tuple
76+
target: sgm.modules.encoders.modules.ConcatTimestepEmbedderND
77+
params:
78+
outdim: 256 # multiplied by two
79+
80+
first_stage_config:
81+
target: sgm.models.autoencoder.AutoencoderKLInferenceWrapper
82+
params:
83+
embed_dim: 4
84+
monitor: val/rec_loss
85+
ddconfig:
86+
attn_type: vanilla-xformers
87+
double_z: true
88+
z_channels: 4
89+
resolution: 256
90+
in_channels: 3
91+
out_ch: 3
92+
ch: 128
93+
ch_mult: [1, 2, 4, 4]
94+
num_res_blocks: 2
95+
attn_resolutions: []
96+
dropout: 0.0
97+
lossconfig:
98+
target: torch.nn.Identity

extensions-builtin/Lora/network.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from collections import namedtuple
44
import enum
55

6+
import torch.nn as nn
7+
import torch.nn.functional as F
8+
69
from modules import sd_models, cache, errors, hashes, shared
710

811
NetworkWeights = namedtuple('NetworkWeights', ['network_key', 'sd_key', 'w', 'sd_module'])
@@ -115,6 +118,29 @@ def __init__(self, net: Network, weights: NetworkWeights):
115118
if hasattr(self.sd_module, 'weight'):
116119
self.shape = self.sd_module.weight.shape
117120

121+
self.ops = None
122+
self.extra_kwargs = {}
123+
if isinstance(self.sd_module, nn.Conv2d):
124+
self.ops = F.conv2d
125+
self.extra_kwargs = {
126+
'stride': self.sd_module.stride,
127+
'padding': self.sd_module.padding
128+
}
129+
elif isinstance(self.sd_module, nn.Linear):
130+
self.ops = F.linear
131+
elif isinstance(self.sd_module, nn.LayerNorm):
132+
self.ops = F.layer_norm
133+
self.extra_kwargs = {
134+
'normalized_shape': self.sd_module.normalized_shape,
135+
'eps': self.sd_module.eps
136+
}
137+
elif isinstance(self.sd_module, nn.GroupNorm):
138+
self.ops = F.group_norm
139+
self.extra_kwargs = {
140+
'num_groups': self.sd_module.num_groups,
141+
'eps': self.sd_module.eps
142+
}
143+
118144
self.dim = None
119145
self.bias = weights.w.get("bias")
120146
self.alpha = weights.w["alpha"].item() if "alpha" in weights.w else None
@@ -137,7 +163,7 @@ def calc_scale(self):
137163
def finalize_updown(self, updown, orig_weight, output_shape, ex_bias=None):
138164
if self.bias is not None:
139165
updown = updown.reshape(self.bias.shape)
140-
updown += self.bias.to(orig_weight.device, dtype=orig_weight.dtype)
166+
updown += self.bias.to(orig_weight.device, dtype=updown.dtype)
141167
updown = updown.reshape(output_shape)
142168

143169
if len(output_shape) == 4:
@@ -155,5 +181,10 @@ def calc_updown(self, target):
155181
raise NotImplementedError()
156182

157183
def forward(self, x, y):
158-
raise NotImplementedError()
184+
"""A general forward implementation for all modules"""
185+
if self.ops is None:
186+
raise NotImplementedError()
187+
else:
188+
updown, ex_bias = self.calc_updown(self.sd_module.weight)
189+
return y + self.ops(x, weight=updown, bias=ex_bias, **self.extra_kwargs)
159190

extensions-builtin/Lora/network_full.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def __init__(self, net: network.Network, weights: network.NetworkWeights):
1818

1919
def calc_updown(self, orig_weight):
2020
output_shape = self.weight.shape
21-
updown = self.weight.to(orig_weight.device, dtype=orig_weight.dtype)
21+
updown = self.weight.to(orig_weight.device)
2222
if self.ex_bias is not None:
23-
ex_bias = self.ex_bias.to(orig_weight.device, dtype=orig_weight.dtype)
23+
ex_bias = self.ex_bias.to(orig_weight.device)
2424
else:
2525
ex_bias = None
2626

extensions-builtin/Lora/network_glora.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def __init__(self, net: network.Network, weights: network.NetworkWeights):
2222
self.w2b = weights.w["b2.weight"]
2323

2424
def calc_updown(self, orig_weight):
25-
w1a = self.w1a.to(orig_weight.device, dtype=orig_weight.dtype)
26-
w1b = self.w1b.to(orig_weight.device, dtype=orig_weight.dtype)
27-
w2a = self.w2a.to(orig_weight.device, dtype=orig_weight.dtype)
28-
w2b = self.w2b.to(orig_weight.device, dtype=orig_weight.dtype)
25+
w1a = self.w1a.to(orig_weight.device)
26+
w1b = self.w1b.to(orig_weight.device)
27+
w2a = self.w2a.to(orig_weight.device)
28+
w2b = self.w2b.to(orig_weight.device)
2929

3030
output_shape = [w1a.size(0), w1b.size(1)]
31-
updown = ((w2b @ w1b) + ((orig_weight @ w2a) @ w1a))
31+
updown = ((w2b @ w1b) + ((orig_weight.to(dtype = w1a.dtype) @ w2a) @ w1a))
3232

3333
return self.finalize_updown(updown, orig_weight, output_shape)

extensions-builtin/Lora/network_hada.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ def __init__(self, net: network.Network, weights: network.NetworkWeights):
2727
self.t2 = weights.w.get("hada_t2")
2828

2929
def calc_updown(self, orig_weight):
30-
w1a = self.w1a.to(orig_weight.device, dtype=orig_weight.dtype)
31-
w1b = self.w1b.to(orig_weight.device, dtype=orig_weight.dtype)
32-
w2a = self.w2a.to(orig_weight.device, dtype=orig_weight.dtype)
33-
w2b = self.w2b.to(orig_weight.device, dtype=orig_weight.dtype)
30+
w1a = self.w1a.to(orig_weight.device)
31+
w1b = self.w1b.to(orig_weight.device)
32+
w2a = self.w2a.to(orig_weight.device)
33+
w2b = self.w2b.to(orig_weight.device)
3434

3535
output_shape = [w1a.size(0), w1b.size(1)]
3636

3737
if self.t1 is not None:
3838
output_shape = [w1a.size(1), w1b.size(1)]
39-
t1 = self.t1.to(orig_weight.device, dtype=orig_weight.dtype)
39+
t1 = self.t1.to(orig_weight.device)
4040
updown1 = lyco_helpers.make_weight_cp(t1, w1a, w1b)
4141
output_shape += t1.shape[2:]
4242
else:
@@ -45,7 +45,7 @@ def calc_updown(self, orig_weight):
4545
updown1 = lyco_helpers.rebuild_conventional(w1a, w1b, output_shape)
4646

4747
if self.t2 is not None:
48-
t2 = self.t2.to(orig_weight.device, dtype=orig_weight.dtype)
48+
t2 = self.t2.to(orig_weight.device)
4949
updown2 = lyco_helpers.make_weight_cp(t2, w2a, w2b)
5050
else:
5151
updown2 = lyco_helpers.rebuild_conventional(w2a, w2b, output_shape)

extensions-builtin/Lora/network_ia3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, net: network.Network, weights: network.NetworkWeights):
1717
self.on_input = weights.w["on_input"].item()
1818

1919
def calc_updown(self, orig_weight):
20-
w = self.w.to(orig_weight.device, dtype=orig_weight.dtype)
20+
w = self.w.to(orig_weight.device)
2121

2222
output_shape = [w.size(0), orig_weight.size(1)]
2323
if self.on_input:

extensions-builtin/Lora/network_lokr.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ def __init__(self, net: network.Network, weights: network.NetworkWeights):
3737

3838
def calc_updown(self, orig_weight):
3939
if self.w1 is not None:
40-
w1 = self.w1.to(orig_weight.device, dtype=orig_weight.dtype)
40+
w1 = self.w1.to(orig_weight.device)
4141
else:
42-
w1a = self.w1a.to(orig_weight.device, dtype=orig_weight.dtype)
43-
w1b = self.w1b.to(orig_weight.device, dtype=orig_weight.dtype)
42+
w1a = self.w1a.to(orig_weight.device)
43+
w1b = self.w1b.to(orig_weight.device)
4444
w1 = w1a @ w1b
4545

4646
if self.w2 is not None:
47-
w2 = self.w2.to(orig_weight.device, dtype=orig_weight.dtype)
47+
w2 = self.w2.to(orig_weight.device)
4848
elif self.t2 is None:
49-
w2a = self.w2a.to(orig_weight.device, dtype=orig_weight.dtype)
50-
w2b = self.w2b.to(orig_weight.device, dtype=orig_weight.dtype)
49+
w2a = self.w2a.to(orig_weight.device)
50+
w2b = self.w2b.to(orig_weight.device)
5151
w2 = w2a @ w2b
5252
else:
53-
t2 = self.t2.to(orig_weight.device, dtype=orig_weight.dtype)
54-
w2a = self.w2a.to(orig_weight.device, dtype=orig_weight.dtype)
55-
w2b = self.w2b.to(orig_weight.device, dtype=orig_weight.dtype)
53+
t2 = self.t2.to(orig_weight.device)
54+
w2a = self.w2a.to(orig_weight.device)
55+
w2b = self.w2b.to(orig_weight.device)
5656
w2 = lyco_helpers.make_weight_cp(t2, w2a, w2b)
5757

5858
output_shape = [w1.size(0) * w2.size(0), w1.size(1) * w2.size(1)]

extensions-builtin/Lora/network_lora.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ def create_module(self, weights, key, none_ok=False):
6161
return module
6262

6363
def calc_updown(self, orig_weight):
64-
up = self.up_model.weight.to(orig_weight.device, dtype=orig_weight.dtype)
65-
down = self.down_model.weight.to(orig_weight.device, dtype=orig_weight.dtype)
64+
up = self.up_model.weight.to(orig_weight.device)
65+
down = self.down_model.weight.to(orig_weight.device)
6666

6767
output_shape = [up.size(0), down.size(1)]
6868
if self.mid_model is not None:
6969
# cp-decomposition
70-
mid = self.mid_model.weight.to(orig_weight.device, dtype=orig_weight.dtype)
70+
mid = self.mid_model.weight.to(orig_weight.device)
7171
updown = lyco_helpers.rebuild_cp_decomposition(up, down, mid)
7272
output_shape += mid.shape[2:]
7373
else:

extensions-builtin/Lora/network_norm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def __init__(self, net: network.Network, weights: network.NetworkWeights):
1818

1919
def calc_updown(self, orig_weight):
2020
output_shape = self.w_norm.shape
21-
updown = self.w_norm.to(orig_weight.device, dtype=orig_weight.dtype)
21+
updown = self.w_norm.to(orig_weight.device)
2222

2323
if self.b_norm is not None:
24-
ex_bias = self.b_norm.to(orig_weight.device, dtype=orig_weight.dtype)
24+
ex_bias = self.b_norm.to(orig_weight.device)
2525
else:
2626
ex_bias = None
2727

0 commit comments

Comments
 (0)