| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This example demonstrates the backward pass of 2D Layer Normalization. This operation computes the gradients of the loss with respect to the input, gamma, and beta parameters of a layer normalization layer, which is essential for training neural networks that use layer normalization, particularly Transformers.
The backward pass of layer normalization involves computing gradients for three components: input X, scale parameter gamma, and shift parameter beta.
Given:
From the forward pass, we have:
Gradient w.r.t. beta: $\frac{\partial L}{\partial \beta_j} = \sum_{i=0}^{M-1} \frac{\partial L}{\partial Y_{ij}}$
Gradient w.r.t. gamma: $\frac{\partial L}{\partial \gamma_j} = \sum_{i=0}^{M-1} \frac{\partial L}{\partial Y_{ij}} \cdot \hat{X}_{ij}$
Gradient w.r.t. input (most complex): $\frac{\partial L}{\partial X_{ij}} = \frac{\gamma_j}{\sqrt{\sigma_i^2 + \epsilon}} \left[ \frac{\partial L}{\partial Y_{ij}} - \frac{1}{N}\left(\frac{\partial L}{\partial \beta_j} + \hat{X}_{ij} \frac{\partial L}{\partial \gamma_j}\right) \right]$
Where the gradient w.r.t. input involves the normalized input values and requires careful handling of the mean and variance computations.
The backward pass requires multiple reduction operations and careful coordination between gradient computations.
Pass 1: Compute Gamma and Beta Gradients
Pass 2: Compute Input Gradients
Memory Management:
Ensure the Composable Kernel library is built and installed.
cd /path/to/composable_kernel/build
make -j installcd /path/to/composable_kernel/example/53_layernorm2d_bwd
mkdir build && cd build
cmake \
-DCMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc \
-DCMAKE_PREFIX_PATH="/opt/rocm;${CK_INSTALL_PATH}" \
..
make -j# Run the example with default settings
./layernorm2d_bwd_xdl
# Run with verification, data initialization, and timing
./layernorm2d_bwd_xdl 1 2 1The backward pass of layer normalization has similar computational complexity to the forward pass but requires additional memory for storing gradients:
Layer normalization backward is crucial for training Transformer models:
The efficient implementation of this operation is critical for the overall training performance of large language models and other Transformer-based architectures.
| Back | FazBrowse Home | New Git URL |