pub enum SamplingMode {
Greedy,
TopP {
p: Probability<f64>,
min_keep: NonZeroUsize,
},
TopK {
k: NonZeroUsize,
},
MinP {
p: Probability<f32>,
min_keep: NonZeroUsize,
},
TailFree {
z: Probability<f32>,
min_keep: NonZeroUsize,
},
LocallyTypical {
p: Probability<f32>,
min_keep: NonZeroUsize,
},
Mirostat {
tau: f32,
eta: f32,
max_keep: Option<NonZeroUsize>,
},
MirostatV2 {
tau: f32,
eta: f32,
max_keep: Option<NonZeroUsize>,
},
SplitP {
min_keep: NonZeroUsize,
max_keep: Option<NonZeroUsize>,
},
SplitL {
min_keep: NonZeroUsize,
max_keep: Option<NonZeroUsize>,
},
}Variants§
Greedy
Greedy sampling. The most likely next token is always chosen. Not very useful unless you want to regurgitate the training data.
TopP
Top-p sampling. A token is chosen from the top tokens whose cumulative
probability is greater than or equal to p.
Fields
p: Probability<f64>Reasonable values are between 0.9 and 0.95. Higher means more diversity, but potentially less coherent.
min_keep: NonZeroUsizeMinimum number of candidates to keep per token.
TopK
A token is chosen from the top k tokens. This is not very good.
Fields
k: NonZeroUsizeThe top k tokens are kept. Reasonable values are between 30 and
40.
MinP
Min-p sampling. p sets the minimum probability to keep a token. Below
that the tail is cut off. p is scaled by the top token’s probability
to balance diversity and quality.
It is described in detail in the following pull request: https://github.com/ggerganov/llama.cpp/pull/3841
Fields
p: Probability<f32>The minimum probability to keep a token. This is scaled by the top token’s probability. Reasonable values are 0.05 to 0.3. Higher means less diversity.
min_keep: NonZeroUsizeTailFree
Tail free sampling.
“TFS first converts logits output by a model into probabilities using the softmax function before sorting them in descending order. It then calculates the first and second derivatives. As the tokens are discrete, this can be found with subtraction. The magnitude of each second derivative is then taken and normalized so that they sum to 1. Finally, a threshold z is used to determine what part of the cumulative distribution of the second derivative weights to define the “tail” of the distribution to be at.”
Fields
z: Probability<f32>Reasonable values are between 0.25 and 0.75. The higher, the more diverse the output, but also potentially less coherent.
min_keep: NonZeroUsizeMinimum number of candidates to keep per token.
LocallyTypical
Locally typical sampling.
“First, we compute the conditional entropy, which is an O(|V|)
operation. Second, we sort words by their absolute distance from H(pb(·|
Y <t = y<t)), which can be done in O(|V| log |V|) time with standard
sorting algorithms. Finally, we greedily take words from this list until
their cumulative probability exceeds the threshold p , which again
takes O(|V|) time. Thus, creating our altered distribution has time
complexity O(|V| log |V|).”
Fields
p: Probability<f32>Probability. Reasonable values are between 0.2 and 0.95. For story generation, lower is better. For summarization, higher is better.
min_keep: NonZeroUsizeMinimum number of candidates to keep per token.
Mirostat
Mirostat sampling.
“a neural text decoding algorithm that directly controls the perplexity of the generated text over a wide range of text length. Notably, for longer texts and certain ranges of input parameters, top-k and top-p sampling fall into boredom and confusion traps which cause low-quality texts; Mirostat avoids both traps.”
Fields
tau: f32Tau. Target entropy. A good value is 3.0 according to this paper: https://arxiv.org/pdf/2202.00666.pdf
llama.cpp uses a default of 5.0.
max_keep: Option<NonZeroUsize>Maximum number of candidates to keep. In the original paper and code
the default is 100 and the name is m.
MirostatV2
Mirostat V.2 sampling.
“Here we provide an alternate algorithm for perplexity control, Alg. 2, which does not depend on the distribution of the underlying LM. In this sense, Alg. 2 controls perplexity in more general sequential generative models than Alg. 1 where the underlying distribution may not be Zipfian. In our work, we choose Alg. 1 since it has only an additional constant time complexity compared to top-k sampling. Whereas Alg. 2 has additional time complexity that depends on target cross-entropy rate and vocabulary size, which may vary with different LMs.”
§Note:
- The bit about time complexity is not relevant to this implementation since we truncate the candidates to a fixed size like v1.
Fields
tau: f32Tau. Target entropy. A good value is 3.0 according to the paper and HF’s experiments in https://arxiv.org/pdf/2202.00666.pdf
llama.cpp uses a default of 5.0.
max_keep: Option<NonZeroUsize>Maximum number of candidates to keep. Defaults to 100. The original implementation does not support this. If identical behavior is desired, set this to the vocabulary size.
SplitP
Split P sampling. This cuts the tail off where the difference between adjacent probabilities is greatest, where the slope is steepest.
Fields
min_keep: NonZeroUsizeMinimum number of candidates to keep.
max_keep: Option<NonZeroUsize>Maximum number of candidates to keep.
SplitL
Split L sampling. This cuts the tail off where the difference between adjacent logits is greatest, where the slope is steepest.
Fields
min_keep: NonZeroUsizeMinimum number of candidates to keep.
max_keep: Option<NonZeroUsize>Maximum number of candidates to keep.
Implementations§
Source§impl SamplingMode
impl SamplingMode
pub const ALL: [Self; 10]
Sourcepub const fn help(&self) -> &'static str
pub const fn help(&self) -> &'static str
A help message for the sampling mode (but not it’s parameters)
Sourcepub const fn locally_typical() -> Self
pub const fn locally_typical() -> Self
Default locally typical sampling: p = 0.5 with no minimum keep.
Sourcepub const fn mirostat() -> Self
pub const fn mirostat() -> Self
Default mirostat sampling: tau = 3.0, eta = 0.1, max_keep = 100.
Sourcepub const fn mirostat_v2() -> Self
pub const fn mirostat_v2() -> Self
Default mirostat v2 sampling: tau = 3.0, eta = 0.1, max_keep = 100.
Sourcepub fn draw_inner(&mut self, ui: &mut Ui) -> Response
pub fn draw_inner(&mut self, ui: &mut Ui) -> Response
Draw egui::Ui, but without the outer collapsible header.
Trait Implementations§
Source§impl Clone for SamplingMode
impl Clone for SamplingMode
Source§fn clone(&self) -> SamplingMode
fn clone(&self) -> SamplingMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SamplingMode
impl Debug for SamplingMode
Source§impl Default for SamplingMode
impl Default for SamplingMode
Source§impl<'de> Deserialize<'de> for SamplingMode
impl<'de> Deserialize<'de> for SamplingMode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SamplingMode
impl PartialEq for SamplingMode
Source§impl Serialize for SamplingMode
impl Serialize for SamplingMode
impl StructuralPartialEq for SamplingMode
Auto Trait Implementations§
impl Freeze for SamplingMode
impl RefUnwindSafe for SamplingMode
impl Send for SamplingMode
impl Sync for SamplingMode
impl Unpin for SamplingMode
impl UnsafeUnpin for SamplingMode
impl UnwindSafe for SamplingMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().