pub struct Linear<T: WithDTypeF, B: Backend> { /* private fields */ }Expand description
A linear layer, x @ weight^T + bias.
The weight is treated as a model parameter: on the CPU, the gemm keeps it packed between calls instead of packing it on every call. Do not write it in place once the layer has run.
Each thread that runs part of the product keeps its own packed copy, and dropping the layer
does not release it: copies are held until their thread exits. GEMM_PACKED_LHS_CACHE_MB
caps what is held across the process (256 by default; past it, products pack per call as
before), and GEMM_PACKED_LHS_CACHE_MB=0 turns the cache off.
Implementations§
Source§impl<T: WithDTypeF, B: Backend> Linear<T, B>
impl<T: WithDTypeF, B: Backend> Linear<T, B>
pub fn new(weight: Tensor<T, B>) -> Self
pub fn weight(&self) -> &Tensor<T, B>
pub fn bias(&self) -> Option<&Tensor<T, B>>
pub fn with_bias(self, bias: Tensor<T, B>) -> Self
pub fn load<V: Borrow<Path<B>>>( vb: V, in_features: usize, out_features: usize, ) -> Result<Self>
pub fn load_b<V: Borrow<Path<B>>>( vb: V, in_features: usize, out_features: usize, ) -> Result<Self>
pub fn load_o<V: Borrow<Path<B>>>( vb: V, in_features: usize, out_features: usize, bias: bool, ) -> Result<Self>
pub fn forward<X: TensorOrView<T, B>>(&self, x: &X) -> Result<Tensor<T, B>>
pub fn device(&self) -> &B
Trait Implementations§
Auto Trait Implementations§
impl<T, B> Forget for Linear<T, B>
impl<T, B> Freeze for Linear<T, B>
impl<T, B> Move for Linear<T, B>
impl<T, B> RefUnwindSafe for Linear<T, B>
impl<T, B> Send for Linear<T, B>
impl<T, B> Sync for Linear<T, B>
impl<T, B> Unpin for Linear<T, B>
impl<T, B> UnsafeUnpin for Linear<T, B>
impl<T, B> UnwindSafe for Linear<T, B>
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more