feedforward
feedforward
¶
Feedforward block: norm -> FFN -> gated residual.
FeedforwardBlock
¶
Bases: TransformerBlock
Norm -> feedforward -> gated residual.
Source code in src/versatil/models/layers/transformer/block/feedforward.py
forward
¶
Norm -> feedforward -> 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
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Output hidden states (B, S, D). |
Source code in src/versatil/models/layers/transformer/block/feedforward.py
build_feedforward
¶
build_feedforward(embedding_dimension, feedforward_dimension, activation=value, dropout=0.1, bias=True)
Build a gated or standard feedforward layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dimension
|
int
|
Input and output dimension. |
required |
feedforward_dimension
|
int
|
Hidden dimension. |
required |
activation
|
str
|
Activation function name from ActivationFunction enum. |
value
|
dropout
|
float
|
Dropout rate. |
0.1
|
bias
|
bool
|
Whether to use bias in linear layers. |
True
|
Note
Sets SQUARE_ROOT_WEIGHT flag to true, for scaling the variance of residual connections.
Returns:
| Type | Description |
|---|---|
Sequential
|
Sequential with |