The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Use fused situ with MOSS-image (#17099)
Jukka Seppänena639f187a9f6
diff --git a/comfy/ldm/moss_image/model.py b/comfy/ldm/moss_image/model.pyindex 3122b19ac..d733ff4ac 100644--- a/comfy/ldm/moss_image/model.py+++ b/comfy/ldm/moss_image/model.py@@ -118,10 +118,8 @@ class Block(nn.Module):out = attention(q, k, v, self.q_norm, self.k_norm, pe, self.num_heads, self.comfy_attention, transformer_options)x = gated_residual(x, self.proj["o"](out), gate_a)y = modulated_rms_norm(x, self.norm2, scale_f, shift_f)- hidden, gate = self.proj["ffn_up_gate"](y).chunk(2, dim=-1)- # situ without its 4 * 25 factor, applied on the gate instead (ffn_down has no bias): two fewer passes- out = self.proj["ffn_down"](torch.tanh(gate / 4.0) * torch.sigmoid(gate) * torch.tanh(hidden / 25.0))- return gated_residual(x, out, gate_f * 100.0)+ # situ on the [hidden | gate] halves; int8 weights fold it into the activation quantization+ return gated_residual(x, comfy.ops.linear_input_act(self.proj["ffn_down"], self.proj["ffn_up_gate"](y), "situ"), gate_f)class MOSSImage(nn.Module):diff --git a/comfy/ops.py b/comfy/ops.pyindex 4fdbc0dac..07dd351d0 100644--- a/comfy/ops.py+++ b/comfy/ops.py@@ -977,9 +977,16 @@ def _swiglu_eager(x):return torch.nn.functional.silu(gate).mul_(up)+def _situ_eager(x):+ # out of place: the training path runs through here+ hidden, gate = x.chunk(2, dim=-1)+ return (4.0 * torch.tanh(gate / 4.0) * torch.sigmoid(gate)) * (25.0 * torch.tanh(hidden / 25.0))++INPUT_ACT_EAGER = {"gelu_tanh": lambda x: torch.nn.functional.gelu(x, approximate="tanh"),"swiglu": _swiglu_eager,+ "situ": _situ_eager,}