Struct dfdx::tensor::Cpu

source ·
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§

source§

impl Cpu

source

pub fn seed_from_u64(seed: u64) -> Self

Constructs rng with the given seed.

Trait Implementations§

source§

impl Cache for Cpu

source§

fn try_enable_cache(&self) -> Result<(), Self::Err>

Tries to enable the cache of the device.
source§

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>

Tries to empty the cache of the device. See Cache::empty_cache for details of when this is useful.
source§

fn enable_cache(&self)

Enables the cache of the device.
source§

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)

Empties the cache of the device. Read more
source§

impl Clone for Cpu

source§

fn clone(&self) -> Cpu

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<E: Unit> CopySlice<E> for Cpu

source§

fn copy_from<S: Shape, T>(dst: &mut Tensor<S, E, Self, T>, src: &[E])

source§

fn copy_into<S: Shape, T>(src: &Tensor<S, E, Self, T>, dst: &mut [E])

source§

impl Debug for Cpu

source§

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

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

impl Default for Cpu

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl DeviceBuildExt for Cpu

source§

fn build_module<M: BuildOnDevice<Self, E>, E: Dtype>(&self) -> M::Builtwhere Self: Device<E>,

source§

fn try_build_module<M: BuildOnDevice<Self, E>, E: Dtype>( &self ) -> Result<M::Built, Self::Err>where Self: Device<E>,

source§

impl HasErr for Cpu

source§

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>

Fallible version of OnesTensor::ones_like
source§

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>

Fallible version of OnesTensor::ones
source§

fn ones_like<S: HasShape>(&self, src: &S) -> Tensor<S::Shape, E, Self>

Build the tensor with a shape given by something else. Read more
source§

impl RandomU64 for Cpu

source§

fn random_u64(&self) -> u64

Generates a random u64 number
source§

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>

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>

Fills tensor Storage<E> with data from a given distribution
source§

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>

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>

Samples a tensor with a given shape from a given distribution.
source§

impl<E: Unit> Storage<E> for Cpu

§

type Vec = CachableVec<E>

Generic Storage type
source§

fn try_alloc_len(&self, len: usize) -> Result<Self::Vec, Self::Err>

source§

fn len(&self, v: &Self::Vec) -> usize

source§

fn tensor_to_vec<S: Shape, T>(&self, tensor: &Tensor<S, E, Self, T>) -> Vec<E>

source§

fn try_alloc_grad(&self, storage: &Self::Vec) -> Result<Self::Vec, Self::Err>

Allocates a gradient for the given nd array
source§

impl Synchronize for Cpu

source§

fn try_synchronize(&self) -> Result<(), Self::Err>

Blocks until all work on device to complete. Useful for benchmarking.
source§

fn synchronize(&self)

Blocks until all work on device to complete. Useful for benchmarking.
source§

impl<E: Unit> TensorFromVec<E> for Cpu

source§

fn try_tensor_from_vec<S: Shape>( &self, src: Vec<E>, shape: S ) -> Result<Tensor<S, E, Self>, Self::Err>

source§

fn tensor_from_vec<S: Shape>(&self, src: Vec<E>, shape: S) -> Tensor<S, E, Self>

source§

impl<E: Unit> TensorToArray<(), E> for Cpu

§

type Array = E

source§

fn tensor_to_array<T>(&self, tensor: &Tensor<Rank0, E, Self, T>) -> Self::Array

source§

impl<E: Unit, const M: usize> TensorToArray<(Const<M>,), E> for Cpu

§

type Array = [E; M]

source§

fn tensor_to_array<T>( &self, tensor: &Tensor<Rank1<M>, E, Self, T> ) -> Self::Array

source§

impl<E: Unit, const M: usize, const N: usize> TensorToArray<(Const<M>, Const<N>), E> for Cpu

§

type Array = [[E; N]; M]

source§

fn tensor_to_array<T>( &self, tensor: &Tensor<Rank2<M, N>, E, Self, T> ) -> Self::Array

