pub struct DeterministicRng { /* private fields */ }Expand description
Deterministic, checkpointable PRNG for weight initialization and replay dropout.
Implementations§
Source§impl DeterministicRng
impl DeterministicRng
Sourcepub fn from_seed_u64(seed: u64) -> Self
pub fn from_seed_u64(seed: u64) -> Self
Constructs a PRNG deterministically from a 64-bit seed.
Sourcepub fn state(&self) -> RngState
pub fn state(&self) -> RngState
Captures the exact internal PRNG state for resumable checkpoints.
Sourcepub fn restore_state(&mut self, state: &RngState)
pub fn restore_state(&mut self, state: &RngState)
Restores a previously captured RngState.
Sourcepub fn sample_normal_vec(
&mut self,
len: usize,
mean: f32,
std: f32,
) -> Result<Vec<f32>, CodecError>
pub fn sample_normal_vec( &mut self, len: usize, mean: f32, std: f32, ) -> Result<Vec<f32>, CodecError>
Samples len i.i.d. normal values N(mean, std^2).
§Errors
Returns CodecError::InvalidConfig if std is negative or non-finite.
Sourcepub fn dropout_mask(
&mut self,
shape: &Shape,
drop_p: f32,
dtype: DType,
device: &Device,
) -> Result<Tensor, CodecError>
pub fn dropout_mask( &mut self, shape: &Shape, drop_p: f32, dtype: DType, device: &Device, ) -> Result<Tensor, CodecError>
Generates an inverted-dropout scaling mask of shape on device in dtype.
§Errors
Returns CodecError on invalid drop_p or tensor transfer failure.
Trait Implementations§
Source§impl Clone for DeterministicRng
impl Clone for DeterministicRng
Auto Trait Implementations§
impl Freeze for DeterministicRng
impl RefUnwindSafe for DeterministicRng
impl Send for DeterministicRng
impl Sync for DeterministicRng
impl Unpin for DeterministicRng
impl UnsafeUnpin for DeterministicRng
impl UnwindSafe for DeterministicRng
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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