Struct dfdx::nn::modules::UnbiasedLinear
source · pub struct UnbiasedLinear<const I: usize, const O: usize, E: Dtype, D: DeviceStorage> {
pub weight: Tensor<Rank2<O, I>, E, D>,
}
Expand description
A linear transformation of the form weight * x
, where weight
is a matrix, x
is a vector or matrix.
Initializes Self::weight from a Uniform distribution between [-1 / sqrt(I), 1 / sqrt(I)].
Generics
I
The “input” size of vectors & matrices.O
The “output” size of vectors & matrices.
Examples
UnbiasedLinear<5, 2>
can act on vectors with 5 elements, and results in vectors with 2 elements.
type Model = UnbiasedLinear<5, 2>;
let model = dev.build_module::<Model, f32>();
// single item forward
let _: Tensor<Rank1<2>, f32, _> = model.forward(dev.zeros::<Rank1<5>>());
// batched forward
let _: Tensor<Rank2<10, 2>, f32, _> = model.forward(dev.zeros::<Rank2<10, 5>>());
Fields§
§weight: Tensor<Rank2<O, I>, E, D>
Transposed weight matrix, shape (I, O)
Trait Implementations§
source§impl<const I: usize, const O: usize, E: Clone + Dtype, D: Clone + DeviceStorage> Clone for UnbiasedLinear<I, O, E, D>
impl<const I: usize, const O: usize, E: Clone + Dtype, D: Clone + DeviceStorage> Clone for UnbiasedLinear<I, O, E, D>
source§fn clone(&self) -> UnbiasedLinear<I, O, E, D>
fn clone(&self) -> UnbiasedLinear<I, O, E, D>
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 I: usize, const O: usize, E: Debug + Dtype, D: Debug + DeviceStorage> Debug for UnbiasedLinear<I, O, E, D>
impl<const I: usize, const O: usize, E: Debug + Dtype, D: Debug + DeviceStorage> Debug for UnbiasedLinear<I, O, E, D>
source§impl<const I: usize, const O: usize, E: Dtype, D: Device<E>, T> Module<T> for UnbiasedLinear<I, O, E, D>where
T: SplitTape + TryMatMul<Tensor<Rank2<I, O>, E, D, T::Tape>> + HasErr<Err = D::Err>,
T::Tape: Tape<E, D>,
impl<const I: usize, const O: usize, E: Dtype, D: Device<E>, T> Module<T> for UnbiasedLinear<I, O, E, D>where T: SplitTape + TryMatMul<Tensor<Rank2<I, O>, E, D, T::Tape>> + HasErr<Err = D::Err>, T::Tape: Tape<E, D>,
source§impl<const I: usize, const O: usize, E: Dtype + Float + SampleUniform, D: Device<E>> TensorCollection<E, D> for UnbiasedLinear<I, O, E, D>
impl<const I: usize, const O: usize, E: Dtype + Float + SampleUniform, D: Device<E>> TensorCollection<E, D> for UnbiasedLinear<I, O, E, D>
§type To<E2: Dtype, D2: Device<E2>> = UnbiasedLinear<I, O, E2, D2>
type To<E2: Dtype, D2: Device<E2>> = UnbiasedLinear<I, O, E2, D2>
Type alias that specifies the how a module’s type changes when using a different dtype and/or
device.
source§fn iter_tensors<V: ModuleVisitor<Self, E, D>>(
visitor: &mut V
) -> Result<Option<Self::To<V::E2, V::D2>>, V::Err>
fn iter_tensors<V: ModuleVisitor<Self, E, D>>( visitor: &mut V ) -> Result<Option<Self::To<V::E2, V::D2>>, V::Err>
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