module

nn

168 members
lucid.nn

Classes

classModule47 methods

Base class for all neural network modules.

classParameter2 methods

A `Tensor` subclass that `Module` recognises as a learnable parameter.

classRemovableHandle4 methods

Lightweight handle returned by every `register_*_hook` call.

classLinear4 methods

Apply a learnable affine transformation to incoming data.

classIdentity1 methods

Pass-through layer that returns its input unchanged.

classBilinear4 methods

Apply a bilinear transformation to a pair of input tensors.

classLazyLinear3 methods

Linear layer whose input dimension is inferred on the first forward call.

classFusedLinear3 methods

Linear layer with a kernel-fused non-linear activation.

classConv1d3 methods

Applies a 1D convolution over a sequence of input signals.

classConv2d3 methods

Applies a 2D convolution over a batch of images or feature maps.

classConv3d3 methods

Applies a 3D convolution over volumetric data (e.g. video or medical scans).

classConvTranspose1d3 methods

Applies a 1D transposed convolution (fractionally-strided convolution).

classConvTranspose2d3 methods

Applies a 2D transposed convolution (fractionally-strided convolution).

classConvTranspose3d3 methods

Applies a 3D transposed convolution (fractionally-strided convolution).

classLazyConv1d3 methods

A `Conv1d` that infers `in_channels` from the first input.

classLazyConv2d3 methods

A `Conv2d` that infers `in_channels` from the first input.

classLazyConv3d3 methods

A `Conv3d` that infers `in_channels` from the first input.

classLazyConvTranspose1d3 methods

A `ConvTranspose1d` that infers `in_channels` from the first input.

classLazyConvTranspose2d3 methods

A `ConvTranspose2d` that infers `in_channels` from the first input.

classLazyConvTranspose3d3 methods

A `ConvTranspose3d` that infers `in_channels` from the first input.

classReLU3 methods

Rectified Linear Unit activation function.

classLeakyReLU3 methods

Leaky Rectified Linear Unit activation function.

classELU3 methods

Exponential Linear Unit activation function.

classCELU3 methods

Continuously Differentiable Exponential Linear Unit activation function.

classSELU2 methods

Scaled Exponential Linear Unit activation function.

classGELU3 methods

Gaussian Error Linear Unit activation function.

classSiLU2 methods

Sigmoid Linear Unit (Swish) activation function.

classMish1 methods

Mish activation function.

classSoftplus3 methods

Softplus activation function.

classHardswish1 methods

Hard Swish activation function.

classHardsigmoid1 methods

Hard Sigmoid activation function.

classSigmoid1 methods

Sigmoid (logistic) activation function.

classTanh1 methods

Hyperbolic tangent activation function.

classSoftmax3 methods

Softmax activation function.

classSoftmax2d1 methods

Softmax activation applied over the channel dimension of a 4-D tensor.

classLogSoftmax3 methods

Log-Softmax activation function.

classRReLU3 methods

Randomized Leaky ReLU activation function.

classCosineSimilarity3 methods

Cosine similarity between two tensors along a specified dimension.

classPairwiseDistance3 methods

Pairwise $\ell_p$ distance between corresponding rows of two tensors.

classReLU62 methods

ReLU6 activation function.

classPReLU3 methods

Parametric Rectified Linear Unit activation function.

classThreshold3 methods

Threshold activation function.

classHardtanh3 methods

Hardtanh activation function.

classLogSigmoid1 methods

Log-Sigmoid activation function.

classSoftsign1 methods

Softsign activation function.

classSoftmin3 methods

Softmin activation function.

classGLU3 methods

Gated Linear Unit activation function.

classHardshrink3 methods

Hard Shrinkage activation function.

classTanhshrink1 methods

Tanhshrink activation function.

classSoftshrink3 methods

Soft Shrinkage activation function.

classLayerNorm3 methods

Layer normalization over the trailing dimensions of the input.

classRMSNorm3 methods

Root Mean Square Layer Normalization.

classGroupNorm3 methods

Group normalization over the channel dimension.

classBatchNorm1d

Batch normalization over a 2-D or 3-D input `(N, C)` or `(N, C, L)`.

classBatchNorm2d

Batch normalization over a 4-D input `(N, C, H, W)`.

classBatchNorm3d

Batch normalization over a 5-D input `(N, C, D, H, W)`.

classInstanceNorm1d

Instance normalization for 3-D input `(N, C, L)`.

classInstanceNorm2d

Instance normalization for 4-D input `(N, C, H, W)`.

classInstanceNorm3d

Instance normalization for 5-D input `(N, C, D, H, W)`.

classLocalResponseNorm3 methods

Local Response Normalization (LRN) across adjacent channels.

classLazyBatchNorm1d

BatchNorm1d with lazy `num_features` inference.

classLazyBatchNorm2d

BatchNorm2d with lazy `num_features` inference.

classLazyBatchNorm3d

