Layer

Enum Layer 

Source
pub enum Layer<B: Backend> {
Show 24 variants Attention(Attention<B>), Bias(Bias<B>), BatchNorm(BatchNorm<B>), Cache(Cache<B>), Cat(Ignored<CatLayer>), Conv2d(Conv2d<B>), CrossEntropy(CrossEntropyLoss<B>), Dropout(Dropout), Embedding(Embedding<B>), Flatten(Ignored<FlattenLayer<Range<isize>>>), KQV(KQV<B>), LayerNorm(LayerNorm<B>), Linear(Linear<B>), MaxPool2d(MaxPool2d), Mse(MseLoss), Relu(Relu), Reshape(Ignored<ReshapeLayer<Reshape>>), Rotary(RotaryEncoding<B>), ScaleShift(ScaleShift<B>), Squeeze(Ignored<SqueezeLayer>), Stack(Ignored<StackLayer>), Sum(Ignored<SumLayer>), Tanh(Tanh), Unsqueeze(Ignored<UnsqueezeLayer>),
}
Expand description

enumerates some burn layers

Variants§

§

Attention(Attention<B>)

§

Bias(Bias<B>)

§

BatchNorm(BatchNorm<B>)

§

Cache(Cache<B>)

§

Cat(Ignored<CatLayer>)

§

Conv2d(Conv2d<B>)

§

CrossEntropy(CrossEntropyLoss<B>)

§

Dropout(Dropout)

§

Embedding(Embedding<B>)

§

Flatten(Ignored<FlattenLayer<Range<isize>>>)

§

KQV(KQV<B>)

§

LayerNorm(LayerNorm<B>)

§

Linear(Linear<B>)

§

MaxPool2d(MaxPool2d)

§

Mse(MseLoss)

§

Relu(Relu)

§

Reshape(Ignored<ReshapeLayer<Reshape>>)

§

Rotary(RotaryEncoding<B>)

§

ScaleShift(ScaleShift<B>)

§

Squeeze(Ignored<SqueezeLayer>)

§

Stack(Ignored<StackLayer>)

§

Sum(Ignored<SumLayer>)

§

Tanh(Tanh)

§

Unsqueeze(Ignored<UnsqueezeLayer>)

Implementations§

Source§

impl<B: Backend> Layer<B>

Source

pub fn attention(heads: usize, mask: AttentionMask) -> Self

creates an attention config

Source

pub fn batch_norm(countfeatures: usize, epsilon: f32, momentum: f32) -> Self

creates a batch norm layer

Source

pub fn bias(dim: usize) -> Self

creates a bias config

Source

pub fn cache(limit: usize) -> Self

creates a cache layer

Source

pub fn clear_cache(&mut self) -> bool

clears the cache if the layer has one

Source

pub fn dropout(chance: f32) -> Self

creates a dropout layer

Source

pub fn embedding(input: usize, output: usize, wscale: f32) -> Self

creates a embedding layer

Source

pub fn flatten<R: RangeBounds<isize>>(dims: R) -> Self

creates a flatten layer

Source

pub fn layer_norm(dim: usize) -> Self

creates a layer norm layer

Source

pub fn linear(bias: bool, input: usize, output: usize, wscale: f32) -> Self

creates a linear layer

Source

pub fn max_pool_2d(kernel: [usize; 2], strides: [usize; 2]) -> Self

creates a max pool 2d layer

Source

pub fn relu() -> Self

creates a relu layer

Source

pub fn reshape<R: Into<Reshape>>(args: R) -> Self

creates a reshape layer

Source

pub fn rotary(distance: usize, head: usize) -> Self

creates a rotary layer

Source

pub fn scale_shift() -> Self

creates a scale shift layer

Source

pub fn tanh() -> Self

creates a tanh layer

Trait Implementations§

Source§

impl<B: Backend> AI<Value<B>, Value<B>> for Layer<B>

Source§

fn forward(&self, input: Value<B>) -> Value<B>

