MCPcopy Create free account
hub / github.com/MotrixLab/FineMoGen / StylizationBlock

Class StylizationBlock

mogen/models/utils/stylization_block.py:14–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class StylizationBlock(nn.Module):
15
16 def __init__(self, latent_dim, time_embed_dim, dropout):
17 super().__init__()
18 self.emb_layers = nn.Sequential(
19 nn.SiLU(),
20 nn.Linear(time_embed_dim, 2 * latent_dim),
21 )
22 self.norm = nn.LayerNorm(latent_dim)
23 self.out_layers = nn.Sequential(
24 nn.SiLU(),
25 nn.Dropout(p=dropout),
26 zero_module(nn.Linear(latent_dim, latent_dim)),
27 )
28
29 def forward(self, h, emb):
30 """
31 h: B, T, D
32 emb: B, D
33 """
34 # B, 1, 2D
35 emb_out = self.emb_layers(emb).unsqueeze(1)
36 # scale: B, 1, D / shift: B, 1, D
37 scale, shift = torch.chunk(emb_out, 2, dim=2)
38 h = self.norm(h) * (1 + scale) + shift
39 h = self.out_layers(h)
40 return h

Callers 12

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected