pub struct BeamSearchEngine {
pub config: BeamSearchConfig,
}Expand description
Beam search engine.
Decoupled from the model via a get_logits closure so it can be used
with any inference backend.
Fields§
§config: BeamSearchConfigSearch configuration.
Implementations§
Source§impl BeamSearchEngine
impl BeamSearchEngine
Sourcepub fn new(config: BeamSearchConfig) -> Self
pub fn new(config: BeamSearchConfig) -> Self
Create a new engine with the given configuration.
Sourcepub fn search<F>(
&self,
initial_tokens: Vec<u32>,
_vocab_size: usize,
get_logits: F,
) -> BeamSearchResult
pub fn search<F>( &self, initial_tokens: Vec<u32>, _vocab_size: usize, get_logits: F, ) -> BeamSearchResult
Run beam search.
get_logits(beam_tokens, step) is called for every live beam at every
step and must return a logit vector of length vocab_size.
Sourcepub fn apply_no_repeat_ngram(
logits: &mut [f32],
tokens: &[u32],
ngram_size: usize,
)
pub fn apply_no_repeat_ngram( logits: &mut [f32], tokens: &[u32], ngram_size: usize, )
Zero out (set to −∞) any token that would create a repeated n-gram.
For each position in tokens where the last ngram_size - 1 tokens
match the trailing ngram_size - 1 tokens of the current sequence,
the following token is forbidden.
Auto Trait Implementations§
impl Freeze for BeamSearchEngine
impl RefUnwindSafe for BeamSearchEngine
impl Send for BeamSearchEngine
impl Sync for BeamSearchEngine
impl Unpin for BeamSearchEngine
impl UnsafeUnpin for BeamSearchEngine
impl UnwindSafe for BeamSearchEngine
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> 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>
Converts
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>
Converts
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 more