Skip to content

Commit 62863ac

Browse files
authored
~7% speedup (1.57 to 1.69it/s) from switch to += in ldm.modules.attention. (#482)
Tested on 8GB eGPU nvidia setup so YMMV. 512x512 output, max VRAM stays same.
1 parent 79ac0f3 commit 62863ac

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ldm/modules/attention.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ def forward(self, x, context=None):
235235

236236
def _forward(self, x, context=None):
237237
x = x.contiguous() if x.device.type == 'mps' else x
238-
x = self.attn1(self.norm1(x)) + x
239-
x = self.attn2(self.norm2(x), context=context) + x
240-
x = self.ff(self.norm3(x)) + x
238+
x += self.attn1(self.norm1(x))
239+
x += self.attn2(self.norm2(x), context=context)
240+
x += self.ff(self.norm3(x))
241241
return x
242242

243243

0 commit comments

Comments
 (0)