Struct PositionWiseFeedForward
pub struct PositionWiseFeedForward<B>where
B: Backend,{
pub linear_inner: Linear<B>,
pub linear_outer: Linear<B>,
pub dropout: Dropout,
pub activation: Activation<B>,
}Expand description
Applies the position-wise feed-forward network to the input tensor from the paper Attention Is All You Need.
§Params
- linear inner: Linear layer with
d_modelinput features andd_ffoutput features. - linear outer: Linear layer with
d_ffinput features andd_modeloutput features.
FFN(x) = max(0, xW1 + b1)W2 + b2
Should be created using PositionWiseFeedForwardConfig
§Notes
The activation field is currently marked #[module(skip)] for backward
compatibility with records saved before this field was introduced (when
the activation was always Gelu and had no state). This means activation
state is not persisted when saving or loading records.
For stateless activations (GELU, ReLU, etc.) this has no effect.
If you are using SwiGLU, its learnable parameters will not be saved or
loaded correctly.
Fields§
§linear_inner: Linear<B>Linear layer with d_model input features and d_ff output features.
linear_outer: Linear<B>Linear layer with d_ff input features and d_model output features.
dropout: DropoutDropout layer.
activation: Activation<B>Activation function.
Implementations§
Trait Implementations§
§impl<B> AutodiffModule<B> for PositionWiseFeedForward<B>
impl<B> AutodiffModule<B> for PositionWiseFeedForward<B>
§type InnerModule = PositionWiseFeedForward<<B as AutodiffBackend>::InnerBackend>
type InnerModule = PositionWiseFeedForward<<B as AutodiffBackend>::InnerBackend>
§fn valid(
&self,
) -> <PositionWiseFeedForward<B> as AutodiffModule<B>>::InnerModule
fn valid( &self, ) -> <PositionWiseFeedForward<B> as AutodiffModule<B>>::InnerModule
§fn from_inner(
module: <PositionWiseFeedForward<B> as AutodiffModule<B>>::InnerModule,
) -> PositionWiseFeedForward<B>
fn from_inner( module: <PositionWiseFeedForward<B> as AutodiffModule<B>>::InnerModule, ) -> PositionWiseFeedForward<B>
§impl<B> Clone for PositionWiseFeedForward<B>where
B: Backend,
impl<B> Clone for PositionWiseFeedForward<B>where
B: Backend,
§fn clone(&self) -> PositionWiseFeedForward<B>
fn clone(&self) -> PositionWiseFeedForward<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<B> Debug for PositionWiseFeedForward<B>
impl<B> Debug for PositionWiseFeedForward<B>
§impl<B> Display for PositionWiseFeedForward<B>where
B: Backend,
impl<B> Display for PositionWiseFeedForward<B>where
B: Backend,
§impl<B> HasAutodiffModule<B> for PositionWiseFeedForward<<B as AutodiffBackend>::InnerBackend>
impl<B> HasAutodiffModule<B> for PositionWiseFeedForward<<B as AutodiffBackend>::InnerBackend>
§type TrainModule = PositionWiseFeedForward<B>
type TrainModule = PositionWiseFeedForward<B>
§impl<B> Module<B> for PositionWiseFeedForward<B>where
B: Backend,
impl<B> Module<B> for PositionWiseFeedForward<B>where
B: Backend,
§type Record = PositionWiseFeedForwardRecord<B>
type Record = PositionWiseFeedForwardRecord<B>
§fn load_record(
self,
record: <PositionWiseFeedForward<B> as Module<B>>::Record,
) -> PositionWiseFeedForward<B>
fn load_record( self, record: <PositionWiseFeedForward<B> as Module<B>>::Record, ) -> PositionWiseFeedForward<B>
§fn into_record(self) -> <PositionWiseFeedForward<B> as Module<B>>::Record
fn into_record(self) -> <PositionWiseFeedForward<B> as Module<B>>::Record
§fn num_params(&self) -> usize
fn num_params(&self) -> usize
§fn visit<Visitor>(&self, visitor: &mut Visitor)where
Visitor: ModuleVisitor<B>,
fn visit<Visitor>(&self, visitor: &mut Visitor)where
Visitor: ModuleVisitor<B>,
§fn map<Mapper>(self, mapper: &mut Mapper) -> PositionWiseFeedForward<B>where
Mapper: ModuleMapper<B>,
fn map<Mapper>(self, mapper: &mut Mapper) -> PositionWiseFeedForward<B>where
Mapper: ModuleMapper<B>,
§fn collect_devices(
&self,
devices: Vec<<B as BackendTypes>::Device>,
) -> Vec<<B as BackendTypes>::Device>
fn collect_devices( &self, devices: Vec<<B as BackendTypes>::Device>, ) -> Vec<<B as BackendTypes>::Device>
§fn to_device(
self,
device: &<B as BackendTypes>::Device,
) -> PositionWiseFeedForward<B>
fn to_device( self, device: &<B as BackendTypes>::Device, ) -> PositionWiseFeedForward<B>
§fn fork(
self,
device: &<B as BackendTypes>::Device,
) -> PositionWiseFeedForward<B>
fn fork( self, device: &<B as BackendTypes>::Device, ) -> PositionWiseFeedForward<B>
§fn devices(&self) -> Vec<<B as BackendTypes>::Device>
fn devices(&self) -> Vec<<B as BackendTypes>::Device>
§fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
§fn save_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
) -> Result<(), RecorderError>
fn save_file<FR, PB>( self, file_path: PB, recorder: &FR, ) -> Result<(), RecorderError>
§fn load_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
device: &<B as BackendTypes>::Device,
) -> Result<Self, RecorderError>
fn load_file<FR, PB>( self, file_path: PB, recorder: &FR, device: &<B as BackendTypes>::Device, ) -> Result<Self, RecorderError>
§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
§impl<B> ModuleDisplay for PositionWiseFeedForward<B>where
B: Backend,
impl<B> ModuleDisplay for PositionWiseFeedForward<B>where
B: Backend,
§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
§fn custom_content(&self, content: Content) -> Option<Content>
fn custom_content(&self, content: Content) -> Option<Content>
§fn format(&self, passed_settings: DisplaySettings) -> String
fn format(&self, passed_settings: DisplaySettings) -> String
§impl<B> ModuleDisplayDefault for PositionWiseFeedForward<B>where
B: Backend,
impl<B> ModuleDisplayDefault for PositionWiseFeedForward<B>where
B: Backend,
Auto Trait Implementations§
impl<B> !Freeze for PositionWiseFeedForward<B>
impl<B> !RefUnwindSafe for PositionWiseFeedForward<B>
impl<B> Send for PositionWiseFeedForward<B>
impl<B> Sync for PositionWiseFeedForward<B>
impl<B> Unpin for PositionWiseFeedForward<B>where
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
<B as BackendTypes>::Device: Unpin,
impl<B> !UnwindSafe for PositionWiseFeedForward<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
§impl<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more