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:

  1. Module requires that the input tensor has a NoneTape. i.e. that gradients are not being tracked.
  2. ModuleMut requires that the tensor has a OwnedTape. i.e. that the gradients are being tracked

That means the following will fail to compile:

  1. Using Module with OwnedTape fails to compile
let dropout: DropoutOneIn<2> = BuildModule::build(&dev);
let grads = dropout.alloc_grads();
dropout.forward(dev.zeros::<Rank1<5>>().trace(grads));
  1. Using ModuleMut with NoneTape fails to compile
let mut dropout: DropoutOneIn<2> = Default::default();
dropout.forward_mut(dev.zeros::<Rank1<5>>());

Generics:

  • N: p is set as 1.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, 2.0, 2.0, 0.0, 0.0], [2.0, 2.0, 0.0, 0.0, 2.0]]);

Trait Implementations§

source§

impl<const N: usize> Clone for DropoutOneIn<N>

source§

fn clone(&self) -> DropoutOneIn<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const N: usize> Debug for DropoutOneIn<N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const N: usize> Default for DropoutOneIn<N>

source§

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>

§

type Error = <D as HasErr>::Err

Does nothing

§

type Output = Tensor<S, E, D, NoneTape>

The type that this unit produces given Input.
source§

fn try_forward( &self, input: Tensor<S, E, D, NoneTape> ) -> Result<Self::Output, D::Err>

source§

fn forward(&self, input: Input) -> Self::Output

Forward Input through the module and produce Module::Output. Read more
source§

impl<const N: usize, S: Shape, E: Dtype, D: Device<E>> ModuleMut<Tensor<S, E, D, OwnedTape<E, D>>> for DropoutOneIn<N>

source§

fn try_forward_mut( &mut self, input: Tensor<S, E, D, OwnedTape<E, D>> ) -> Result<Self::Output, D::Err>

Calls dropout() with p=1/N using self.rng.

§

type Output = Tensor<S, E, D, OwnedTape<E, D>>

The type that this unit produces given Input.
§

type Error = <D as HasErr>::Err

source§

fn forward_mut(&mut self, input: Input) -> Self::Output

Forward Input through the module and produce ModuleMut::Output. Read more
source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V