pub struct SplitInto<T>(pub T);
Expand description
Splits input into multiple heads. T
should be a tuple,
where every element of the tuple accepts the same input type.
This provides a utility for multi headed structures where the tape needs to be moved around a number of times.
Each head’s operations will be stored in its output’s tape, while the operations stored in the input tape will be saved in the first output’s tape.
Generics
T
the module to split the input into.
Examples
type Model = SplitInto<(Linear<5, 3>, Linear<5, 7>)>;
let model = dev.build_module::<Model, f32>();
let _: (Tensor<Rank1<3>, f32, _>, Tensor<Rank1<7>, f32, _>) = model.forward(dev.zeros::<Rank1<5>>());
Tuple Fields§
§0: T
Trait Implementations§
source§impl<T: BuildOnDevice<D, E>, D: Device<E>, E: Dtype> BuildOnDevice<D, E> for SplitInto<T>
impl<T: BuildOnDevice<D, E>, D: Device<E>, E: Dtype> BuildOnDevice<D, E> for SplitInto<T>
source§impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B)>
impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B)>
source§impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C)>
impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C)>
source§impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>, D: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C, D)>
impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>, D: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C, D)>
source§impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>, D: Module<Input, Error = A::Error>, E: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C, D, E)>
impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>, D: Module<Input, Error = A::Error>, E: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C, D, E)>
§type Output = (<A as Module<Input>>::Output, <B as Module<Input>>::Output, <C as Module<Input>>::Output, <D as Module<Input>>::Output, <E as Module<Input>>::Output)
type Output = (<A as Module<Input>>::Output, <B as Module<Input>>::Output, <C as Module<Input>>::Output, <D as Module<Input>>::Output, <E as Module<Input>>::Output)
The type that this unit produces given
Input
.type Error = <A as Module<Input>>::Error
fn try_forward(&self, x: Input) -> Result<Self::Output, A::Error>
source§impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>, D: Module<Input, Error = A::Error>, E: Module<Input, Error = A::Error>, F: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C, D, E, F)>
impl<Input: WithEmptyTape, A: Module<Input>, B: Module<Input, Error = A::Error>, C: Module<Input, Error = A::Error>, D: Module<Input, Error = A::Error>, E: Module<Input, Error = A::Error>, F: Module<Input, Error = A::Error>> Module<Input> for SplitInto<(A, B, C, D, E, F)>
§type Output = (<A as Module<Input>>::Output, <B as Module<Input>>::Output, <C as Module<Input>>::Output, <D as Module<Input>>::Output, <E as Module<Input>>::Output, <F as Module<Input>>::Output)
type Output = (<A as Module<Input>>::Output, <B as Module<Input>>::Output, <C as Module<Input>>::Output, <D as Module<Input>>::Output, <E as Module<Input>>::Output, <F as Module<Input>>::Output)
The type that this unit produces given
Input
.type Error = <A as Module<Input>>::Error
fn try_forward(&self, x: Input) -> Result<Self::Output, A::Error>
source§impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B)>
impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B)>
§type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output)
type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output)
The type that this unit produces given
Input
.type Error = <A as ModuleMut<Input>>::Error
fn try_forward_mut(&mut self, x: Input) -> Result<Self::Output, A::Error>
source§fn forward_mut(&mut self, input: Input) -> Self::Output
fn forward_mut(&mut self, input: Input) -> Self::Output
source§impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C)>
impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C)>
§type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output)
type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output)
The type that this unit produces given
Input
.type Error = <A as ModuleMut<Input>>::Error
fn try_forward_mut(&mut self, x: Input) -> Result<Self::Output, A::Error>
source§fn forward_mut(&mut self, input: Input) -> Self::Output
fn forward_mut(&mut self, input: Input) -> Self::Output
source§impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>, D: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C, D)>
impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>, D: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C, D)>
§type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output, <D as ModuleMut<Input>>::Output)
type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output, <D as ModuleMut<Input>>::Output)
The type that this unit produces given
Input
.type Error = <A as ModuleMut<Input>>::Error
fn try_forward_mut(&mut self, x: Input) -> Result<Self::Output, A::Error>
source§fn forward_mut(&mut self, input: Input) -> Self::Output
fn forward_mut(&mut self, input: Input) -> Self::Output
source§impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>, D: ModuleMut<Input, Error = A::Error>, E: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C, D, E)>
impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>, D: ModuleMut<Input, Error = A::Error>, E: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C, D, E)>
§type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output, <D as ModuleMut<Input>>::Output, <E as ModuleMut<Input>>::Output)
type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output, <D as ModuleMut<Input>>::Output, <E as ModuleMut<Input>>::Output)
The type that this unit produces given
Input
.type Error = <A as ModuleMut<Input>>::Error
fn try_forward_mut(&mut self, x: Input) -> Result<Self::Output, A::Error>
source§fn forward_mut(&mut self, input: Input) -> Self::Output
fn forward_mut(&mut self, input: Input) -> Self::Output
source§impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>, D: ModuleMut<Input, Error = A::Error>, E: ModuleMut<Input, Error = A::Error>, F: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C, D, E, F)>
impl<Input: WithEmptyTape, A: ModuleMut<Input>, B: ModuleMut<Input, Error = A::Error>, C: ModuleMut<Input, Error = A::Error>, D: ModuleMut<Input, Error = A::Error>, E: ModuleMut<Input, Error = A::Error>, F: ModuleMut<Input, Error = A::Error>> ModuleMut<Input> for SplitInto<(A, B, C, D, E, F)>
§type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output, <D as ModuleMut<Input>>::Output, <E as ModuleMut<Input>>::Output, <F as ModuleMut<Input>>::Output)
type Output = (<A as ModuleMut<Input>>::Output, <B as ModuleMut<Input>>::Output, <C as ModuleMut<Input>>::Output, <D as ModuleMut<Input>>::Output, <E as ModuleMut<Input>>::Output, <F as ModuleMut<Input>>::Output)
The type that this unit produces given
Input
.type Error = <A as ModuleMut<Input>>::Error
fn try_forward_mut(&mut self, x: Input) -> Result<Self::Output, A::Error>
source§fn forward_mut(&mut self, input: Input) -> Self::Output
fn forward_mut(&mut self, input: Input) -> Self::Output
source§impl<E: Dtype, D: Device<E>, T: TensorCollection<E, D>> TensorCollection<E, D> for SplitInto<T>
impl<E: Dtype, D: Device<E>, T: TensorCollection<E, D>> TensorCollection<E, D> for SplitInto<T>
§type To<E2: Dtype, D2: Device<E2>> = SplitInto<<T as TensorCollection<E, D>>::To<E2, D2>>
type To<E2: Dtype, D2: Device<E2>> = SplitInto<<T as TensorCollection<E, D>>::To<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
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
Auto Trait Implementations§
impl<T> RefUnwindSafe for SplitInto<T>where T: RefUnwindSafe,
impl<T> Send for SplitInto<T>where T: Send,
impl<T> Sync for SplitInto<T>where T: Sync,
impl<T> Unpin for SplitInto<T>where T: Unpin,
impl<T> UnwindSafe for SplitInto<T>where T: UnwindSafe,
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<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, 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
.