Mila 0.13.48
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::FusedComponent< TDeviceType, TPrecision > Class Template Referenceexport

DEPRECATED. More...

Inheritance diagram for Mila::Dnn::FusedComponent< TDeviceType, TPrecision >:
Collaboration diagram for Mila::Dnn::FusedComponent< TDeviceType, TPrecision >:

Public Types

using ComponentBase = Component<TDeviceType, TPrecision>
using OperationType = UnaryOperation<TDeviceType, TPrecision>

Public Member Functions

 FusedComponent (const std::string &fused_op_name, const std::vector< std::shared_ptr< ComponentBase > > &original_components, IExecutionContext *exec_context)
 Construct fused component from original sequence.
void backward (const ITensor &input, const ITensor &output_grad, ITensor &input_grad)
void forward (const ITensor &input, ITensor &output)
DeviceId getDeviceId () const override
 Get the compute device id associated with this component.
std::vector< ITensor * > getGradients () const override
 Return non-owning pointers to parameter gradient tensors.
std::vector< ITensor * > getParameters () const override
 Return non-owning pointers to parameter tensors.
void onBuilding (const shape_t &input_shape) override
size_t parameterCount () const override
 Return number of trainable parameters.
void save_ (ModelArchive &archive, SerializationMode mode) const override
void synchronize () override
 Wait for outstanding device work submitted by this component.
std::string toString () const override
 Produce a short, human-readable description of the component.
Public Member Functions inherited from Mila::Dnn::Component< TDeviceType, TPrecision >
 Component (const std::string &name)
 Construct component with required name identifier.
virtual ~Component ()=default
virtual void build (const BuildContext &context) final
 Build the component with the provided BuildContext (canonical overload).
virtual MemoryStats getMemoryStats () const =0
 Return the current memory allocation breakdown for this component.
const std::string getName () const
 Get the component's name identifier.
virtual std::vector< std::string > getParameterNames () const
 List all available parameter names for this component.
RuntimeMode getRuntimeMode () const noexcept
 Convenience accessor — true if currently in Eval mode.
TrainingMode getTrainingMode () const noexcept
 The current runtime behavioral mode of this Component.
virtual const ComponentType getType () const =0
 Get the component type identifier.
virtual bool isBuilt () const final
 Returns true if build() has completed successfully.
bool isInferenceMode () const noexcept
bool isTrainingMode () const noexcept
virtual void loadParameter (const std::string &name, const Serialization::ITensorBlob &blob)
 Load a parameter from serialized tensor data.
void setTrainingMode (TrainingMode mode)
 Set the runtime behavioral mode for this Component.
virtual void zeroGradients ()
 Clear all model-owned gradients for this component.

Protected Member Functions

void onTrainingChanging (bool is_training) override
Protected Member Functions inherited from Mila::Dnn::Component< TDeviceType, TPrecision >
IExecutionContextgetExecutionContext () const
 Get the shared execution context.
bool hasExecutionContext () const noexcept
 Check if execution context has been set.
template<TensorDataType TParameterPrecision, typename TMemoryResource>
void loadParameterFromBlob (const std::string &param_name, const Serialization::ITensorBlob &blob, Tensor< TParameterPrecision, TMemoryResource > &target, const shape_t &expected_shape)
 Load a tensor blob into a parameter tensor with validation.
virtual void onBuilding (const BuildContext &config)
 Hook invoked by build() to allocate component buffers.
virtual void onExecutionContextSet ()
 Lifecycle hook: Called immediately after ExecutionContext is set.
virtual void onTrainingModeChanging (TrainingMode mode)
 Hook called before TrainingMode transitions.
void setExecutionContext (IExecutionContext *context)
 Set the execution context for this component.

Private Attributes

IExecutionContextexec_context_
std::shared_ptr< OperationTypeoperation_
std::vector< std::shared_ptr< ComponentBase > > original_components_
std::vector< ITensor * > parameters_

Additional Inherited Members

Static Public Member Functions inherited from Mila::Dnn::Component< TDeviceType, TPrecision >
static constexpr DeviceType getDeviceType ()
 Compile-time device type for this component instance.
static constexpr TensorDataType getPrecision () noexcept
 Compile-time tensor precision for this component instance.
Protected Attributes inherited from Mila::Dnn::Component< TDeviceType, TPrecision >
BuildContext build_context_ { shape_t{ 1 }, RuntimeMode::Training }
 The BuildContext stored at build time.

Detailed Description

template<DeviceType TDeviceType, TensorDataType TPrecision>
class Mila::Dnn::FusedComponent< TDeviceType, TPrecision >

DEPRECATED.

Generic wrapper for fused backend operations.

Replaces a sequence of components with a single backend operation without exposing a new component type in the public API.

Deprecated
Built on the retired UnaryOperation base and the string-keyed OperationRegistry runtime dispatch, both superseded by compile-time OperationTraits. The only callers were CompositeComponent's never-invoked fuseSequentialOperations()/fusePair(). Excluded from the build (removed from Mila/CMakeLists.txt); retained for reference pending removal.

Member Typedef Documentation

◆ ComponentBase

template<DeviceType TDeviceType, TensorDataType TPrecision>
using Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::ComponentBase = Component<TDeviceType, TPrecision>

◆ OperationType

template<DeviceType TDeviceType, TensorDataType TPrecision>
using Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::OperationType = UnaryOperation<TDeviceType, TPrecision>

Constructor & Destructor Documentation

◆ FusedComponent()

template<DeviceType TDeviceType, TensorDataType TPrecision>
Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::FusedComponent ( const std::string & fused_op_name,
const std::vector< std::shared_ptr< ComponentBase > > & original_components,
IExecutionContext * exec_context )
inline

Construct fused component from original sequence.

Parameters
fused_op_nameBackend operation name (e.g., "LinearGeluOp")
original_componentsOriginal unfused components (for parameter extraction)
exec_contextExecution context
Here is the call graph for this function:

Member Function Documentation

◆ backward()

template<DeviceType TDeviceType, TensorDataType TPrecision>
void Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::backward ( const ITensor & input,
const ITensor & output_grad,
ITensor & input_grad )
inline

◆ forward()

template<DeviceType TDeviceType, TensorDataType TPrecision>
void Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::forward ( const ITensor & input,
ITensor & output )
inline

◆ getDeviceId()

template<DeviceType TDeviceType, TensorDataType TPrecision>
DeviceId Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::getDeviceId ( ) const
inlineoverridevirtual

Get the compute device id associated with this component.

Must return the device on which parameters and operations execute.

Implements Mila::Dnn::Component< TDeviceType, TPrecision >.

◆ getGradients()

template<DeviceType TDeviceType, TensorDataType TPrecision>
std::vector< ITensor * > Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::getGradients ( ) const
inlineoverridevirtual

Return non-owning pointers to parameter gradient tensors.

Only valid when isTraining() is true.

Exceptions
std::runtime_errorif called when not in training mode or before the component has been built.

Implements Mila::Dnn::Component< TDeviceType, TPrecision >.

◆ getParameters()

template<DeviceType TDeviceType, TensorDataType TPrecision>
std::vector< ITensor * > Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::getParameters ( ) const
inlineoverridevirtual

Return non-owning pointers to parameter tensors.

The returned tensor pointers remain valid for the lifetime of the component. Order should be canonical (weights before biases).

Implements Mila::Dnn::Component< TDeviceType, TPrecision >.

◆ onBuilding()

template<DeviceType TDeviceType, TensorDataType TPrecision>
void Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::onBuilding ( const shape_t & input_shape)
inlineoverride

◆ onTrainingChanging()

template<DeviceType TDeviceType, TensorDataType TPrecision>
void Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::onTrainingChanging ( bool is_training)
inlineoverrideprotected

◆ parameterCount()

template<DeviceType TDeviceType, TensorDataType TPrecision>
size_t Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::parameterCount ( ) const
inlineoverridevirtual

Return number of trainable parameters.

For leaf components this is the element count of owned parameter tensors. CompositeComponent and Network implementations should return the recursive aggregate across all children.

Implements Mila::Dnn::Component< TDeviceType, TPrecision >.

◆ save_()

template<DeviceType TDeviceType, TensorDataType TPrecision>
void Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::save_ ( ModelArchive & archive,
SerializationMode mode ) const
inlineoverridevirtual

◆ synchronize()

template<DeviceType TDeviceType, TensorDataType TPrecision>
void Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::synchronize ( )
inlineoverridevirtual

Wait for outstanding device work submitted by this component.

On CPU this may be a no-op. Use to ensure results are visible to the host or to measure synchronous timings.

Implements Mila::Dnn::Component< TDeviceType, TPrecision >.

◆ toString()

template<DeviceType TDeviceType, TensorDataType TPrecision>
std::string Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::toString ( ) const
inlineoverridevirtual

Produce a short, human-readable description of the component.

Implementations should keep output concise and avoid throwing.

Implements Mila::Dnn::Component< TDeviceType, TPrecision >.

Here is the call graph for this function:

Member Data Documentation

◆ exec_context_

template<DeviceType TDeviceType, TensorDataType TPrecision>
IExecutionContext* Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::exec_context_
private

◆ operation_

template<DeviceType TDeviceType, TensorDataType TPrecision>
std::shared_ptr<OperationType> Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::operation_
private

◆ original_components_

template<DeviceType TDeviceType, TensorDataType TPrecision>
std::vector<std::shared_ptr<ComponentBase> > Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::original_components_
private

◆ parameters_

template<DeviceType TDeviceType, TensorDataType TPrecision>
std::vector<ITensor*> Mila::Dnn::FusedComponent< TDeviceType, TPrecision >::parameters_
private

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