pub struct Sampler { /* private fields */ }Expand description
Draws tokens from a row of logits, carrying the sampling stream with it.
Gpt2::generate and friends sample internally; this is the same drawing
logic for callers that own the loop themselves, and it owns its RNG so no
caller has to name rand’s types.
let mut s = Sampler::new(1337);
let logits = vec![0.1f32, 2.0, 0.3];
let id = s.pick(&logits, Sampling::TopK { k: 2, temperature: 0.8, seed: 0 });Sampling::TopK’s own seed field is ignored here — the stream is this
sampler’s, seeded once at Sampler::new, so successive picks continue it
rather than restarting it.
Implementations§
Auto Trait Implementations§
impl Freeze for Sampler
impl RefUnwindSafe for Sampler
impl Send for Sampler
impl Sync for Sampler
impl Unpin for Sampler
impl UnsafeUnpin for Sampler
impl UnwindSafe for Sampler
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
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