MCPcopy Create free account
hub / github.com/Alpha-VLLM/LLaMA2-Accessory / ParallelFinalLayer

Class ParallelFinalLayer

Large-DiT-ImageNet/models.py:449–474  ·  view source on GitHub ↗

The final layer of DiT.

Source from the content-addressed store, hash-verified

447 return x
448
449class ParallelFinalLayer(nn.Module):
450 """
451 The final layer of DiT.
452 """
453 def __init__(self, hidden_size, patch_size, out_channels):
454 super().__init__()
455 self.norm_final = nn.LayerNorm(
456 hidden_size, elementwise_affine=False, eps=1e-6,
457 )
458 self.linear = ColumnParallelLinear(
459 hidden_size, patch_size * patch_size * out_channels, bias=True,
460 init_method=nn.init.zeros_, gather_output=True,
461 )
462 self.adaLN_modulation = nn.Sequential(
463 nn.SiLU(),
464 ColumnParallelLinear(
465 min(hidden_size, 1024), 2 * hidden_size, bias=True,
466 init_method=nn.init.zeros_, gather_output=True,
467 ),
468 )
469
470 def forward(self, x, c):
471 shift, scale = self.adaLN_modulation(c).chunk(2, dim=1)
472 x = modulate(self.norm_final(x), shift, scale)
473 x = self.linear(x)
474 return x
475
476
477class DiT_Llama(nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected