beam
genlm.bytes.byte_lm.beam
BeamParams
dataclass
Parameters for byte-level beam summing algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
K
|
int
|
Beam width - maximum number of candidates to maintain. |
required |
prune_threshold
|
float
|
Probability threshold for pruning candidates. Candidates with probability below this are removed. Defaults to 0.0 |
0.0
|
verbose
|
bool
|
Whether to print the beam state at each step. Defaults to False |
False
|
eos_tokens
|
list[bytes]
|
List of tokens that should be treated as EOS. When configured, EOS tokens will terminate generation when sampled. Defaults to None |
None
|
heal
|
bool
|
Whether to enable adaptive token healing. Defaults to True |
True
|
heal_max_backoff
|
int
|
Maximum number of bytes to back off when healing. Defaults to None |
None
|
heal_max_splits
|
int
|
Maximum number of intra-suffix commits allowed during a single healing attempt. Defaults to None |
None
|
Source code in genlm/bytes/byte_lm/beam.py
ByteBeamState
Bases: StatefulByteLM
Represents the state of the beam during byte-level language modeling.
Tracks multiple candidate states and their probabilities, pruning low-probability candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
list[LazyTrieState]
|
List of candidate states to track |
required |
params
|
BeamParams
|
Parameters controlling beam search behavior |
required |
Source code in genlm/bytes/byte_lm/beam.py
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
initial(llm, params, trie_opts=None)
async
classmethod
Creates initial beam state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
StatefulTokenizedLM
|
Token-level language model to use. |
required |
params
|
BeamParams
|
Beam search parameters. |
required |
trie_opts
|
dict
|
Additional keyword arguments passed to AsyncTokenByteTrie.from_vocab. For example, {"max_batch_size": 100}. |
None
|
Returns:
| Type | Description |
|---|---|
ByteBeamState
|
Initial beam state. |
Source code in genlm/bytes/byte_lm/beam.py
logZ
cached
property
Estimate of the partition function (sum of weights) for current beam. This is the estimate of the prefix probability of the bytes consumed so far.
__lshift__(a)
async
Advances the beam state with a new byte.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
int
|
Byte to add to states. |
required |
Returns:
| Type | Description |
|---|---|
ByteBeamState
|
New beam state after processing the byte. |
Source code in genlm/bytes/byte_lm/beam.py
logp_next()
async
Computes log probabilities for the next byte across all beam candidates.
Returns:
| Type | Description |
|---|---|
LazyByteProbs
|
Log probabilities for next possible bytes. |
Source code in genlm/bytes/byte_lm/beam.py
extend(logZ)
async
Attempts to advance each candidate in the beam by a token (EOT).
For each candididate with EOT available, this ends the current token and starts a new one in preparation for the next byte.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logZ
|
float
|
Current estimated of the partition function for pruning |
required |
Returns:
| Type | Description |
|---|---|
list[LazyTrieState]
|
New candidate states after extension |
Source code in genlm/bytes/byte_lm/beam.py
prune()
Prunes beam to maintain beam width and probability threshold.
Returns:
| Type | Description |
|---|---|
ByteBeamState
|
New state with pruned candidates. |
Source code in genlm/bytes/byte_lm/beam.py
with_mode(mode)
Create a new beam state with specified trie mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
TrieMode
|
Trie mode for the new beam state |
required |
Returns:
| Type | Description |
|---|---|
ByteBeamState
|
New beam state with updated mode |
Source code in genlm/bytes/byte_lm/beam.py
prefill(bs)
async
Prefill the beam on a sequence of bytes.
During prefilling, EOS tokens are treated as normal tokens and don't cause termination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bs
|
bytes
|
Byte sequence to prefill on |
required |
Returns:
| Type | Description |
|---|---|
ByteBeamState
|
New beam state after prefilling |