MCPcopy Create free account
hub / github.com/ali-vilab/ACE_plus / LastLayer

Class LastLayer

modules/layers.py:495–506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493
494
495class LastLayer(nn.Module):
496 def __init__(self, hidden_size: int, patch_size: int, out_channels: int):
497 super().__init__()
498 self.norm_final = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
499 self.linear = nn.Linear(hidden_size, patch_size * patch_size * out_channels, bias=True)
500 self.adaLN_modulation = nn.Sequential(nn.SiLU(), nn.Linear(hidden_size, 2 * hidden_size, bias=True))
501
502 def forward(self, x: Tensor, vec: Tensor) -> Tensor:
503 shift, scale = self.adaLN_modulation(vec).chunk(2, dim=1)
504 x = (1 + scale[:, None, :]) * self.norm_final(x) + shift[:, None, :]
505 x = self.linear(x)
506 return x
507
508
509if __name__ == '__main__':

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected