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

Configuration class for MLP block. More...

Inheritance diagram for Mila::Dnn::MLPConfig:
Collaboration diagram for Mila::Dnn::MLPConfig:

Public Member Functions

 MLPConfig (const std::vector< size_t > &input_shape, size_t hidden_size)
 Constructor with required parameters.
 
 MLPConfig (size_t input_features, size_t hidden_size)
 Alternative constructor with direct input features specification.
 
ActivationType getActivationType () const
 
float getDropout () const
 
size_t getHiddenSize () const
 
size_t getInputFeatures () const
 
const std::vector< size_t > & getInputShape () const
 
bool hasBias () const
 
bool useFusedOperations () const
 
bool useLayerNorm () const
 
bool useResidual () const
 
void validate () const
 Validate configuration parameters.
 
MLPConfigwithActivation (ActivationType activation)
 Set the activation function type.
 
MLPConfigwithBias (bool has_bias)
 Configure whether the linear layers use bias.
 
MLPConfigwithDropout (float dropout)
 Set the dropout rate.
 
MLPConfigwithFusedOperations (bool fuse_ops)
 Configure whether to fuse operations for inference.
 
MLPConfigwithLayerNorm (bool use_layer_norm)
 Configure whether to use layer normalization.
 
MLPConfigwithResidual (bool use_residual)
 Configure whether to use a residual connection.
 
- Public Member Functions inherited from Mila::Dnn::ComponentConfig
virtual ~ComponentConfig ()=default
 Virtual destructor to support proper polymorphic destruction.
 
const std::string & getName () const
 Gets the configured component name.
 
ComputePrecision::Policy getPrecision () const
 Gets the configured precision policy.
 
bool isTraining () const
 Gets the configured training mode.
 
template<typename Self >
auto & withName (this Self &&self, std::string name)
 Sets the name of the component with fluent interface.
 
template<typename Self >
auto & withPrecision (this Self &&self, ComputePrecision::Policy policy)
 Sets the compute precision policy with fluent interface.
 
template<typename Self >
auto & withTraining (this Self &&self, bool is_training)
 Sets the training mode with fluent interface.
 

Private Attributes

ActivationType activation_type_ { ActivationType::Gelu}
 
float dropout_ { 0.0f }
 
bool fuse_operations_ { false }
 
bool has_bias_ { true }
 
size_t hidden_size_ { 0 }
 
size_t input_features_ { 0 }
 
std::vector< size_t > input_shape_
 
bool use_layer_norm_ { false }
 
bool use_residual_ { false }
 

Additional Inherited Members

- Protected Attributes inherited from Mila::Dnn::ComponentConfig
bool is_training_ = false
 Training mode flag, defaults to false (inference mode)
 
std::string name_ = "unnamed"
 Component name, defaults to "unnamed" if not explicitly set.
 
ComputePrecision::Policy precision_ = ComputePrecision::Policy::Auto
 Precision policy for computation, defaults to Auto.
 

Detailed Description

Configuration class for MLP block.

Constructor & Destructor Documentation

◆ MLPConfig() [1/2]

Mila::Dnn::MLPConfig::MLPConfig ( const std::vector< size_t > &  input_shape,
size_t  hidden_size 
)
inline

Constructor with required parameters.

Parameters
input_shapeThe shape of the input tensor
hidden_sizeThe size of the hidden layer (intermediate dimension)

◆ MLPConfig() [2/2]

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

Alternative constructor with direct input features specification.

Parameters
input_featuresThe number of input features
hidden_sizeThe size of the hidden layer (intermediate dimension)

Member Function Documentation

◆ getActivationType()

ActivationType Mila::Dnn::MLPConfig::getActivationType ( ) const
inline
Here is the caller graph for this function:

◆ getDropout()

float Mila::Dnn::MLPConfig::getDropout ( ) const
inline
Here is the caller graph for this function:

◆ getHiddenSize()

size_t Mila::Dnn::MLPConfig::getHiddenSize ( ) const
inline
Here is the caller graph for this function:

◆ getInputFeatures()

size_t Mila::Dnn::MLPConfig::getInputFeatures ( ) const
inline
Here is the caller graph for this function:

◆ getInputShape()

const std::vector< size_t > & Mila::Dnn::MLPConfig::getInputShape ( ) const
inline
Here is the caller graph for this function:

◆ hasBias()

bool Mila::Dnn::MLPConfig::hasBias ( ) const
inline
Here is the caller graph for this function:

◆ useFusedOperations()

bool Mila::Dnn::MLPConfig::useFusedOperations ( ) const
inline
Here is the caller graph for this function:

◆ useLayerNorm()

bool Mila::Dnn::MLPConfig::useLayerNorm ( ) const
inline
Here is the caller graph for this function:

◆ useResidual()

bool Mila::Dnn::MLPConfig::useResidual ( ) const
inline
Here is the caller graph for this function:

◆ validate()

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

Validate configuration parameters.

Exceptions
std::invalid_argumentIf validation fails

Reimplemented from Mila::Dnn::ComponentConfig.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ withActivation()

MLPConfig & Mila::Dnn::MLPConfig::withActivation ( ActivationType  activation)
inline

Set the activation function type.

Parameters
activationThe activation function to use
Returns
MLPConfig& Reference to this for method chaining

◆ withBias()

MLPConfig & Mila::Dnn::MLPConfig::withBias ( bool  has_bias)
inline

Configure whether the linear layers use bias.

Parameters
has_biasWhether to include bias terms
Returns
MLPConfig& Reference to this for method chaining

◆ withDropout()

MLPConfig & Mila::Dnn::MLPConfig::withDropout ( float  dropout)
inline

Set the dropout rate.

Parameters
dropoutDropout probability (0.0 to 1.0)
Returns
MLPConfig& Reference to this for method chaining

◆ withFusedOperations()

MLPConfig & Mila::Dnn::MLPConfig::withFusedOperations ( bool  fuse_ops)
inline

Configure whether to fuse operations for inference.

Parameters
fuse_opsWhether to fuse operations when possible
Returns
MLPConfig& Reference to this for method chaining

◆ withLayerNorm()

MLPConfig & Mila::Dnn::MLPConfig::withLayerNorm ( bool  use_layer_norm)
inline

Configure whether to use layer normalization.

Parameters
use_layer_normWhether to use layer normalization
Returns
MLPConfig& Reference to this for method chaining

◆ withResidual()

MLPConfig & Mila::Dnn::MLPConfig::withResidual ( bool  use_residual)
inline

Configure whether to use a residual connection.

Parameters
use_residualWhether to add a residual connection
Returns
MLPConfig& Reference to this for method chaining

Member Data Documentation

◆ activation_type_

ActivationType Mila::Dnn::MLPConfig::activation_type_ { ActivationType::Gelu}
private

◆ dropout_

float Mila::Dnn::MLPConfig::dropout_ { 0.0f }
private

◆ fuse_operations_

bool Mila::Dnn::MLPConfig::fuse_operations_ { false }
private

◆ has_bias_

bool Mila::Dnn::MLPConfig::has_bias_ { true }
private

◆ hidden_size_

size_t Mila::Dnn::MLPConfig::hidden_size_ { 0 }
private

◆ input_features_

size_t Mila::Dnn::MLPConfig::input_features_ { 0 }
private

◆ input_shape_

std::vector<size_t> Mila::Dnn::MLPConfig::input_shape_
private

◆ use_layer_norm_

bool Mila::Dnn::MLPConfig::use_layer_norm_ { false }
private

◆ use_residual_

bool Mila::Dnn::MLPConfig::use_residual_ { false }
private

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