Skip to main content

Overview

The Module class is the base class for all neural network modules in Neurenix. It provides parameter management, training/evaluation modes, and hierarchical organization of submodules.

Class Definition

Initialize a new module.

Core Methods

forward

Forward pass of the module. This method should be overridden by all subclasses.
Any
Input arguments to the module.
Any
Keyword arguments to the module.
Any
Output of the forward pass.

call

Call the module as a function. Internally calls forward().

Parameter Management

register_parameter

Register a parameter with the module.
str
required
The name of the parameter.
Optional[Tensor]
required
The parameter tensor, or None to remove the parameter.

register_module

Register a submodule with the module.
str
required
The name of the submodule.
Optional[Module]
required
The submodule, or None to remove the submodule.

register_buffer

Register a buffer with the module. Buffers are module states that should be saved along with parameters but are not parameters (e.g., running mean in batch normalization).
str
required
The name of the buffer.
Optional[Tensor]
required
The tensor to register as buffer, or None to remove the buffer.

parameters

Get all parameters of the module and its submodules.
List[Tensor]
A list of all parameter tensors.

Training Mode

train

Set the module in training mode.
bool
default:"True"
Whether to set training mode (True) or evaluation mode (False).
Module
The module itself.

eval

Set the module in evaluation mode.
Module
The module itself.

is_training

Check if the module is in training mode.
bool
True if the module is in training mode, False otherwise.

Device Management

to

Move the module and its parameters to the specified device.
Device
required
The device to move to.
Module
The module itself.

clone

Create a clone of this module with the same parameters.
Module
A new module with the same parameters.

Example Usage

Built-in Modules

Neurenix provides many built-in modules:
  • Linear layers: Linear
  • Convolutional layers: Conv1d, Conv2d, Conv3d
  • Recurrent layers: RNN, LSTM, GRU
  • Activation functions: ReLU, Sigmoid, Tanh, Softmax
  • Pooling layers: MaxPool2d
  • Regularization: Dropout
  • Containers: Sequential
See individual documentation pages for details on each module type.