Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::MLPConfig Class Referenceexport

Configuration class for the Multi-Layer Perceptron (MLP) block. More...

Inheritance diagram for Mila::Dnn::MLPConfig:
Mila::Dnn::ComponentConfig

Public Member Functions

 MLPConfig (dim_t input_features, dim_t hidden_size)
 Construct MLP configuration.
void fromMetadata (const SerializationMetadata &meta) override
 Populate configuration from provided metadata.
ActivationType getActivationType () const noexcept
 Get the configured activation function type.
dim_t getHiddenSize () const noexcept
 Get the hidden layer size.
dim_t getInputFeatures () const noexcept
 Get the configured number of input (and output) features.
bool hasBias () const noexcept
 Query whether linear layers include bias terms.
SerializationMetadata toMetadata () const override
 Convert configuration into SerializationMetadata.
std::string toString () const override
 Produce a short, human-readable summary of the configuration.
void validate () const override
 Validate configuration parameters.
template<typename Self>
decltype(auto) withActivation (this Self &&self, ActivationType activation)
 Set the activation function type (C++23 fluent style).
template<typename Self>
Self && withBias (this Self &&self, bool has_bias)
 Configure whether the linear layers use bias.
Public Member Functions inherited from Mila::Dnn::ComponentConfig
virtual ~ComponentConfig ()=default
 Virtual destructor for polymorphic base.

Detailed Description

Configuration class for the Multi-Layer Perceptron (MLP) block.

MLPConfig specifies the architectural parameters for an MLP block:

  • Input and hidden feature dimensions
  • Activation function type
  • Optional bias and layer normalization

The MLP block structure is: Input -> Linear(in_features, hidden_size) -> [LayerNorm] -> Activation -> Linear(hidden_size, in_features) -> Output

Constructor & Destructor Documentation

◆ MLPConfig()

Mila::Dnn::MLPConfig::MLPConfig ( dim_t input_features,
dim_t hidden_size )
inline

Construct MLP configuration.

Parameters
input_featuresNumber of input (and output) features (must be > 0).
hidden_sizeSize of the intermediate hidden layer (must be > 0).

Member Function Documentation

◆ fromMetadata()

void Mila::Dnn::MLPConfig::fromMetadata ( const SerializationMetadata & meta)
inlineoverridevirtual

Populate configuration from provided metadata.

Missing keys are ignored. Type-safe try-get helpers are used to avoid throwing on absent fields and to preserve forward/backward compatibility.

Parameters
metaMetadata to read configuration values from.

Implements Mila::Dnn::ComponentConfig.

◆ getActivationType()

ActivationType Mila::Dnn::MLPConfig::getActivationType ( ) const
inlinenoexcept

Get the configured activation function type.

Returns
ActivationType selected for the MLP.

◆ getHiddenSize()

dim_t Mila::Dnn::MLPConfig::getHiddenSize ( ) const
inlinenoexcept

Get the hidden layer size.

Returns
Hidden layer dimension.

◆ getInputFeatures()

dim_t Mila::Dnn::MLPConfig::getInputFeatures ( ) const
inlinenoexcept

Get the configured number of input (and output) features.

Returns
Number of input features.

◆ hasBias()

bool Mila::Dnn::MLPConfig::hasBias ( ) const
inlinenoexcept

Query whether linear layers include bias terms.

Returns
True if bias is enabled.

◆ toMetadata()

SerializationMetadata Mila::Dnn::MLPConfig::toMetadata ( ) const
inlineoverridevirtual

Convert configuration into SerializationMetadata.

Produces keys:

  • "input_features" : integer
  • "hidden_size" : integer
  • "has_bias" : boolean
  • "activation" : integer (ActivationType)
Returns
SerializationMetadata Metadata representing this configuration.

Implements Mila::Dnn::ComponentConfig.

◆ toString()

std::string Mila::Dnn::MLPConfig::toString ( ) const
inlineoverridevirtual

Produce a short, human-readable summary of the configuration.

Implementations should return a compact, single-line description suitable for logging and debugging.

Returns
std::string Human-readable summary of the configuration.

Implements Mila::Dnn::ComponentConfig.

◆ validate()

void Mila::Dnn::MLPConfig::validate ( ) const
inlineoverridevirtual

Validate configuration parameters.

Exceptions
std::invalid_argumentIf validation fails (e.g. zero-sized dimensions).

Implements Mila::Dnn::ComponentConfig.

◆ withBias()

template<typename Self>
Self && Mila::Dnn::MLPConfig::withBias ( this Self && self,
bool has_bias )
inline

Configure whether the linear layers use bias.

Parameters
has_biasTrue to include bias terms in linear layers, false to omit.
Returns
Self forwarding reference for method chaining.

The documentation for this class was generated from the following file: