layernorm
¶
Custom normalization layers.
Classes¶
fastvideo.layers.layernorm.LayerNormScaleShift
¶
LayerNormScaleShift(hidden_size: int, norm_type: str = 'rms', eps: float = 1e-06, elementwise_affine: bool = False, dtype: dtype = float32, compute_dtype: dtype | None = None, prefix: str = '')
Bases: Module
Fused operation that combines LayerNorm with scale and shift operations. This reduces memory bandwidth by combining memory-bound operations.
Source code in fastvideo/layers/layernorm.py
Functions¶
fastvideo.layers.layernorm.LayerNormScaleShift.forward
¶
Apply ln followed by scale and shift in a single fused operation.
Source code in fastvideo/layers/layernorm.py
fastvideo.layers.layernorm.RMSNorm
¶
RMSNorm(hidden_size: int, eps: float = 1e-06, dtype: dtype = float32, var_hidden_size: int | None = None, has_weight: bool = True)
Bases: CustomOp
Root mean square normalization.
Computes x -> w * x / sqrt(E[x^2] + eps) where w is the learned weight. Refer to https://arxiv.org/abs/1910.07467
Source code in fastvideo/layers/layernorm.py
Functions¶
fastvideo.layers.layernorm.RMSNorm.forward_native
¶
forward_native(x: Tensor, residual: Tensor | None = None) -> Tensor | tuple[Tensor, Tensor]
PyTorch-native implementation equivalent to forward().
Source code in fastvideo/layers/layernorm.py
fastvideo.layers.layernorm.ScaleResidual
¶
ScaleResidual(prefix: str = '')
Bases: Module
Applies gated residual connection.
Source code in fastvideo/layers/layernorm.py
Functions¶
fastvideo.layers.layernorm.ScaleResidual.forward
¶
Apply gated residual connection.
Source code in fastvideo/layers/layernorm.py
fastvideo.layers.layernorm.ScaleResidualLayerNormScaleShift
¶
ScaleResidualLayerNormScaleShift(hidden_size: int, norm_type: str = 'rms', eps: float = 1e-06, elementwise_affine: bool = False, dtype: dtype = float32, compute_dtype: dtype | None = None, prefix: str = '')
Bases: Module
Fused operation that combines: 1. Gated residual connection 2. LayerNorm 3. Scale and shift operations
This reduces memory bandwidth by combining memory-bound operations.
Source code in fastvideo/layers/layernorm.py
Functions¶
fastvideo.layers.layernorm.ScaleResidualLayerNormScaleShift.forward
¶
forward(residual: Tensor, x: Tensor, gate: Tensor | int, shift: Tensor, scale: Tensor) -> tuple[Tensor, Tensor]
Apply gated residual connection, followed by layernorm and scale/shift in a single fused operation.
Returns:
| Type | Description |
|---|---|
Tensor
|
Tuple containing: |
Tensor
|
|
tuple[Tensor, Tensor]
|
|