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
|
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
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 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 |
|
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. |