action_masking
action_masking
¶
Attention masking for models with bidirectional prefix and causal action tokens.
make_attention_mask
¶
make_attention_mask(action_tokens, feature_tokens, feature_token_mask=None, causal_actions=True, causal_prefix_suffix_length=0)
Compute attention mask with bidirectional prefix and configurable action masking.
The prefix is split into a bidirectional region and an optional causal suffix. Tokens in the causal suffix can see all earlier prefix tokens but earlier prefix tokens cannot see them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_tokens
|
Tensor
|
Action token embeddings (B, action_token_len, emb_dim) |
required |
feature_tokens
|
Tensor
|
Feature token embeddings (B, feat_token_len, emb_dim) |
required |
feature_token_mask
|
Tensor | None
|
Optional feature token mask (B, feat_token_len) where True indicates padded (masked) tokens. |
None
|
causal_actions
|
bool
|
If True, action tokens use causal (autoregressive) masking. If False, action tokens attend bidirectionally to each other. |
True
|
causal_prefix_suffix_length
|
int
|
Number of tokens at the end of the prefix that use causal masking. These tokens can attend to all earlier prefix tokens, but earlier tokens cannot attend to them. 0 disables (fully bidirectional prefix). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
full_padding_mask |
Tensor
|
Attention mask (B, 1, total_len, total_len) |
full_key_padding_mask |
Tensor
|
Key padding mask (B, total_len) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If token or mask shapes are inconsistent. |
Note: True indicates masked tokens, False indicates valid tokens.
Source code in src/versatil/models/decoding/action_masking.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |