InvokeAI 2.2.4.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- backend/__init__.py +0 -0
- backend/invoke_ai_web_server.py +1724 -0
- backend/modules/__init__.py +0 -0
- backend/modules/create_cmd_parser.py +55 -0
- backend/modules/get_canvas_generation_mode.py +117 -0
- backend/modules/parameters.py +71 -0
- backend/modules/parse_seed_weights.py +47 -0
- configs/INITIAL_MODELS.yaml +80 -0
- configs/models.yaml.example +29 -0
- configs/sd-concepts.txt +803 -0
- configs/stable-diffusion/v1-finetune.yaml +110 -0
- configs/stable-diffusion/v1-finetune_style.yaml +103 -0
- configs/stable-diffusion/v1-inference.yaml +79 -0
- configs/stable-diffusion/v1-inpainting-inference.yaml +79 -0
- configs/stable-diffusion/v1-m1-finetune.yaml +110 -0
- docs/assets/invoke-web-server-1.png +0 -0
- docs/assets/invoke_ai_banner.png +0 -0
- invokeai-2.2.4.5.data/data/assets/caution.png +0 -0
- invokeai-2.2.4.5.data/data/configs/INITIAL_MODELS.yaml +80 -0
- invokeai-2.2.4.5.data/data/configs/models.yaml.example +29 -0
- invokeai-2.2.4.5.data/data/configs/sd-concepts.txt +803 -0
- invokeai-2.2.4.5.data/data/configs/stable-diffusion/v1-finetune.yaml +110 -0
- invokeai-2.2.4.5.data/data/configs/stable-diffusion/v1-finetune_style.yaml +103 -0
- invokeai-2.2.4.5.data/data/configs/stable-diffusion/v1-inference.yaml +79 -0
- invokeai-2.2.4.5.data/data/configs/stable-diffusion/v1-inpainting-inference.yaml +79 -0
- invokeai-2.2.4.5.data/data/configs/stable-diffusion/v1-m1-finetune.yaml +110 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/Inter-Bold.790c108b.ttf +0 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/Inter.b9a8e5e2.ttf +0 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/favicon.0d253ced.ico +0 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/index-legacy-b741077f.js +48 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/index.0dadf5d0.css +1 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/index.21ff81eb.js +625 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/logo.13003d72.png +0 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/polyfills-legacy-dde3a68a.js +4 -0
- invokeai-2.2.4.5.data/data/frontend/dist/assets/polyfills.1ff60148.js +1 -0
- invokeai-2.2.4.5.data/data/frontend/dist/index.html +23 -0
- invokeai-2.2.4.5.data/data/scripts/configure_invokeai.py +797 -0
- invokeai-2.2.4.5.data/data/scripts/create_root.py +43 -0
- invokeai-2.2.4.5.data/data/scripts/dream.py +10 -0
- invokeai-2.2.4.5.data/data/scripts/images2prompt.py +30 -0
- invokeai-2.2.4.5.data/data/scripts/invoke.py +5 -0
- invokeai-2.2.4.5.data/data/scripts/legacy_api.py +681 -0
- invokeai-2.2.4.5.data/data/scripts/load_models.py +12 -0
- invokeai-2.2.4.5.data/data/scripts/merge_embeddings.py +124 -0
- invokeai-2.2.4.5.data/data/scripts/preload_models.py +12 -0
- invokeai-2.2.4.5.data/data/scripts/sd-metadata.py +22 -0
- invokeai-2.2.4.5.dist-info/LICENSE +21 -0
- invokeai-2.2.4.5.dist-info/LICENSE-ModelWeights.txt +294 -0
- invokeai-2.2.4.5.dist-info/METADATA +288 -0
- invokeai-2.2.4.5.dist-info/RECORD +169 -0
- invokeai-2.2.4.5.dist-info/WHEEL +5 -0
- invokeai-2.2.4.5.dist-info/entry_points.txt +4 -0
- invokeai-2.2.4.5.dist-info/top_level.txt +6 -0
- invokeai-2.2.4.5.dist-info/zip-safe +1 -0
- ldm/__init__.py +0 -0
- ldm/data/__init__.py +0 -0
- ldm/data/base.py +31 -0
- ldm/data/imagenet.py +466 -0
- ldm/data/lsun.py +126 -0
- ldm/data/personalized.py +202 -0
- ldm/data/personalized_style.py +169 -0
- ldm/generate.py +1159 -0
- ldm/invoke/CLI.py +960 -0
- ldm/invoke/__init__.py +3 -0
- ldm/invoke/args.py +1257 -0
- ldm/invoke/concepts_lib.py +169 -0
- ldm/invoke/conditioning.py +289 -0
- ldm/invoke/devices.py +27 -0
- ldm/invoke/generator/__init__.py +4 -0
- ldm/invoke/generator/base.py +335 -0
- ldm/invoke/generator/embiggen.py +501 -0
- ldm/invoke/generator/img2img.py +97 -0
- ldm/invoke/generator/inpaint.py +358 -0
- ldm/invoke/generator/omnibus.py +175 -0
- ldm/invoke/generator/txt2img.py +88 -0
- ldm/invoke/generator/txt2img2img.py +182 -0
- ldm/invoke/globals.py +31 -0
- ldm/invoke/image_util.py +70 -0
- ldm/invoke/log.py +66 -0
- ldm/invoke/model_cache.py +449 -0
- ldm/invoke/patchmatch.py +44 -0
- ldm/invoke/pngwriter.py +113 -0
- ldm/invoke/prompt_parser.py +655 -0
- ldm/invoke/readline.py +442 -0
- ldm/invoke/restoration/__init__.py +4 -0
- ldm/invoke/restoration/base.py +38 -0
- ldm/invoke/restoration/codeformer.py +103 -0
- ldm/invoke/restoration/codeformer_arch.py +276 -0
- ldm/invoke/restoration/gfpgan.py +84 -0
- ldm/invoke/restoration/outcrop.py +108 -0
- ldm/invoke/restoration/outpaint.py +92 -0
- ldm/invoke/restoration/realesrgan.py +90 -0
- ldm/invoke/restoration/vqgan_arch.py +435 -0
- ldm/invoke/seamless.py +30 -0
- ldm/invoke/server.py +282 -0
- ldm/invoke/server_legacy.py +246 -0
- ldm/invoke/txt2mask.py +136 -0
- ldm/lr_scheduler.py +143 -0
- ldm/models/__init__.py +0 -0
- ldm/models/autoencoder.py +596 -0
- ldm/models/diffusion/__init__.py +0 -0
- ldm/models/diffusion/classifier.py +355 -0
- ldm/models/diffusion/cross_attention_control.py +443 -0
- ldm/models/diffusion/cross_attention_map_saving.py +95 -0
- ldm/models/diffusion/ddim.py +111 -0
- ldm/models/diffusion/ddpm.py +2263 -0
- ldm/models/diffusion/ksampler.py +312 -0
- ldm/models/diffusion/plms.py +146 -0
- ldm/models/diffusion/sampler.py +450 -0
- ldm/models/diffusion/shared_invokeai_diffusion.py +244 -0
- ldm/modules/__init__.py +0 -0
- ldm/modules/attention.py +274 -0
- ldm/modules/diffusionmodules/__init__.py +0 -0
- ldm/modules/diffusionmodules/model.py +894 -0
- ldm/modules/diffusionmodules/openaimodel.py +1036 -0
- ldm/modules/diffusionmodules/util.py +314 -0
- ldm/modules/distributions/__init__.py +0 -0
- ldm/modules/distributions/distributions.py +104 -0
- ldm/modules/ema.py +88 -0
- ldm/modules/embedding_manager.py +413 -0
- ldm/modules/encoders/__init__.py +0 -0
- ldm/modules/encoders/modules.py +772 -0
- ldm/modules/image_degradation/__init__.py +6 -0
- ldm/modules/image_degradation/bsrgan.py +846 -0
- ldm/modules/image_degradation/bsrgan_light.py +751 -0
- ldm/modules/image_degradation/utils_image.py +1024 -0
- ldm/modules/losses/__init__.py +1 -0
- ldm/modules/losses/contperceptual.py +175 -0
- ldm/modules/losses/vqperceptual.py +240 -0
- ldm/modules/x_transformer.py +752 -0
- ldm/simplet2i.py +13 -0
- ldm/util.py +264 -0
- scripts/configure_invokeai.py +797 -0
- scripts/create_root.py +43 -0
- scripts/dream.py +10 -0
- scripts/images2prompt.py +30 -0
- scripts/invoke.py +5 -0
- scripts/legacy_api.py +681 -0
- scripts/load_models.py +12 -0
- scripts/merge_embeddings.py +124 -0
- scripts/orig_scripts/img2img.py +296 -0
- scripts/orig_scripts/inpaint.py +98 -0
- scripts/orig_scripts/knn2img.py +397 -0
- scripts/orig_scripts/sample_diffusion.py +313 -0
- scripts/orig_scripts/train_searcher.py +147 -0
- scripts/orig_scripts/txt2img.py +324 -0
- scripts/preload_models.py +12 -0
- scripts/sd-metadata.py +22 -0
- vendored/clip/clip/__init__.py +1 -0
- vendored/clip/clip/bpe_simple_vocab_16e6.txt.gz +0 -0
- vendored/clip/clip/clip.py +237 -0
- vendored/clip/clip/model.py +436 -0
- vendored/clip/clip/simple_tokenizer.py +132 -0
- vendored/clip/hubconf.py +42 -0
- vendored/clip/setup.py +21 -0
- vendored/clip/tests/test_consistency.py +25 -0
- vendored/clipseg/datasets/coco_wrapper.py +99 -0
- vendored/clipseg/datasets/pascal_zeroshot.py +60 -0
- vendored/clipseg/datasets/pfe_dataset.py +129 -0
- vendored/clipseg/datasets/phrasecut.py +380 -0
- vendored/clipseg/datasets/utils.py +68 -0
- vendored/clipseg/evaluation_utils.py +292 -0
- vendored/clipseg/general_utils.py +272 -0
- vendored/clipseg/metrics.py +271 -0
- vendored/clipseg/models/clipseg.py +538 -0
- vendored/clipseg/models/vitseg.py +286 -0
- vendored/clipseg/score.py +453 -0
- vendored/clipseg/setup.py +30 -0
- vendored/clipseg/training.py +266 -0
ldm/modules/attention.py
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
from inspect import isfunction
|
|
2
|
+
import math
|
|
3
|
+
from typing import Callable, Optional
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
import torch.nn.functional as F
|
|
7
|
+
from torch import nn, einsum
|
|
8
|
+
from einops import rearrange, repeat
|
|
9
|
+
|
|
10
|
+
from ldm.models.diffusion.cross_attention_control import InvokeAICrossAttentionMixin
|
|
11
|
+
from ldm.modules.diffusionmodules.util import checkpoint
|
|
12
|
+
|
|
13
|
+
def exists(val):
|
|
14
|
+
return val is not None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def uniq(arr):
|
|
18
|
+
return{el: True for el in arr}.keys()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def default(val, d):
|
|
22
|
+
if exists(val):
|
|
23
|
+
return val
|
|
24
|
+
return d() if isfunction(d) else d
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def max_neg_value(t):
|
|
28
|
+
return -torch.finfo(t.dtype).max
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def init_(tensor):
|
|
32
|
+
dim = tensor.shape[-1]
|
|
33
|
+
std = 1 / math.sqrt(dim)
|
|
34
|
+
tensor.uniform_(-std, std)
|
|
35
|
+
return tensor
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# feedforward
|
|
39
|
+
class GEGLU(nn.Module):
|
|
40
|
+
def __init__(self, dim_in, dim_out):
|
|
41
|
+
super().__init__()
|
|
42
|
+
self.proj = nn.Linear(dim_in, dim_out * 2)
|
|
43
|
+
|
|
44
|
+
def forward(self, x):
|
|
45
|
+
x, gate = self.proj(x).chunk(2, dim=-1)
|
|
46
|
+
return x * F.gelu(gate)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class FeedForward(nn.Module):
|
|
50
|
+
def __init__(self, dim, dim_out=None, mult=4, glu=False, dropout=0.):
|
|
51
|
+
super().__init__()
|
|
52
|
+
inner_dim = int(dim * mult)
|
|
53
|
+
dim_out = default(dim_out, dim)
|
|
54
|
+
project_in = nn.Sequential(
|
|
55
|
+
nn.Linear(dim, inner_dim),
|
|
56
|
+
nn.GELU()
|
|
57
|
+
) if not glu else GEGLU(dim, inner_dim)
|
|
58
|
+
|
|
59
|
+
self.net = nn.Sequential(
|
|
60
|
+
project_in,
|
|
61
|
+
nn.Dropout(dropout),
|
|
62
|
+
nn.Linear(inner_dim, dim_out)
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
def forward(self, x):
|
|
66
|
+
return self.net(x)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def zero_module(module):
|
|
70
|
+
"""
|
|
71
|
+
Zero out the parameters of a module and return it.
|
|
72
|
+
"""
|
|
73
|
+
for p in module.parameters():
|
|
74
|
+
p.detach().zero_()
|
|
75
|
+
return module
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def Normalize(in_channels):
|
|
79
|
+
return torch.nn.GroupNorm(num_groups=32, num_channels=in_channels, eps=1e-6, affine=True)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class LinearAttention(nn.Module):
|
|
83
|
+
def __init__(self, dim, heads=4, dim_head=32):
|
|
84
|
+
super().__init__()
|
|
85
|
+
self.heads = heads
|
|
86
|
+
hidden_dim = dim_head * heads
|
|
87
|
+
self.to_qkv = nn.Conv2d(dim, hidden_dim * 3, 1, bias = False)
|
|
88
|
+
self.to_out = nn.Conv2d(hidden_dim, dim, 1)
|
|
89
|
+
|
|
90
|
+
def forward(self, x):
|
|
91
|
+
b, c, h, w = x.shape
|
|
92
|
+
qkv = self.to_qkv(x)
|
|
93
|
+
q, k, v = rearrange(qkv, 'b (qkv heads c) h w -> qkv b heads c (h w)', heads = self.heads, qkv=3)
|
|
94
|
+
k = k.softmax(dim=-1)
|
|
95
|
+
context = torch.einsum('bhdn,bhen->bhde', k, v)
|
|
96
|
+
out = torch.einsum('bhde,bhdn->bhen', context, q)
|
|
97
|
+
out = rearrange(out, 'b heads c (h w) -> b (heads c) h w', heads=self.heads, h=h, w=w)
|
|
98
|
+
return self.to_out(out)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class SpatialSelfAttention(nn.Module):
|
|
102
|
+
def __init__(self, in_channels):
|
|
103
|
+
super().__init__()
|
|
104
|
+
self.in_channels = in_channels
|
|
105
|
+
|
|
106
|
+
self.norm = Normalize(in_channels)
|
|
107
|
+
self.q = torch.nn.Conv2d(in_channels,
|
|
108
|
+
in_channels,
|
|
109
|
+
kernel_size=1,
|
|
110
|
+
stride=1,
|
|
111
|
+
padding=0)
|
|
112
|
+
self.k = torch.nn.Conv2d(in_channels,
|
|
113
|
+
in_channels,
|
|
114
|
+
kernel_size=1,
|
|
115
|
+
stride=1,
|
|
116
|
+
padding=0)
|
|
117
|
+
self.v = torch.nn.Conv2d(in_channels,
|
|
118
|
+
in_channels,
|
|
119
|
+
kernel_size=1,
|
|
120
|
+
stride=1,
|
|
121
|
+
padding=0)
|
|
122
|
+
self.proj_out = torch.nn.Conv2d(in_channels,
|
|
123
|
+
in_channels,
|
|
124
|
+
kernel_size=1,
|
|
125
|
+
stride=1,
|
|
126
|
+
padding=0)
|
|
127
|
+
|
|
128
|
+
def forward(self, x):
|
|
129
|
+
h_ = x
|
|
130
|
+
h_ = self.norm(h_)
|
|
131
|
+
q = self.q(h_)
|
|
132
|
+
k = self.k(h_)
|
|
133
|
+
v = self.v(h_)
|
|
134
|
+
|
|
135
|
+
# compute attention
|
|
136
|
+
b,c,h,w = q.shape
|
|
137
|
+
q = rearrange(q, 'b c h w -> b (h w) c')
|
|
138
|
+
k = rearrange(k, 'b c h w -> b c (h w)')
|
|
139
|
+
w_ = torch.einsum('bij,bjk->bik', q, k)
|
|
140
|
+
|
|
141
|
+
w_ = w_ * (int(c)**(-0.5))
|
|
142
|
+
w_ = torch.nn.functional.softmax(w_, dim=2)
|
|
143
|
+
|
|
144
|
+
# attend to values
|
|
145
|
+
v = rearrange(v, 'b c h w -> b c (h w)')
|
|
146
|
+
w_ = rearrange(w_, 'b i j -> b j i')
|
|
147
|
+
h_ = torch.einsum('bij,bjk->bik', v, w_)
|
|
148
|
+
h_ = rearrange(h_, 'b c (h w) -> b c h w', h=h)
|
|
149
|
+
h_ = self.proj_out(h_)
|
|
150
|
+
|
|
151
|
+
return x+h_
|
|
152
|
+
|
|
153
|
+
def get_mem_free_total(device):
|
|
154
|
+
#only on cuda
|
|
155
|
+
if not torch.cuda.is_available():
|
|
156
|
+
return None
|
|
157
|
+
stats = torch.cuda.memory_stats(device)
|
|
158
|
+
mem_active = stats['active_bytes.all.current']
|
|
159
|
+
mem_reserved = stats['reserved_bytes.all.current']
|
|
160
|
+
mem_free_cuda, _ = torch.cuda.mem_get_info(device)
|
|
161
|
+
mem_free_torch = mem_reserved - mem_active
|
|
162
|
+
mem_free_total = mem_free_cuda + mem_free_torch
|
|
163
|
+
return mem_free_total
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class CrossAttention(nn.Module, InvokeAICrossAttentionMixin):
|
|
167
|
+
def __init__(self, query_dim, context_dim=None, heads=8, dim_head=64, dropout=0.):
|
|
168
|
+
super().__init__()
|
|
169
|
+
InvokeAICrossAttentionMixin.__init__(self)
|
|
170
|
+
inner_dim = dim_head * heads
|
|
171
|
+
context_dim = default(context_dim, query_dim)
|
|
172
|
+
|
|
173
|
+
self.scale = dim_head ** -0.5
|
|
174
|
+
self.heads = heads
|
|
175
|
+
|
|
176
|
+
self.to_q = nn.Linear(query_dim, inner_dim, bias=False)
|
|
177
|
+
self.to_k = nn.Linear(context_dim, inner_dim, bias=False)
|
|
178
|
+
self.to_v = nn.Linear(context_dim, inner_dim, bias=False)
|
|
179
|
+
|
|
180
|
+
self.to_out = nn.Sequential(
|
|
181
|
+
nn.Linear(inner_dim, query_dim),
|
|
182
|
+
nn.Dropout(dropout)
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
def forward(self, x, context=None, mask=None):
|
|
186
|
+
h = self.heads
|
|
187
|
+
|
|
188
|
+
q = self.to_q(x)
|
|
189
|
+
context = default(context, x)
|
|
190
|
+
k = self.to_k(context) * self.scale
|
|
191
|
+
v = self.to_v(context)
|
|
192
|
+
del context, x
|
|
193
|
+
|
|
194
|
+
q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> (b h) n d', h=h), (q, k, v))
|
|
195
|
+
|
|
196
|
+
# don't apply scale twice
|
|
197
|
+
cached_scale = self.scale
|
|
198
|
+
self.scale = 1
|
|
199
|
+
r = self.get_invokeai_attention_mem_efficient(q, k, v)
|
|
200
|
+
self.scale = cached_scale
|
|
201
|
+
|
|
202
|
+
hidden_states = rearrange(r, '(b h) n d -> b n (h d)', h=h)
|
|
203
|
+
return self.to_out(hidden_states)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class BasicTransformerBlock(nn.Module):
|
|
209
|
+
def __init__(self, dim, n_heads, d_head, dropout=0., context_dim=None, gated_ff=True, checkpoint=True):
|
|
210
|
+
super().__init__()
|
|
211
|
+
self.attn1 = CrossAttention(query_dim=dim, heads=n_heads, dim_head=d_head, dropout=dropout) # is a self-attention
|
|
212
|
+
self.ff = FeedForward(dim, dropout=dropout, glu=gated_ff)
|
|
213
|
+
self.attn2 = CrossAttention(query_dim=dim, context_dim=context_dim,
|
|
214
|
+
heads=n_heads, dim_head=d_head, dropout=dropout) # is self-attn if context is none
|
|
215
|
+
self.norm1 = nn.LayerNorm(dim)
|
|
216
|
+
self.norm2 = nn.LayerNorm(dim)
|
|
217
|
+
self.norm3 = nn.LayerNorm(dim)
|
|
218
|
+
self.checkpoint = checkpoint
|
|
219
|
+
|
|
220
|
+
def forward(self, x, context=None):
|
|
221
|
+
return checkpoint(self._forward, (x, context), self.parameters(), self.checkpoint)
|
|
222
|
+
|
|
223
|
+
def _forward(self, x, context=None):
|
|
224
|
+
x = x.contiguous() if x.device.type == 'mps' else x
|
|
225
|
+
x += self.attn1(self.norm1(x.clone()))
|
|
226
|
+
x += self.attn2(self.norm2(x.clone()), context=context)
|
|
227
|
+
x += self.ff(self.norm3(x.clone()))
|
|
228
|
+
return x
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class SpatialTransformer(nn.Module):
|
|
232
|
+
"""
|
|
233
|
+
Transformer block for image-like data.
|
|
234
|
+
First, project the input (aka embedding)
|
|
235
|
+
and reshape to b, t, d.
|
|
236
|
+
Then apply standard transformer action.
|
|
237
|
+
Finally, reshape to image
|
|
238
|
+
"""
|
|
239
|
+
def __init__(self, in_channels, n_heads, d_head,
|
|
240
|
+
depth=1, dropout=0., context_dim=None):
|
|
241
|
+
super().__init__()
|
|
242
|
+
self.in_channels = in_channels
|
|
243
|
+
inner_dim = n_heads * d_head
|
|
244
|
+
self.norm = Normalize(in_channels)
|
|
245
|
+
|
|
246
|
+
self.proj_in = nn.Conv2d(in_channels,
|
|
247
|
+
inner_dim,
|
|
248
|
+
kernel_size=1,
|
|
249
|
+
stride=1,
|
|
250
|
+
padding=0)
|
|
251
|
+
|
|
252
|
+
self.transformer_blocks = nn.ModuleList(
|
|
253
|
+
[BasicTransformerBlock(inner_dim, n_heads, d_head, dropout=dropout, context_dim=context_dim)
|
|
254
|
+
for d in range(depth)]
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
self.proj_out = zero_module(nn.Conv2d(inner_dim,
|
|
258
|
+
in_channels,
|
|
259
|
+
kernel_size=1,
|
|
260
|
+
stride=1,
|
|
261
|
+
padding=0))
|
|
262
|
+
|
|
263
|
+
def forward(self, x, context=None):
|
|
264
|
+
# note: if no context is given, cross-attention defaults to self-attention
|
|
265
|
+
b, c, h, w = x.shape
|
|
266
|
+
x_in = x
|
|
267
|
+
x = self.norm(x)
|
|
268
|
+
x = self.proj_in(x)
|
|
269
|
+
x = rearrange(x, 'b c h w -> b (h w) c')
|
|
270
|
+
for block in self.transformer_blocks:
|
|
271
|
+
x = block(x, context=context)
|
|
272
|
+
x = rearrange(x, 'b (h w) c -> b c h w', h=h, w=w)
|
|
273
|
+
x = self.proj_out(x)
|
|
274
|
+
return x + x_in
|
|
File without changes
|