pub struct Cpu { /* private fields */ }
Expand description
A device that stores data on the heap.
The Default impl seeds the underlying rng with seed of 0.
Use Cpu::seed_from_u64 to control what seed is used.
Implementations§
Trait Implementations§
source§impl Cache for Cpu
impl Cache for Cpu
source§fn try_disable_cache(&self) -> Result<(), Self::Err>
fn try_disable_cache(&self) -> Result<(), Self::Err>
Tries to disable the cache of the device. See Cache::disable_cache for
details of when this is useful.
source§fn try_empty_cache(&self) -> Result<(), Self::Err>
fn try_empty_cache(&self) -> Result<(), Self::Err>
Tries to empty the cache of the device. See Cache::empty_cache for
details of when this is useful.
source§fn enable_cache(&self)
fn enable_cache(&self)
Enables the cache of the device.
source§fn disable_cache(&self)
fn disable_cache(&self)
Disables the cache of the device. This will also empty the cache
if there are things in it. See Cache::empty_cache for
more information.
source§fn empty_cache(&self)
fn empty_cache(&self)
Empties the cache of the device. Read more
source§impl DeviceBuildExt for Cpu
impl DeviceBuildExt for Cpu
fn build_module<M: BuildOnDevice<Self, E>, E: Dtype>(&self) -> M::Builtwhere Self: Device<E>,
fn try_build_module<M: BuildOnDevice<Self, E>, E: Dtype>( &self ) -> Result<M::Built, Self::Err>where Self: Device<E>,
source§impl<E: Unit> OnesTensor<E> for Cpu
impl<E: Unit> OnesTensor<E> for Cpu
source§fn try_ones_like<S: HasShape>(
&self,
src: &S
) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
fn try_ones_like<S: HasShape>( &self, src: &S ) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
Fallible version of OnesTensor::ones_like
source§fn ones<S: ConstShape>(&self) -> Tensor<S, E, Self>
fn ones<S: ConstShape>(&self) -> Tensor<S, E, Self>
Creates a tensor filled with ones. Read more
source§fn try_ones<S: ConstShape>(&self) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_ones<S: ConstShape>(&self) -> Result<Tensor<S, E, Self>, Self::Err>
Fallible version of OnesTensor::ones
source§impl<E: Unit> SampleTensor<E> for Cpu
impl<E: Unit> SampleTensor<E> for Cpu
source§fn try_sample_like<S: HasShape, D: Distribution<E>>(
&self,
src: &S,
distr: D
) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
fn try_sample_like<S: HasShape, D: Distribution<E>>( &self, src: &S, distr: D ) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
Fallibly samples a tensor with a given shape from a given distribution.
source§fn try_fill_with_distr<D: Distribution<E>>(
&self,
storage: &mut Self::Vec,
distr: D
) -> Result<(), Self::Err>
fn try_fill_with_distr<D: Distribution<E>>( &self, storage: &mut Self::Vec, distr: D ) -> Result<(), Self::Err>
Fills tensor
Storage<E>
with data from a given distributionsource§fn sample<S: ConstShape, D: Distribution<E>>(
&self,
distr: D
) -> Tensor<S, E, Self>
fn sample<S: ConstShape, D: Distribution<E>>( &self, distr: D ) -> Tensor<S, E, Self>
Samples a const tensor from a given distribution.
source§fn try_sample<S: ConstShape, D: Distribution<E>>(
&self,
distr: D
) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_sample<S: ConstShape, D: Distribution<E>>( &self, distr: D ) -> Result<Tensor<S, E, Self>, Self::Err>
Fallibly samples a const tensor from a given distribution.
source§fn sample_like<S: HasShape, D: Distribution<E>>(
&self,
src: &S,
distr: D
) -> Tensor<S::Shape, E, Self>
fn sample_like<S: HasShape, D: Distribution<E>>( &self, src: &S, distr: D ) -> Tensor<S::Shape, E, Self>
Samples a tensor with a given shape from a given distribution.
source§impl<E: Unit> Storage<E> for Cpu
impl<E: Unit> Storage<E> for Cpu
source§impl Synchronize for Cpu
impl Synchronize for Cpu
source§fn try_synchronize(&self) -> Result<(), Self::Err>
fn try_synchronize(&self) -> Result<(), Self::Err>
Blocks until all work on device to complete. Useful for benchmarking.
source§fn synchronize(&self)
fn synchronize(&self)
Blocks until all work on device to complete. Useful for benchmarking.
source§impl<E: Unit> TensorFromVec<E> for Cpu
impl<E: Unit> TensorFromVec<E> for Cpu
source§impl<E: Unit, const M: usize, const N: usize, const O: usize> TensorToArray<(Const<M>, Const<N>, Const<O>), E> for Cpu
impl<E: Unit, const M: usize, const N: usize, const O: usize> TensorToArray<(Const<M>, Const<N>, Const<O>), E> for Cpu
source§impl<E: Unit, const M: usize, const N: usize, const O: usize, const P: usize> TensorToArray<(Const<M>, Const<N>, Const<O>, Const<P>), E> for Cpu
impl<E: Unit, const M: usize, const N: usize, const O: usize, const P: usize> TensorToArray<(Const<M>, Const<N>, Const<O>, Const<P>), E> for Cpu
source§impl<E: Unit> TriangleTensor<E> for Cpu
impl<E: Unit> TriangleTensor<E> for Cpu
source§fn try_upper_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
fn try_upper_tri_like<S: HasShape>( &self, src: &S, val: E, diagonal: impl Into<Option<isize>> ) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
Fallible version of TriangleTensor::upper_tri_like
source§fn try_lower_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
fn try_lower_tri_like<S: HasShape>( &self, src: &S, val: E, diagonal: impl Into<Option<isize>> ) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
Fallible version of TriangleTensor::lower_tri_like
source§fn upper_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S, E, Self>
fn upper_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S, E, Self>
Build a tensor containing the upper triangle part of each lowest 2D matrix
set to the given value, along the given diagonal. The other values will be
E::default()
. Read moresource§fn try_upper_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_upper_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Result<Tensor<S, E, Self>, Self::Err>
Fallible version of TriangleTensor::upper_tri
source§fn upper_tri_like<S: HasShape>(
&self,
src: &S,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S::Shape, E, Self>
fn upper_tri_like<S: HasShape>( &self, src: &S, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S::Shape, E, Self>
Build an upper triangular tensor with the given shape. See TriangleTensor::upper_tri.
source§fn lower_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Tensor<S, E, Self>
fn lower_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S, E, Self>
Build a tensor containing the lower triangle part of each lowest 2D matrix
set to the given value, along the given diagonal. The other values will be
E::default()
. Read moresource§fn try_lower_tri<S: ConstShape>(
&self,
val: E,
diagonal: impl Into<Option<isize>>
) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_lower_tri<S: ConstShape>( &self, val: E, diagonal: impl Into<Option<isize>> ) -> Result<Tensor<S, E, Self>, Self::Err>
Fallible version of TriangleTensor::lower_tri
source§impl<E: Unit> ZerosTensor<E> for Cpu
impl<E: Unit> ZerosTensor<E> for Cpu
source§fn try_zeros_like<S: HasShape>(
&self,
src: &S
) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
fn try_zeros_like<S: HasShape>( &self, src: &S ) -> Result<Tensor<S::Shape, E, Self>, Self::Err>
Fallible version of ZerosTensor::zeros_like
source§fn zeros<S: ConstShape>(&self) -> Tensor<S, E, Self>
fn zeros<S: ConstShape>(&self) -> Tensor<S, E, Self>
Creates a tensor filled with zeros. Read more
source§fn try_zeros<S: ConstShape>(&self) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_zeros<S: ConstShape>(&self) -> Result<Tensor<S, E, Self>, Self::Err>
Fallible version of ZerosTensor::zeros
impl Device<f32> for Cpu
impl Device<f64> for Cpu
Auto Trait Implementations§
impl RefUnwindSafe for Cpu
impl Send for Cpu
impl Sync for Cpu
impl Unpin for Cpu
impl UnwindSafe for Cpu
Blanket Implementations§
source§impl<E, D> Arange<E> for Dwhere
E: Dtype,
D: ZerosTensor<E> + TensorFromVec<E>,
impl<E, D> Arange<E> for Dwhere E: Dtype, D: ZerosTensor<E> + TensorFromVec<E>,
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<E, D> OneHotEncode<E> for Dwhere
E: Dtype,
D: Storage<E> + ZerosTensor<E> + TensorFromVec<E>,
impl<E, D> OneHotEncode<E> for Dwhere E: Dtype, D: Storage<E> + ZerosTensor<E> + TensorFromVec<E>,
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<E, const M: usize, D> TensorFrom<&[E; M], (Const<M>,), E> for Dwhere
E: Copy,
D: TensorFromVec<E>,
impl<E, const M: usize, D> TensorFrom<&[E; M], (Const<M>,), E> for Dwhere E: Copy, D: TensorFromVec<E>,
source§impl<E, const M: usize, const N: usize, const O: usize, const P: usize, D> TensorFrom<[[[[E; P]; O]; N]; M], (Const<M>, Const<N>, Const<O>, Const<P>), E> for Dwhere
E: Copy,
D: TensorFromVec<E>,
impl<E, const M: usize, const N: usize, const O: usize, const P: usize, D> TensorFrom<[[[[E; P]; O]; N]; M], (Const<M>, Const<N>, Const<O>, Const<P>), E> for Dwhere E: Copy, D: TensorFromVec<E>,
source§impl<E, const M: usize, const N: usize, const O: usize, D> TensorFrom<[[[E; O]; N]; M], (Const<M>, Const<N>, Const<O>), E> for Dwhere
E: Copy,
D: TensorFromVec<E>,
impl<E, const M: usize, const N: usize, const O: usize, D> TensorFrom<[[[E; O]; N]; M], (Const<M>, Const<N>, Const<O>), E> for Dwhere E: Copy, D: TensorFromVec<E>,
source§impl<E, const M: usize, const N: usize, D> TensorFrom<[[E; N]; M], (Const<M>, Const<N>), E> for Dwhere
E: Copy,
D: TensorFromVec<E>,
impl<E, const M: usize, const N: usize, D> TensorFrom<[[E; N]; M], (Const<M>, Const<N>), E> for Dwhere E: Copy, D: TensorFromVec<E>,
source§impl<E, const M: usize, D> TensorFrom<[E; M], (Const<M>,), E> for Dwhere
E: Copy,
D: TensorFromVec<E>,
impl<E, const M: usize, D> TensorFrom<[E; M], (Const<M>,), E> for Dwhere E: Copy, D: TensorFromVec<E>,
source§impl<E, S, D> TensorFrom<(Vec<E, Global>, S), S, E> for Dwhere
S: Shape,
D: TensorFromVec<E>,
impl<E, S, D> TensorFrom<(Vec<E, Global>, S), S, E> for Dwhere S: Shape, D: TensorFromVec<E>,
source§impl<E, D> TensorFrom<E, (), E> for Dwhere
D: TensorFromVec<E>,
impl<E, D> TensorFrom<E, (), E> for Dwhere D: TensorFromVec<E>,
source§impl<E, S, D> TensorFrom<Vec<E, Global>, S, E> for Dwhere
S: ConstShape,
D: TensorFromVec<E>,
impl<E, S, D> TensorFrom<Vec<E, Global>, S, E> for Dwhere S: ConstShape, D: TensorFromVec<E>,
source§impl<E, D> TryAttentionReshape<E> for Dwhere
E: Dtype,
D: AttentionReshapeKernel<E>,
impl<E, D> TryAttentionReshape<E> for Dwhere E: Dtype, D: AttentionReshapeKernel<E>,
source§fn try_attention_reshape<const THREE_HIDDEN_DIM: usize, const NUM_HEADS: usize, const HEAD_DIM: usize>(
&self,
qkv: &Tensor<(usize, Const<THREE_HIDDEN_DIM>), E, D, NoneTape>,
past_key: &Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, D, NoneTape>,
past_value: &Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, D, NoneTape>
) -> Result<(Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, D, NoneTape>, Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, D, NoneTape>, Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, D, NoneTape>), <D as HasErr>::Err>
fn try_attention_reshape<const THREE_HIDDEN_DIM: usize, const NUM_HEADS: usize, const HEAD_DIM: usize>( &self, qkv: &Tensor<(usize, Const<THREE_HIDDEN_DIM>), E, D, NoneTape>, past_key: &Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, D, NoneTape>, past_value: &Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, D, NoneTape> ) -> Result<(Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, D, NoneTape>, Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, D, NoneTape>, Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, D, NoneTape>), <D as HasErr>::Err>
Fallible version of TryAttentionReshape::attention_reshape
source§fn attention_reshape<const THREE_HIDDEN_DIM: usize, const NUM_HEADS: usize, const HEAD_DIM: usize>(
&self,
qkv: &Tensor<(usize, Const<THREE_HIDDEN_DIM>), E, Self>,
past_key: &Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, Self>,
past_value: &Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, Self>
) -> (Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, Self>, Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, Self>, Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, Self>)
fn attention_reshape<const THREE_HIDDEN_DIM: usize, const NUM_HEADS: usize, const HEAD_DIM: usize>( &self, qkv: &Tensor<(usize, Const<THREE_HIDDEN_DIM>), E, Self>, past_key: &Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, Self>, past_value: &Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, Self> ) -> (Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, Self>, Tensor<(Const<NUM_HEADS>, Const<HEAD_DIM>, usize), E, Self>, Tensor<(Const<NUM_HEADS>, usize, Const<HEAD_DIM>), E, Self>)
This is an inference only kernel:
Within
transformers
architecture, a core component is the attention
layer, which can be written in many forms. Read more