source§

impl<E: Unit, const M: usize, const N: usize, const O: usize> TensorToArray<(Const<M>, Const<N>, Const<O>), E> for Cpu

§

type Array = [[[E; O]; N]; M]

source§

fn tensor_to_array<T>( &self, tensor: &Tensor<Rank3<M, N, O>, E, Self, T> ) -> Self::Array

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

§

type Array = [[[[E; P]; O]; N]; M]

source§

fn tensor_to_array<T>( &self, tensor: &Tensor<Rank4<M, N, O, P>, E, Self, T> ) -> Self::Array

source§

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>

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>

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>

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 more
source§

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>

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>

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 more
source§

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§

fn lower_tri_like<S: HasShape>( &self, src: &S, val: E, diagonal: impl Into<Option<isize>> ) -> Tensor<S::Shape, E, Self>

Build a lower triangular tensor with the given shape. See TriangleTensor::lower_tri.
source§

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>

Fallible version of ZerosTensor::zeros_like
source§

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>

Fallible version of ZerosTensor::zeros
source§

fn zeros_like<S: HasShape>(&self, src: &S) -> Tensor<S::Shape, E, Self>

Build the tensor with a shape given by something else. Read more
source§

impl Device<f32> for Cpu

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<E, D> Arange<E> for Dwhere E: Dtype, D: ZerosTensor<E> + TensorFromVec<E>,

source§

fn arange<Size: Dim>(&self, n: Size) -> Tensor<(Size,), E, Self>

Generates a tensor with ordered data from 0 to N. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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<E, D> OneHotEncode<E> for Dwhere E: Dtype, D: Storage<E> + ZerosTensor<E> + TensorFromVec<E>,

source§

fn one_hot_encode<Lbls: Array<usize>, N: Dim>( &self, n: N, labels: Lbls ) -> Tensor<(Lbls::Dim, N), E, Self>

One hot encodes an array or vec into a tensor. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<E, const M: usize, D> TensorFrom<&[E; M], (Const<M>,), E> for Dwhere E: Copy, D: TensorFromVec<E>,

source§

fn try_tensor( &self, src: &[E; M] ) -> Result<Tensor<(Const<M>,), E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
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>,

source§

fn try_tensor( &self, src: [[[[E; P]; O]; N]; M] ) -> Result<Tensor<(Const<M>, Const<N>, Const<O>, Const<P>), E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
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>,

source§

fn try_tensor( &self, src: [[[E; O]; N]; M] ) -> Result<Tensor<(Const<M>, Const<N>, Const<O>), E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
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>,

source§

fn try_tensor( &self, src: [[E; N]; M] ) -> Result<Tensor<(Const<M>, Const<N>), E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
source§

impl<E, const M: usize, D> TensorFrom<[E; M], (Const<M>,), E> for Dwhere E: Copy, D: TensorFromVec<E>,

source§

fn try_tensor( &self, src: [E; M] ) -> Result<Tensor<(Const<M>,), E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
source§

impl<E, S, D> TensorFrom<(Vec<E, Global>, S), S, E> for Dwhere S: Shape, D: TensorFromVec<E>,

source§

fn try_tensor( &self, _: (Vec<E, Global>, S) ) -> Result<Tensor<S, E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
source§

impl<E, D> TensorFrom<E, (), E> for Dwhere D: TensorFromVec<E>,

source§

fn try_tensor( &self, src: E ) -> Result<Tensor<(), E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
source§

impl<E, S, D> TensorFrom<Vec<E, Global>, S, E> for Dwhere S: ConstShape, D: TensorFromVec<E>,

source§

fn try_tensor( &self, src: Vec<E, Global> ) -> Result<Tensor<S, E, D, NoneTape>, <D as HasErr>::Err>

Fallible version of TensorFrom::tensor
source§

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data Read more
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<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>

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>)

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
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
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.
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