MCPcopy Create free account
hub / github.com/cswry/VOSR / FinalLayer

Class FinalLayer

models/lightningdit.py:308–328  ·  view source on GitHub ↗

The final layer of LightningDiT.

Source from the content-addressed store, hash-verified

306 return x
307
308class FinalLayer(nn.Module):
309 """
310 The final layer of LightningDiT.
311 """
312 def __init__(self, hidden_size, patch_size, out_channels, use_rmsnorm=False):
313 super().__init__()
314 if not use_rmsnorm:
315 self.norm_final = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
316 else:
317 self.norm_final = RMSNorm(hidden_size)
318 self.linear = nn.Linear(hidden_size, patch_size * patch_size * out_channels, bias=True)
319 self.adaLN_modulation = nn.Sequential(
320 nn.SiLU(),
321 nn.Linear(hidden_size, 2 * hidden_size, bias=True)
322 )
323 @torch.compile
324 def forward(self, x, c):
325 shift, scale = self.adaLN_modulation(c).chunk(2, dim=1)
326 x = modulate(self.norm_final(x), shift, scale)
327 x = self.linear(x)
328 return x
329
330
331class LightningDiT(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected