pub struct RotaryPositionalEncoding {
pub dimensions: i32,
pub traditional: bool,
pub base: f32,
pub scale: f32,
}
Expand description
Implements the rotary positional encoding.
The traditional implementation rotates consecutive pairs of elements in the feature dimension while the default implementation rotates pairs with stride half the feature dimensions for efficiency.
For more details see RoFormer: Enhanced Transformer with Rotary Position Embedding (https://arxiv.org/abs/2104.09864)
Fields§
§dimensions: i32
The feature dimensions to be rotated. If the input feature is larger than dims then the rest is left unchanged
traditional: bool
If true
choose the traditional implementation which is slightly
less efficient
base: f32
The base used to compute angular frequency for each dimension in the positional encodings
scale: f32
scale used to scale the positions
Implementations§
Source§impl RotaryPositionalEncoding
impl RotaryPositionalEncoding
Sourcepub const DEFAULT_TRADITIONAL: bool = false
pub const DEFAULT_TRADITIONAL: bool = false
Default value for traditional
field.
Sourcepub const DEFAULT_BASE: f32 = 1.0E+4f32
pub const DEFAULT_BASE: f32 = 1.0E+4f32
Default value for base
field.
Sourcepub const DEFAULT_SCALE: f32 = 1f32
pub const DEFAULT_SCALE: f32 = 1f32
Default value for scale
field.
Trait Implementations§
Source§impl Buildable for RotaryPositionalEncoding
impl Buildable for RotaryPositionalEncoding
Source§type Builder = RotaryPositionalEncodingBuilder
type Builder = RotaryPositionalEncodingBuilder
Source§impl Builder<RotaryPositionalEncoding> for RotaryPositionalEncodingBuilder
impl Builder<RotaryPositionalEncoding> for RotaryPositionalEncodingBuilder
Source§type Error = Infallible
type Error = Infallible
Source§impl Clone for RotaryPositionalEncoding
impl Clone for RotaryPositionalEncoding
Source§fn clone(&self) -> RotaryPositionalEncoding
fn clone(&self) -> RotaryPositionalEncoding
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RotaryPositionalEncoding
impl Debug for RotaryPositionalEncoding
Source§impl<'a, Input> Module<Input> for RotaryPositionalEncoding
impl<'a, Input> Module<Input> for RotaryPositionalEncoding
Source§impl ModuleParameters for RotaryPositionalEncoding
impl ModuleParameters for RotaryPositionalEncoding
Source§fn freeze_parameters(&mut self, recursive: bool)
fn freeze_parameters(&mut self, recursive: bool)
Source§fn unfreeze_parameters(&mut self, recursive: bool)
fn unfreeze_parameters(&mut self, recursive: bool)
Source§fn parameters(&self) -> ModuleParamRef<'_>
fn parameters(&self) -> ModuleParamRef<'_>
Source§fn parameters_mut(&mut self) -> ModuleParamMut<'_>
fn parameters_mut(&mut self) -> ModuleParamMut<'_>
Source§fn trainable_parameters(&self) -> ModuleParamRef<'_>
fn trainable_parameters(&self) -> ModuleParamRef<'_>
Source§fn all_frozen(&self) -> Option<bool>
fn all_frozen(&self) -> Option<bool>
None
if there are no parameters.Source§fn any_frozen(&self) -> Option<bool>
fn any_frozen(&self) -> Option<bool>
None
if there are no parameters.Source§fn update(&mut self, parameters: ModuleParam)
fn update(&mut self, parameters: ModuleParam)
Source§fn update_flattened(&mut self, flattened_parameters: FlattenedModuleParam)
fn update_flattened(&mut self, flattened_parameters: FlattenedModuleParam)
Auto Trait Implementations§
impl Freeze for RotaryPositionalEncoding
impl RefUnwindSafe for RotaryPositionalEncoding
impl Send for RotaryPositionalEncoding
impl Sync for RotaryPositionalEncoding
impl Unpin for RotaryPositionalEncoding
impl UnwindSafe for RotaryPositionalEncoding
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
Source§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
Option
.Source§impl<T> IntoStrideBy for T
impl<T> IntoStrideBy for T
Source§impl<T> ModuleParametersExt for Twhere
T: ModuleParameters,
impl<T> ModuleParametersExt for Twhere
T: ModuleParameters,
Source§impl<T> Parameter for Twhere
T: ModuleParameters,
impl<T> Parameter for Twhere
T: ModuleParameters,
Source§fn is_frozen(&self) -> Option<bool>
fn is_frozen(&self) -> Option<bool>
None
if the parameter is a module that has no
parameters.