self_attention
self_attention
¶
Self-attention block: norm -> self-attention -> gated residual.
SelfAttentionBlock
¶
Bases: TransformerBlock
Norm -> self-attention -> gated residual.
Source code in src/versatil/models/layers/transformer/block/self_attention.py
forward
¶
forward(hidden_states, conditioning=None, attention_mask=None, positional_encoding=None, generation_cache=None)
Norm -> self-attention -> gated residual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states
|
Tensor
|
Input embeddings (B, S, D). |
required |
conditioning
|
Tensor | None
|
Conditioning vector for AdaNorm (B, C). Ignored by UnconditionedNorm. |
None
|
attention_mask
|
Tensor | None
|
Bool mask (B, 1, S, S), True = masked. |
None
|
positional_encoding
|
RotaryPositionalEncoding | None
|
Optional RoPE module. |
None
|
generation_cache
|
GenerationLayerCache | None
|
Cached K/V from previous autoregressive steps. When provided, an updated cache is returned. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, GenerationLayerCache | None]
|
Tuple of (output hidden states (B, S, D), updated GenerationLayerCache or None). |