applies to the input
Source§

fn forward_mut(&mut self, input: Value<B>) -> Value<B>

applies to the input, possibly updating internal caches
Source§

impl<B> AutodiffModule<B> for Layer<B>

Source§

type InnerModule = Layer<<B as AutodiffBackend>::InnerBackend>

Inner module without auto-differentiation.
Source§

fn valid(&self) -> Self::InnerModule

Get the same module, but on the inner backend without auto-differentiation.
Source§

impl<B: Backend> Clone for Layer<B>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<B: Debug + Backend> Debug for Layer<B>

Source§

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

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

impl<B: Backend> Decompose for Layer<B>

Source§

type Decomposition = Layer<B>

the decomposed type
Source§

fn compose(decomposition: Self::Decomposition) -> Self

recreates from the decomposition
Source§

fn decompose(self) -> Self::Decomposition

owned decomposition
Source§

fn decompose_cloned(&self) -> Self::Decomposition

decomposition that copies data
Source§

impl<'de, B: Backend> Deserialize<'de> for Layer<B>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<B: Backend> Display for Layer<B>

Source§

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

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

impl<B: Backend> From<Attention<B>> for Layer<B>

Source§

fn from(value: Attention<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<BatchNorm<B>> for Layer<B>

Source§

fn from(value: BatchNorm<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<Cache<B>> for Layer<B>

Source§

fn from(value: Cache<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<CatLayer> for Layer<B>

Source§

fn from(value: CatLayer) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<CrossEntropyLoss<B>> for Layer<B>

Source§

fn from(value: CrossEntropyLoss<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<Dropout> for Layer<B>

Source§

fn from(value: Dropout) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<Embedding<B>> for Layer<B>

Source§

fn from(value: Embedding<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<FlattenLayer<Range<isize>>> for Layer<B>

Source§

fn from(value: FlattenLayer<Range<isize>>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<LayerNorm<B>> for Layer<B>

Source§

fn from(value: LayerNorm<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<Linear<B>> for Layer<B>

Source§

fn from(value: Linear<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<MaxPool2d> for Layer<B>

Source§

fn from(value: MaxPool2d) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<MseLoss> for Layer<B>

Source§

fn from(value: MseLoss) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<Relu> for Layer<B>

Source§

fn from(value: Relu) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<ReshapeLayer<Reshape>> for Layer<B>

Source§

fn from(value: ReshapeLayer<Reshape>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<RotaryEncoding<B>> for Layer<B>

Source§

fn from(value: RotaryEncoding<B>) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<SqueezeLayer> for Layer<B>

Source§

fn from(value: SqueezeLayer) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<StackLayer> for Layer<B>

Source§

fn from(value: StackLayer) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<SumLayer> for Layer<B>

Source§

fn from(value: SumLayer) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<Tanh> for Layer<B>

Source§

fn from(value: Tanh) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend> From<UnsqueezeLayer> for Layer<B>

Source§

fn from(value: UnsqueezeLayer) -> Self

Converts to this type from the input type.
Source§

impl<B: Backend, M: AI<M::Output, M::Output> + Op> IntoSequence<M> for Layer<B>
where Layer<B>: Into<M>,

Source§

fn into_sequence(self) -> Sequential<Vec<M>>

converts into a sequential module list
Source§

impl<B: Backend> Module<B> for Layer<B>

Source§

type Record = LayerRecord<B>

Type to save and load the module.
Source§

fn load_record(self, record: Self::Record) -> Self

Load the module state from a record.
Source§

fn into_record(self) -> Self::Record

Convert the module into a record containing the state.
Source§

fn num_params(&self) -> usize

Get the number of parameters the module has, including all of its sub-modules.
Source§

fn visit<Visitor: ModuleVisitor<B>>(&self, visitor: &mut Visitor)

Visit each tensor parameter in the module with a visitor.
Source§

fn map<Mapper: ModuleMapper<B>>(self, mapper: &mut Mapper) -> Self

Map each tensor parameter in the module with a mapper.
Source§

fn collect_devices(&self, devices: Devices<B>) -> Devices<B>

Return all the devices found in the underneath module tree added to the given vector without duplicates.
Source§

fn to_device(self, device: &B::Device) -> Self

Move the module and all of its sub-modules to the given device. Read more
Source§

fn fork(self, device: &B::Device) -> Self

Fork the module and all of its sub-modules to the given device. Read more
Source§

fn devices(&self) -> Vec<<B as Backend>::Device>

Return all the devices found in the underneath module tree without duplicates.
Source§

fn no_grad(self) -> Self

Each tensor in the module tree will not require grad. Read more
Source§

fn save_file<FR, PB>( self, file_path: PB, recorder: &FR, ) -> Result<(), RecorderError>
where FR: FileRecorder<B>, PB: Into<PathBuf>,

Save the module to a file using the provided file recorder. Read more
Source§

fn load_file<FR, PB>( self, file_path: PB, recorder: &FR, device: &<B as Backend>::Device, ) -> Result<Self, RecorderError>
where FR: FileRecorder<B>, PB: Into<PathBuf>,

Load the module from a file using the provided file recorder. Read more
Source§

fn quantize_weights(self, quantizer: &mut Quantizer) -> Self

Quantize the weights of the module.
Source§

impl<B: Backend> ModuleDisplay for Layer<B>

Source§

fn format(&self, passed_settings: DisplaySettings) -> String

Formats the module with provided display settings. Read more
Source§

fn custom_settings(&self) -> Option<DisplaySettings>

Custom display settings for the module. Read more
Source§

fn custom_content(&self, _content: Content) -> Option<Content>

Custom attributes for the module. Read more
Source§

impl<B: Backend> ModuleDisplayDefault for Layer<B>

Source§

fn content(&self, content: Content) -> Option<Content>

Attributes of the module used for display purposes. Read more
Source§

fn num_params(&self) -> usize

Gets the number of the parameters of the module.
Source§

impl<B: Backend> Op for Layer<B>

Source§

type Output = Value<B>

suggested output type to help with composition coherence. Ideally, Self should implement AI<X,Self::Output> for some X
Source§

fn abs(self) -> Abs<Self>
where Self: Sized, Abs<Self>: Op,

wraps with an absolute value operation
Source§

fn acc_q(self, gamma: f32) -> AccQ<Self>
where AccQ<Self>: Op, Self: Sized,

wraps with a accq operation
Source§

fn cat(self, dim: i32) -> Cat<Self>
where Cat<Self>: Op, Self: Sized,

wraps with a cat operation
Source§

fn chain<B>(self, b: B) -> Sequential<(Self, B)>
where Self: Sized, Sequential<(Self, B)>: Op,

sequences with another ai operation
Source§

fn cross_entropy(self, temperature: f32) -> CrossEntropy<Self>
where CrossEntropy<Self>: Op, Self: Sized,

wraps with a cross entropy operation. If temperature is a number it will be used to apply softmax to the logits before computing entropy with the target. if the input will already be a probability distribution instead of logits, put NaN temperature
Source§

fn duplicate(self) -> Duplicate<Self>
where Duplicate<Self>: Op, Self: Sized,

wraps with a duplicate operation
Source§

fn fix_type<Z>(self) -> SetType<Self, Z, Z>
where Self: AI<Z, Z> + Sized,

set type but with the same input and output
Source§

fn flatten<R: Clone>(self, args: R) -> Flatten<Self, R>
where Flatten<Self, R>: Op, Self: Sized,

wraps with a flatten layer
Source§

fn forward_fixed<Z>(&self, input: Z) -> Z
where Self: AI<Z, Z> + Sized,

applies to the input
Source§

fn forward_fixed_mut<Z>(&mut self, input: Z) -> Z
where Self: AI<Z, Z> + Sized,

applies to the input
Source§

fn forward_typed<W, Z>(&self, input: W) -> Z
where Self: AI<W, Z> + Sized,

applies to the input
Source§

fn forward_typed_mut<W, Z>(&mut self, input: W) -> Z
where Self: AI<W, Z> + Sized,

applies to the input, possibly updating internal caches
Source§

fn infer_autoregressive<X, Y>(self, input: X) -> Autoregression<Self, Y>
where Self: AI<X, Y> + AI<Y, Y> + Sized, Y: Clone,

creates an autoregressive inference
Source§

fn map<B>(self, b: B) -> Map<Sequential<(Self, B)>>
where Map<Sequential<(Self, B)>>: Op, Self: Sized, Sequential<(Self, B)>: Op,

applies the operation to every output
Source§

fn mean(self) -> Mean<Self>
where Mean<Self>: Op, Self: Sized,

wraps with a mean operation
Source§

fn optional(self) -> Option<Self>
where Self: Sized,

creates an optional operation
Source§

fn reshape<R: Clone>(self, args: R) -> Reshape<Self, R>
where Reshape<Self, R>: Op, Self: Sized,

wraps with a reshape layer
Source§

fn residual(self) -> Residual<Self>
where Residual<Self>: Op, Self: Sized,

wraps in a residual layer
Source§

fn set_type<W, Z>(self) -> SetType<Self, W, Z>
where Self: AI<W, Z> + Sized,

sets the input output types
Source§

fn soft_choose(self, temperature: f32) -> Choose<Self>
where Self: Sized, Choose<Self>: Op,

wraps with a choose operation
Source§

fn squared_error(self) -> SquaredError<Self>
where SquaredError<Self>: Op, Self: Sized,

wraps with a mse operation
Source§

fn squeeze(self, dim: i32) -> Squeeze<Self>
where Squeeze<Self>: Op, Self: Sized,

wraps with a squeeze operation
Source§

fn stack(self, dim: i32) -> Stack<Self>
where Stack<Self>: Op, Self: Sized,

wraps with a stack operation
Source§

fn to_each(self) -> Map<Self>
where Map<Self>: Op, Self: Sized,

wraps with a map operation
Source§

fn unsqueeze(self, dim: i32) -> Unsqueeze<Self>
where Unsqueeze<Self>: Op, Self: Sized,

wraps with a unsqueeze operation
Source§

fn sum(self) -> Sum<Self>
where Sum<Self>: Op, Self: Sized,

wraps with a sum operation
Source§

fn wrap_inner(self) -> Inner<Self>
where Self: Sized,

wraps the inner value so it can be unwrapped with unwrap inner
Source§

fn zip<B>(self, b: B) -> Zip<(Self, B)>
where Self: Sized, Zip<(Self, B)>: Op,

zips with another ai operation
Source§

impl<B: Backend> Serialize for Layer<B>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<B: Backend> Wrappable for Layer<B>

Source§

type B = B

Source§

type With<C: Backend> = Layer<C>

Auto Trait Implementations§

§

impl<B> !Freeze for Layer<B>

§

impl<B> !RefUnwindSafe for Layer<B>

§

impl<B> Send for Layer<B>

§

impl<B> !Sync for Layer<B>

§

impl<B> Unpin for Layer<B>

§

impl<B> !UnwindSafe for Layer<B>

Blanket Implementations§

Source§

impl<T> Adaptor<()> for T

Source§

fn adapt(&self)

Adapt the type to be passed to a metric.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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<T> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Shortcuts for T
where T: Op + ?Sized,

Source§

fn classification(self) -> Classification<Self>
where Classification<Self>: Op, Self: Sized,

wraps in a classification wrapper
Source§

fn regression(self) -> Regression<Self>
where Regression<Self>: Op, Self: Sized,

wraps in a regression wrapper
Source§

fn wrap(self) -> Wrapped<Self>
where Self: Wrappable,

wraps in a burn wrapper
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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<T> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,