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

Method forward

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

Perform a forward pass through the TransformerBlock. Args: x (torch.Tensor): Input tensor. freqs_cis (torch.Tensor): Precomputed cosine and sine frequencies. mask (torch.Tensor, optional): Masking tensor for attention. Defaults to

(
        self,
        x: torch.Tensor,
        freqs_cis: torch.Tensor,
        adaln_input: Optional[torch.Tensor] = None,
    )

Source from the content-addressed store, hash-verified

407 )
408
409 def forward(
410 self,
411 x: torch.Tensor,
412 freqs_cis: torch.Tensor,
413 adaln_input: Optional[torch.Tensor] = None,
414 ):
415 """
416 Perform a forward pass through the TransformerBlock.
417
418 Args:
419 x (torch.Tensor): Input tensor.
420 freqs_cis (torch.Tensor): Precomputed cosine and sine frequencies.
421 mask (torch.Tensor, optional): Masking tensor for attention.
422 Defaults to None.
423
424 Returns:
425 torch.Tensor: Output tensor after applying attention and
426 feedforward layers.
427
428 """
429 if adaln_input is not None:
430 shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = \
431 self.adaLN_modulation(adaln_input).chunk(6, dim=1)
432
433 x = x + gate_msa.unsqueeze(1) * self.attention(
434 modulate(self.attention_norm(x), shift_msa, scale_msa),
435 freqs_cis,
436 )
437 x = x + gate_mlp.unsqueeze(1) * self.feed_forward(
438 modulate(self.ffn_norm(x), shift_mlp, scale_mlp),
439 )
440
441 else:
442 x = x + self.attention(
443 self.attention_norm(x), freqs_cis,
444 )
445 x = x + self.feed_forward(self.ffn_norm(x))
446
447 return x
448
449class ParallelFinalLayer(nn.Module):
450 """

Callers

nothing calls this directly

Calls 1

modulateFunction · 0.70

Tested by

no test coverage detected