BatchNorm3d with lazy `num_features` inference.

classLazyInstanceNorm1d

InstanceNorm1d with lazy `num_features` inference.

classLazyInstanceNorm2d

InstanceNorm2d with lazy `num_features` inference.

classLazyInstanceNorm3d

InstanceNorm3d with lazy `num_features` inference.

classMaxPool1d3 methods

Applies 1-D max pooling over a sequence.

classMaxPool2d3 methods

Applies 2-D max pooling over a spatial feature map.

classMaxPool3d3 methods

Applies 3-D max pooling over a volumetric feature map.

classAvgPool1d3 methods

Applies 1-D average pooling over a sequence.

classAvgPool2d3 methods

Applies 2-D average pooling over a spatial feature map.

classAvgPool3d3 methods

Applies 3-D average pooling over a volumetric feature map.

classAdaptiveAvgPool1d3 methods

Applies adaptive 1-D average pooling to produce a fixed output length.

classAdaptiveAvgPool2d3 methods

Applies adaptive 2-D average pooling to produce a fixed output size.

classAdaptiveAvgPool3d3 methods

Applies adaptive 3-D average pooling to produce a fixed output volume.

classAdaptiveMaxPool2d3 methods

Applies adaptive 2-D max pooling to produce a fixed output size.

classAdaptiveMaxPool1d3 methods

Applies adaptive 1-D max pooling to produce a fixed output length.

classAdaptiveMaxPool3d3 methods

Applies adaptive 3-D max pooling to produce a fixed output volume.

classLPPool1d3 methods

Applies 1-D power-average (Lp-norm) pooling over a sequence.

classLPPool2d3 methods

Applies 2-D power-average (Lp-norm) pooling over a spatial feature map.

classLPPool3d3 methods

Applies 3-D power-average (Lp-norm) pooling over a volumetric input.

classMaxUnpool1d1 methods

Computes a partial inverse of `MaxPool1d`.

classMaxUnpool2d1 methods

Computes a partial inverse of `MaxPool2d`.

classMaxUnpool3d1 methods

Computes a partial inverse of `MaxPool3d`.

classFractionalMaxPool2d2 methods

Applies fractional max-pooling over a 2-D spatial feature map.

classFractionalMaxPool3d2 methods

Applies fractional max-pooling over a 3-D volumetric feature map.

classDropout3 methods

Randomly zero individual tensor elements during training (inverted dropout).

classDropout1d3 methods

Randomly zero entire channels during training for 3-D inputs.

classDropout2d3 methods

Randomly zero entire feature-map channels during training for 4-D inputs.

classDropout3d3 methods

Randomly zero entire volumetric feature-map channels during training.

classAlphaDropout3 methods

Alpha dropout — element-wise dropout that preserves SELU self-normalisation.

classFeatureAlphaDropout3 methods

Channel-wise alpha dropout that preserves SELU self-normalisation.

classEmbedding3 methods

Learnable dense lookup table that maps integer token indices to vectors.

classEmbeddingBag3 methods

Embedding lookup table with per-bag reduction.

classRotaryEmbedding2 methods

Precomputed cos / sin tables for rotary positional embedding.

classSinusoidalEmbedding2 methods

Fixed 1-D sinusoidal positional encoding (Vaswani et al., 2017).

classSinusoidalEmbedding2D2 methods

Fixed 2-D sinusoidal positional encoding (DETR §A.4 / Carion 2020).

classTimestepEmbedding2 methods

Sinusoidal-frequency embedding of integer timesteps + 2-layer MLP.

classMultiheadAttention3 methods

Multi-head scaled dot-product attention.

classLSTM4 methods

Long Short-Term Memory (LSTM) recurrent layer.

classGRU4 methods

Multi-layer Gated Recurrent Unit (GRU) recurrent layer.

classRNN4 methods

Multi-layer Elman recurrent neural network (RNN).

classLSTMCell3 methods

Single time-step Long Short-Term Memory (LSTM) cell.

classGRUCell3 methods

Single time-step Gated Recurrent Unit (GRU) cell.

classRNNCell3 methods

Single time-step Elman RNN cell.

classMSELoss3 methods

Mean squared error (MSE) loss between each element of the prediction and the target.

classL1Loss3 methods

Mean absolute error (MAE) loss between each element of the prediction and the target.

classCrossEntropyLoss3 methods

Cross-entropy loss for multi-class classification.

classNLLLoss3 methods

Negative log-likelihood loss.

classBCELoss3 methods

Binary cross-entropy loss.

classBCEWithLogitsLoss3 methods

Binary cross-entropy loss that accepts raw logits.

classHuberLoss3 methods

Huber loss — a smooth interpolation between MSE and MAE.

classSmoothL1Loss3 methods

Smooth L1 loss — a $\beta$-parameterised Huber loss.

classKLDivLoss3 methods

Kullback–Leibler divergence loss.

classTripletMarginLoss3 methods

