MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / forward

Method forward

k_diffusion/models/modules.py:478–491  ·  view source on GitHub ↗
(self, x, pos, cond)

Source from the content-addressed store, hash-verified

476 return f"d_head={self.d_head}, window_size={self.window_size}, window_shift={self.window_shift}"
477
478 def forward(self, x, pos, cond):
479 skip = x
480 x = self.norm(x, cond)
481 qkv = self.qkv_proj(x)
482 q, k, v = rearrange(qkv, "n h w (t nh e) -> t n nh h w e", t=3, e=self.d_head)
483 q, k = scale_for_cosine_sim(q, k, self.scale[:, None, None, None], 1e-6)
484 theta = self.pos_emb(pos).movedim(-2, -4)
485 q = apply_rotary_emb_(q, theta)
486 k = apply_rotary_emb_(k, theta)
487 x = apply_window_attention(self.window_size, self.window_shift, q, k, v, scale=1.0)
488 x = rearrange(x, "n nh h w e -> n h w (nh e)")
489 x = self.dropout(x)
490 x = self.out_proj(x)
491 return x + skip
492
493
494class FeedForwardBlock(nn.Module):

Callers

nothing calls this directly

Calls 3

apply_rotary_emb_Function · 0.85
apply_window_attentionFunction · 0.85
scale_for_cosine_simFunction · 0.70

Tested by

no test coverage detected