Skip to main content

TransformerDecoderConfig

Struct TransformerDecoderConfig 

Source
pub struct TransformerDecoderConfig {
    pub d_model: usize,
    pub d_ff: usize,
    pub n_heads: usize,
    pub n_layers: usize,
    pub dropout: f64,
    pub norm_first: bool,
    pub quiet_softmax: bool,
    pub initializer: Initializer,
    pub activation: ActivationConfig,
    pub layer_norm_eps: f64,
}
Expand description

Configuration to create a Transformer Decoder layer using the init function.

Fields§

§d_model: usize

The size of the model.

§d_ff: usize

The size of the position-wise feed-forward network.

§n_heads: usize

The number of attention heads.

§n_layers: usize

The number of layers.

§dropout: f64

The dropout rate. Default: 0.1

§norm_first: bool

Layer norm will be applied first instead of after the other modules.

§quiet_softmax: bool

Use “quiet softmax” instead of regular softmax.

  • Usage may improve performance by allowing attention heads to deposit no information (if the sequence contains no information relevant to that head).
  • Usage may reduce the entropy of weights in the model, enhancing quantization and compression.

Reference: https://www.evanmiller.org/attention-is-off-by-one.html

§initializer: Initializer

The type of function used to initialize neural network parameters

§activation: ActivationConfig

The activation function used in the position-wise feed-forward network. Default: Gelu

§layer_norm_eps: f64

The epsilon value for layer normalization. Default: 1e-5

Implementations§

Source§

impl TransformerDecoderConfig

Source

pub fn new( d_model: usize, d_ff: usize, n_heads: usize, n_layers: usize, ) -> TransformerDecoderConfig

Create a new instance of the config.

§Arguments
§Required Arguments
§d_model

The size of the model.

§d_ff

The size of the position-wise feed-forward network.

§n_heads

The number of attention heads.

§n_layers

The number of layers.

§Default Arguments
§dropout

The dropout rate. Default: 0.1

  • Defaults to 0.1
§norm_first

Layer norm will be applied first instead of after the other modules.

  • Defaults to false
§quiet_softmax

Use “quiet softmax” instead of regular softmax.

  • Usage may improve performance by allowing attention heads to deposit no information (if the sequence contains no information relevant to that head).
  • Usage may reduce the entropy of weights in the model, enhancing quantization and compression.

Reference: https://www.evanmiller.org/attention-is-off-by-one.html

  • Defaults to false
§initializer

The type of function used to initialize neural network parameters

  • Defaults to "Initializer::KaimingUniform{gain:1.0/num_traits::Float::sqrt(3.0), fan_out_only:false}"
§activation

The activation function used in the position-wise feed-forward network. Default: Gelu

  • Defaults to "ActivationConfig::Gelu"
§layer_norm_eps

The epsilon value for layer normalization. Default: 1e-5

  • Defaults to 1e-5
Source§

impl TransformerDecoderConfig

Source

pub fn with_dropout(self, dropout: f64) -> TransformerDecoderConfig

Sets the value for the field dropout.

The dropout rate. Default: 0.1

  • Defaults to 0.1
Source

pub fn with_norm_first(self, norm_first: bool) -> TransformerDecoderConfig

Sets the value for the field norm_first.

Layer norm will be applied first instead of after the other modules.

  • Defaults to false
Source

pub fn with_quiet_softmax(self, quiet_softmax: bool) -> TransformerDecoderConfig

Sets the value for the field quiet_softmax.

Use “quiet softmax” instead of regular softmax.

  • Usage may improve performance by allowing attention heads to deposit no information (if the sequence contains no information relevant to that head).
  • Usage may reduce the entropy of weights in the model, enhancing quantization and compression.

Reference: https://www.evanmiller.org/attention-is-off-by-one.html

  • Defaults to false
Source

pub fn with_initializer( self, initializer: Initializer, ) -> TransformerDecoderConfig

Sets the value for the field initializer.

The type of function used to initialize neural network parameters

  • Defaults to "Initializer::KaimingUniform{gain:1.0/num_traits::Float::sqrt(3.0), fan_out_only:false}"
Source

pub fn with_activation( self, activation: ActivationConfig, ) -> TransformerDecoderConfig

Sets the value for the field activation.

The activation function used in the position-wise feed-forward network. Default: Gelu

  • Defaults to "ActivationConfig::Gelu"
Source

pub fn with_layer_norm_eps( self, layer_norm_eps: f64, ) -> TransformerDecoderConfig

Sets the value for the field layer_norm_eps.

The epsilon value for layer normalization. Default: 1e-5

  • Defaults to 1e-5
Source§

impl TransformerDecoderConfig

Source

pub fn init<B>( &self, device: &<B as BackendTypes>::Device, ) -> TransformerDecoder<B>
where B: Backend,

Initialize a new Transformer Decoder module.

Trait Implementations§

Source§

impl Clone for TransformerDecoderConfig

Source§

fn clone(&self) -> TransformerDecoderConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Config for TransformerDecoderConfig

Source§

fn save<P>(&self, file: P) -> Result<(), Error>
where P: AsRef<Path>,

Saves the configuration to a file. Read more
Source§

fn load<P>(file: P) -> Result<Self, ConfigError>
where P: AsRef<Path>,

Loads the configuration from a file. Read more
Source§

fn load_binary(data: &[u8]) -> Result<Self, ConfigError>

Loads the configuration from a binary buffer. Read more
Source§

impl Debug for TransformerDecoderConfig

Source§

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

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

impl<'de> Deserialize<'de> for TransformerDecoderConfig

Source§

fn deserialize<D>( deserializer: D, ) -> Result<TransformerDecoderConfig, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl Display for TransformerDecoderConfig

Source§

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

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

impl Serialize for TransformerDecoderConfig

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

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> 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> 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, 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,