Triplet margin loss for metric learning.

classTripletMarginWithDistanceLoss3 methods

Triplet margin loss with a user-supplied distance function.

classCosineEmbeddingLoss3 methods

Cosine embedding loss for learning similarity/dissimilarity.

classMarginRankingLoss3 methods

Margin ranking loss for pairwise ranking problems.

classHingeEmbeddingLoss3 methods

Hinge embedding loss for binary similarity learning.

classPoissonNLLLoss3 methods

Poisson negative log-likelihood loss for count data.

classGaussianNLLLoss3 methods

Gaussian negative log-likelihood loss for heteroscedastic regression.

classCTCLoss3 methods

Connectionist Temporal Classification (CTC) loss.

classMultiMarginLoss3 methods

Multi-class hinge (SVM-style) margin loss.

classMultilabelMarginLoss3 methods

Multi-label ranking margin loss.

classMultiLabelMarginLoss

CamelCase alias for `MultilabelMarginLoss`.

classSoftMarginLoss3 methods

Soft-margin binary hinge loss.

classMultiLabelSoftMarginLoss3 methods

Multi-label soft-margin loss (BCE with logits averaged over classes).

classSequential9 methods

An ordered container of modules applied one after another in sequence.

classModuleList9 methods

A list-like container that registers all child modules with the parent.

classModuleDict13 methods

A dict-like container that registers all child modules under string keys.

classParameterList8 methods

A list-like container that registers `Parameter` objects with the module.

classParameterDict13 methods

A dict-like container that registers `Parameter` objects under string keys.

classFlatten3 methods

Flatten a contiguous range of dimensions into a single dimension.

classUnflatten3 methods

Expand one dimension of a tensor into multiple dimensions.

classUnfold3 methods

Extract sliding local blocks (patches) from a batched 4-D input tensor.

classFold3 methods

Combine an array of sliding local blocks back into a batched tensor.

classConstantPad1d1 methods

Pad a 3-D tensor (N, C, L) along the last dimension with a constant.

classConstantPad2d1 methods

Pad a 4-D tensor (N, C, H, W) on all four spatial sides with a constant.

classConstantPad3d1 methods

Pad a 5-D tensor (N, C, D, H, W) on all six faces with a constant.

classZeroPad1d2 methods

Pad a 3-D tensor (N, C, L) with zeros along the sequence dimension.

classZeroPad2d2 methods

Pad a 4-D tensor (N, C, H, W) with zeros on all four spatial sides.

classZeroPad3d2 methods

Pad a 5-D tensor (N, C, D, H, W) with zeros on all six faces.

classReflectionPad1d3 methods

Pad a 3-D tensor (N, C, L) by reflecting at the sequence boundaries.

classReflectionPad2d3 methods

Pad a 4-D tensor (N, C, H, W) by reflecting at all four spatial edges.

classReflectionPad3d3 methods

Pad a 5-D tensor (N, C, D, H, W) by reflecting at the volume boundaries.

classReplicationPad1d3 methods

Pad a 3-D tensor (N, C, L) by replicating the edge values.

classReplicationPad2d3 methods

Pad a 4-D tensor (N, C, H, W) by replicating the edge pixels.

classReplicationPad3d3 methods

Pad a 5-D tensor (N, C, D, H, W) by replicating the boundary voxels.

classCircularPad1d3 methods

Pad a 3-D tensor (N, C, L) by wrapping the sequence around itself.

classCircularPad2d3 methods

Pad a 4-D tensor (N, C, H, W) with wrap-around in both spatial axes.

classCircularPad3d3 methods

Pad a 5-D tensor (N, C, D, H, W) with wrap-around in all three axes.

classUpsample3 methods

Upsample an input tensor to a given spatial size or scale factor.

classUpsamplingNearest2d1 methods

Nearest-neighbour upsampling for 4-D tensors (N, C, H, W).

classUpsamplingBilinear2d1 methods

Bilinear upsampling for 4-D tensors (N, C, H, W) with aligned corners.

classPixelShuffle3 methods

Rearrange channel-stacked sub-pixel planes into a high-resolution output.

classPixelUnshuffle3 methods

Reverse the sub-pixel rearrangement performed by `PixelShuffle`.

classChannelShuffle3 methods

Shuffle channels across groups to enable cross-group information flow.

classTransformerEncoderLayer3 methods

Single transformer encoder layer: self-attention followed by a position-wise feed-forward network, with residual connections and layer normalisation.

classTransformerEncoder3 methods

A stack of $N$ identical `TransformerEncoderLayer` modules.

classTransformerDecoderLayer3 methods

Single transformer decoder layer: masked self-attention, cross-attention over encoder memory, and a position-wise FFN — each with residual connections and layer normalisation.

classTransformerDecoder3 methods

A stack of $N$ identical `TransformerDecoderLayer` modules.

classTransformer3 methods

Full encoder-decoder Transformer architecture.

Functions