Struct dfdx::nn::modules::DropoutOneIn
source · pub struct DropoutOneIn<const N: usize>;
Expand description
Does nothing as a Module, and calls dropout() as ModuleMut with probability 1.0 / N
.
To prevent programmer error, Module and ModuleMut are only implemented for specific tapes:
- Module requires that the input tensor has a NoneTape. i.e. that gradients are not being tracked.
- ModuleMut requires that the tensor has a OwnedTape. i.e. that the gradients are being tracked
That means the following will fail to compile:
ⓘ
let dropout: DropoutOneIn<2> = BuildModule::build(&dev);
let grads = dropout.alloc_grads();
dropout.forward(dev.zeros::<Rank1<5>>().trace(grads));
ⓘ
let mut dropout: DropoutOneIn<2> = Default::default();
dropout.forward_mut(dev.zeros::<Rank1<5>>());
Generics:
N
: p is set as1.0 / N
Examples:
let mut dropout: DropoutOneIn<2> = Default::default();
let grads = dropout.alloc_grads();
let x: Tensor<Rank2<2, 5>, f32, _> = dev.ones();
let r = dropout.forward_mut(x.trace(grads));
assert_eq!(r.array(), [[2.0, 0.0, 2.0, 0.0, 2.0], [0.0, 2.0, 0.0, 2.0, 2.0]]);
Trait Implementations§
source§impl<const N: usize> Clone for DropoutOneIn<N>
impl<const N: usize> Clone for DropoutOneIn<N>
source§fn clone(&self) -> DropoutOneIn<N>
fn clone(&self) -> DropoutOneIn<N>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<const N: usize> Debug for DropoutOneIn<N>
impl<const N: usize> Debug for DropoutOneIn<N>
source§impl<const N: usize> Default for DropoutOneIn<N>
impl<const N: usize> Default for DropoutOneIn<N>
source§fn default() -> DropoutOneIn<N>
fn default() -> DropoutOneIn<N>
Returns the “default value” for a type. Read more
source§impl<const N: usize, S: Shape, E: Dtype, D: Device<E>> Module<Tensor<S, E, D, NoneTape>> for DropoutOneIn<N>
impl<const N: usize, S: Shape, E: Dtype, D: Device<E>> Module<Tensor<S, E, D, NoneTape>> for DropoutOneIn<N>
source§impl<const N: usize, S: Shape, E: Dtype, D: Device<E>> ModuleMut<Tensor<S, E, D, OwnedTape<E, D>>> for DropoutOneIn<N>
impl<const N: usize, S: Shape, E: Dtype, D: Device<E>> ModuleMut<Tensor<S, E, D, OwnedTape<E, D>>> for DropoutOneIn<N>
impl<const N: usize> ZeroSizedModule for DropoutOneIn<N>
Auto Trait Implementations§
impl<const N: usize> RefUnwindSafe for DropoutOneIn<N>
impl<const N: usize> Send for DropoutOneIn<N>
impl<const N: usize> Sync for DropoutOneIn<N>
impl<const N: usize> Unpin for DropoutOneIn<N>
impl<const N: usize> UnwindSafe for DropoutOneIn<N>
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
source§impl<D, E, M> BuildModule<D, E> for Mwhere
D: Device<E>,
E: Dtype,
M: TensorCollection<E, D, To<E, D> = M>,
impl<D, E, M> BuildModule<D, E> for Mwhere D: Device<E>, E: Dtype, M: TensorCollection<E, D, To<E, D> = M>,
source§impl<T, D, E> BuildOnDevice<D, E> for Twhere
T: ZeroSizedModule + BuildModule<D, E>,
D: Device<E>,
E: Dtype,
impl<T, D, E> BuildOnDevice<D, E> for Twhere T: ZeroSizedModule + BuildModule<D, E>, D: Device<E>, E: Dtype,
source§impl<E, D, T> LoadFromNpz<E, D> for Twhere
E: Dtype + NumpyDtype,
D: Device<E>,
T: TensorCollection<E, D>,
impl<E, D, T> LoadFromNpz<E, D> for Twhere E: Dtype + NumpyDtype, D: Device<E>, T: TensorCollection<E, D>,
source§impl<E, D, T> LoadFromSafetensors<E, D> for Twhere
E: Dtype + SafeDtype,
D: Device<E>,
T: TensorCollection<E, D>,
impl<E, D, T> LoadFromSafetensors<E, D> for Twhere E: Dtype + SafeDtype, D: Device<E>, T: TensorCollection<E, D>,
source§impl<E, D, M> NumParams<E, D> for Mwhere
E: Dtype,
D: Device<E>,
M: TensorCollection<E, D>,
impl<E, D, M> NumParams<E, D> for Mwhere E: Dtype, D: Device<E>, M: TensorCollection<E, D>,
source§fn num_trainable_params(&self) -> usize
fn num_trainable_params(&self) -> usize
Returns the number of trainable params in any model.
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<E, D, M> ResetParams<E, D> for Mwhere
E: Dtype,
D: Device<E>,
M: TensorCollection<E, D>,
impl<E, D, M> ResetParams<E, D> for Mwhere E: Dtype, D: Device<E>, M: TensorCollection<E, D>,
source§fn reset_params(&mut self)
fn reset_params(&mut self)
Reset all a model’s parameters.
source§impl<E, D, T> SaveToNpz<E, D> for Twhere
E: Dtype + NumpyDtype,
D: Device<E>,
T: TensorCollection<E, D>,
impl<E, D, T> SaveToNpz<E, D> for Twhere E: Dtype + NumpyDtype, D: Device<E>, T: TensorCollection<E, D>,
source§impl<E, D, T> SaveToSafetensors<E, D> for Twhere
E: Dtype + SafeDtype,
D: Device<E>,
T: TensorCollection<E, D>,
impl<E, D, T> SaveToSafetensors<E, D> for Twhere E: Dtype + SafeDtype, D: Device<E>, T: TensorCollection<E, D>,
source§fn save_safetensors<P: AsRef<Path>>(
&self,
path: P
) -> Result<(), SafeTensorError>
fn save_safetensors<P: AsRef<Path>>( &self, path: P ) -> Result<(), SafeTensorError>
source§impl<E, D, T> TensorCollection<E, D> for Twhere
E: Dtype,
D: Device<E>,
T: ZeroSizedModule,
impl<E, D, T> TensorCollection<E, D> for Twhere E: Dtype, D: Device<E>, T: ZeroSizedModule,
§type To<E2: Dtype, D2: Device<E2>> = T
type To<E2: Dtype, D2: Device<E2>> = T
Type alias that specifies the how a module’s type changes when using a different dtype and/or
device.
source§fn iter_tensors<V>(
visitor: &mut V
) -> Result<Option<<T as TensorCollection<E, D>>::To<<V as ModuleVisitor<T, E, D>>::E2, <V as ModuleVisitor<T, E, D>>::D2>>, <V as ModuleVisitor<T, E, D>>::Err>where
V: ModuleVisitor<T, E, D>,
fn iter_tensors<V>( visitor: &mut V ) -> Result<Option<<T as TensorCollection<E, D>>::To<<V as ModuleVisitor<T, E, D>>::E2, <V as ModuleVisitor<T, E, D>>::D2>>, <V as ModuleVisitor<T, E, D>>::Err>where V: ModuleVisitor<T, E, D>,
Specifies how to iterate through tensors or modules containted within this module, and how
to contruct this module given values for its fields. Returns
Err(_)
to indicate an error,
Ok(None)
to indicate that there is no error and a module has not been built, and
Ok(Some(_))
contains Self::Output<E2, D2>
source§fn module<F1, F2, Field>(
name: &str,
get_ref: F1,
get_mut: F2
) -> ModuleField<'_, F1, F2, Self, Field>where
F1: FnMut(&Self) -> &Field,
F2: FnMut(&mut Self) -> &mut Field,
Field: TensorCollection<E, D>,
fn module<F1, F2, Field>( name: &str, get_ref: F1, get_mut: F2 ) -> ModuleField<'_, F1, F2, Self, Field>where F1: FnMut(&Self) -> &Field, F2: FnMut(&mut Self) -> &mut Field, Field: TensorCollection<E, D>,
Creates a ModuleFields that represents a field that may contain one or more tensors. Read more
source§fn tensor<F1, F2, S>(
name: &str,
get_ref: F1,
get_mut: F2,
options: TensorOptions<S, E, D>
) -> TensorField<'_, F1, F2, Self, S, E, D>where
F1: FnMut(&Self) -> &Tensor<S, E, D>,
F2: FnMut(&mut Self) -> &mut Tensor<S, E, D>,
S: Shape,
fn tensor<F1, F2, S>( name: &str, get_ref: F1, get_mut: F2, options: TensorOptions<S, E, D> ) -> TensorField<'_, F1, F2, Self, S, E, D>where F1: FnMut(&Self) -> &Tensor<S, E, D>, F2: FnMut(&mut Self) -> &mut Tensor<S, E, D>, S: Shape,
Creates a ModuleFields that represents a tensor field. Read more
source§fn scalar<F1, F2, N>(
name: &str,
get_ref: F1,
get_mut: F2,
options: ScalarOptions<N>
) -> ScalarField<'_, F1, F2, Self, N>where
F1: FnMut(&Self) -> &N,
F2: FnMut(&mut Self) -> &mut N,
N: NumCast,
fn scalar<F1, F2, N>( name: &str, get_ref: F1, get_mut: F2, options: ScalarOptions<N> ) -> ScalarField<'_, F1, F2, Self, N>where F1: FnMut(&Self) -> &N, F2: FnMut(&mut Self) -> &mut N, N: NumCast,
Creates a ModuleFields that represents a scalar field. Read more
source§impl<E, D1, D2, T> ToDevice<E, D1, D2> for Twhere
E: Dtype,
D1: Device<E>,
D2: Device<E>,
T: TensorCollection<E, D1>,
impl<E, D1, D2, T> ToDevice<E, D1, D2> for Twhere E: Dtype, D1: Device<E>, D2: Device<E>, T: TensorCollection<E, D1>,
source§impl<E1, D, T> ToDtype<E1, D> for Twhere
E1: Dtype,
D: Device<E1>,
T: TensorCollection<E1, D>,
impl<E1, D, T> ToDtype<E1, D> for Twhere E1: Dtype, D: Device<E1>, T: TensorCollection<E1, D>,
source§impl<E, D, M> ZeroGrads<E, D> for Mwhere
E: Dtype,
D: Device<E>,
M: TensorCollection<E, D>,
impl<E, D, M> ZeroGrads<E, D> for Mwhere E: Dtype, D: Device<E>, M: TensorCollection<E, D>,
source§fn alloc_grads(&self) -> Gradients<E, D>
fn alloc_grads(&self) -> Gradients<E, D>
Allocates gradients for this tensor collection. This marks all other
gradients as temporary, so they are dropped after .backward()
source§fn try_alloc_grads(&self) -> Result<Gradients<E, D>, D::Err>
fn try_alloc_grads(&self) -> Result<Gradients<E, D>, D::Err>
Allocates gradients for this tensor collection. This marks all other
gradients as temporary, so they are dropped after .backward()
source§fn zero_grads(&self, gradients: &mut Gradients<E, D>)
fn zero_grads(&self, gradients: &mut Gradients<E, D>)
Zero’s any gradients associated with
self
.