Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Lower peak MOSS memory a bit. (#17338)

comfyanonymous067f853305e7
diff --git a/comfy/ldm/moss_image/model.py b/comfy/ldm/moss_image/model.py
index b50baf6a9..58108b332 100644
--- a/comfy/ldm/moss_image/model.py
+++ b/comfy/ldm/moss_image/model.py
@@ -100,6 +100,7 @@ class TextBlock(nn.Module):
def forward(self, x, pe, transformer_options={}, mask=None):
q, k, v = self.qkv(self.norm1(x)).chunk(3, dim=-1)
x = x + self.proj(attention(q, k, v, self.q_norm, self.k_norm, pe, self.num_heads, self.comfy_attention, transformer_options, mask=mask))
+ del q, k, v
y = self.norm2(x)
return x + self.ffn_down(situ(self.ffn_up(y), self.ffn_gate(y)))
@@ -143,11 +144,15 @@ class Block(nn.Module):
q, k, v = self.proj["qkv"](y).chunk(3, dim=-1)
else:
q, k, v = self.proj["q"](y), self.proj["k"](y), self.proj["v"](y)
+ del y
out = attention(q, k, v, self.q_norm, self.k_norm, pe, self.num_heads, self.comfy_attention, transformer_options, ref_kv, kv_out, mask)
+ del q, k, v
x = residual(x, self.proj["o"](out), mod, 2, ref)
+ del out
y = modulate(x, self.norm2, mod, 3, ref)
+ y = self.proj["ffn_up_gate"](y)
# situ on the [hidden | gate] halves; int8 weights fold it into the activation quantization
- return residual(x, comfy.ops.linear_input_act(self.proj["ffn_down"], self.proj["ffn_up_gate"](y), "situ"), mod, 5, ref)
+ return residual(x, comfy.ops.linear_input_act(self.proj["ffn_down"], y, "situ"), mod, 5, ref)
class MOSSImage(nn.Module):