Samplers
BeamSearchSampler
Beam Search sampling algorithm.
Attributes:
Name | Type | Description |
---|---|---|
samples |
The number of samples taken for each input sequence. Equivalent to the number of beams. |
Source code in outlines/samplers.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
__call__(next_token_logits, sequence_weights, _)
Call the beam search sampler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
next_token_logits
|
DoubleTensor
|
A tensor of shape |
required |
sequence_weights
|
DoubleTensor
|
A tensor of shape |
required |
rng
|
A random number generator. |
required |
Returns:
Type | Description |
---|---|
A tuple with an array that contains the ids of the sampled tokens of
|
|
shape ``(n_seqs, 1)``, an array that contains the ancestors of each
|
|
sampled id of shape ``(n_seqs,)`` and an array that contains the updated
|
|
cumulative weights of each sequence of shape ``(n_seqs,)``.
|
|
Source code in outlines/samplers.py
GreedySampler
Greedy Sampling algorithm.
Greedy sampling consists in choosing the token with the largest likelihood at every step.
We don't allow more than one sample. We could attribute this a meaning, for instance the k-th sample represents the k-th most likely token. In which case it would be equivalent to beam search without the sequence weights.
Attributes:
Name | Type | Description |
---|---|---|
samples |
The number of samples taken for each input sequence. |
Source code in outlines/samplers.py
__call__(next_token_logits, sequence_weights, _)
Call the greedy sampler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
next_token_logits
|
DoubleTensor
|
A tensor of shape |
required |
sequence_weights
|
DoubleTensor
|
A tensor of shape |
required |
rng
|
A random number generator. |
required |
Returns:
Type | Description |
---|---|
A tuple with an array that contains the ids of the sampled tokens of
|
|
shape ``(n_seqs, 1)``, an array that contains the ancestors of each
|
|
sampled id of shape ``(n_seqs,)`` and an array that contains the updated
|
|
cumulative weights of each sequence of shape ``(n_seqs,)``.
|
|
Source code in outlines/samplers.py
MultinomialSampler
Multinomial sampling algorithm.
Multinomial sampling consists in randomly sampling the next token assuming its distribution is a Categorical distribution parametrized by the next-token logits.
Attributes:
Name | Type | Description |
---|---|---|
samples |
The number of samples taken for each input sequence. |
Source code in outlines/samplers.py
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 |
|
__call__(next_token_logits, sequence_weights, rng)
Call the multinomial sampler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
next_token_logits
|
DoubleTensor
|
A tensor of shape |
required |
sequence_weights
|
DoubleTensor
|
A tensor of shape |
required |
rng
|
Generator
|
A random number generator. |
required |
Returns:
Type | Description |
---|---|
A tuple with an array that contains the ids of the sampled tokens of
|
|
shape ``(n_seqs, 1)``, an array that contains the ancestors of each
|
|
sampled id of shape ``(n_seqs,)`` and an array that contains the updated
|
|
cumulative weights of each sequence of shape ``(n_seqs,)``.
|
|
Source code in outlines/samplers.py
SamplingParameters
dataclass
Sampling parameters available in Outlines.
Source code in outlines/samplers.py
keep_top_k_logits(k)
Build a function that masks logits values smaller than the top k
ones.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k
|
int
|
The ranking below which logit values are replaced by |
required |
Source code in outlines/samplers.py
keep_top_p_logits(p)
Build a function that masks the lowest probability tokens whose cumulative probability is below a certain threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p
|
float
|
The value of the threshold. We keep the highest probability tokens whose
cumulative distribution is greater than or equal to |
required |
Source code in outlines/samplers.py
rescale_logits(temperature)
Build a function that rescales the token probabilities exponentially.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
temperature
|
float
|
The value by which we rescale the logits. |
required |