dual_stream_decoder
dual_stream_decoder
¶
Dual-stream bidirectional transformer decoder that stacks dual stream transformer layers.
Provides positional encoding and final normalization for both streams processed through joint attention layers.
Note: this is the original architecture of the Multimodal Diffusion Transformer (MMDiT), but it's proposed here as a general-purpose dual-stream transformer decoder for multimodal sequence modeling.
References
Esser et al. "Scaling Rectified Flow Transformers for High-Resolution Image Synthesis" https://arxiv.org/abs/2403.03206
DualStreamBidirectionalDecoder
¶
DualStreamBidirectionalDecoder(number_of_layers, embedding_dimension, conditioning_dimension, number_of_heads, feedforward_dimension=None, dropout=0.1, attention_dropout=0.0, activation=value, normalization_type=value, normalization_epsilon=1e-06, use_query_key_norm=True, use_gating=True, positional_encoding_type=None, maximum_sequence_length_observation=1024, maximum_sequence_length_action=256, bias=True, initializer_range=0.02)
Bases: TransformerMixin, Module
Dual-stream bidirectional transformer decoder.
Stacks dual stream (multimodal) transformer layers with optional positional encodings and final normalization for both streams.
Initialize decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number_of_layers
|
int
|
Number of dual-stream attention layers. |
required |
embedding_dimension
|
int
|
Hidden dimension for both streams. |
required |
conditioning_dimension
|
int
|
Dimension of conditioning vector. |
required |
number_of_heads
|
int
|
Number of attention heads. |
required |
feedforward_dimension
|
int | None
|
FFN hidden dimension. |
None
|
dropout
|
float
|
Dropout rate for residual connections. |
0.1
|
attention_dropout
|
float
|
Dropout rate for attention weights. |
0.0
|
activation
|
str
|
Activation function for FFN. |
value
|
normalization_type
|
str
|
Normalization type. |
value
|
normalization_epsilon
|
float
|
Epsilon for normalization layers. |
1e-06
|
use_query_key_norm
|
bool
|
Whether to apply QK-normalization. |
True
|
use_gating
|
bool
|
Whether to use gating in adaptive normalization. |
True
|
positional_encoding_type
|
str | None
|
Type of positional encoding. |
None
|
maximum_sequence_length_observation
|
int
|
Max primary sequence length. |
1024
|
maximum_sequence_length_action
|
int
|
Max secondary sequence length. |
256
|
bias
|
bool
|
Whether to use bias in linear layers. |
True
|
initializer_range
|
float
|
Standard deviation for weight initialization. |
0.02
|
Source code in src/versatil/models/layers/transformer/dual_stream_decoder.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
forward
¶
forward(hidden_states_observation, hidden_states_action, conditioning, attention_mask_observation=None, attention_mask_action=None)
Forward pass through decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states_observation
|
Tensor
|
Primary stream tokens (B, S, D). |
required |
hidden_states_action
|
Tensor
|
Secondary stream tokens (B, T, D). |
required |
conditioning
|
Tensor
|
Conditioning vector (B, D). |
required |
attention_mask_observation
|
Tensor | None
|
Padding mask for primary (B, S). |
None
|
attention_mask_action
|
Tensor | None
|
Padding mask for secondary (B, T). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor]
|
Tuple of (primary_output, secondary_output) with same shapes. |