tensorrt_llm.functional.rms_norm

The tensorrt_llm.functional.rms_norm function in TensorRT-LLM applies Root Mean Square (RMS) normalization to a tensor. This operation is similar to layer normalization but with some key differences, particularly in how the normalization is computed. RMS normalization is often used in neural network architectures, including large language models, to help stabilize training and improve the learning process.

Function Purpose

  • RMS Normalization: Normalizes the input tensor based on the root mean square of the elements along the specified axes. It's an alternative to the standard layer normalization, with the variance normalized separately and not jointly with the mean.

Parameters

  1. input (Tensor):

    • The input tensor to be normalized.

    • Typically, this would be the output of a neural network layer.

  2. normalized_shape (int or Tuple[int]):

    • The dimensions over which normalization is performed.

    • In language models, it usually corresponds to the hidden dimension or feature dimension of the tensor.

  3. weight (Tensor, optional):

    • The scale coefficient (often denoted as gamma) for normalization, applied element-wise to the normalized tensor.

    • It should have the same shape as normalized_shape. If omitted, the tensor is normalized without scaling.

  4. eps (float):

    • A small constant (epsilon) added for numerical stability to avoid division by zero when computing the root mean square.

    • Typically a very small value like 1e-6.

How to Use

  • Prepare Input Tensor: Make sure your input tensor is ready and in the correct format (shape and data type).

  • Determine Normalization Shape: Choose the normalized_shape based on the dimensions you want to normalize, typically the feature dimensions.

  • Optional Weight: Provide a weight tensor for scaling if you have specific scaling parameters. If not provided, the operation defaults to RMS normalization without scaling.

  • Set Epsilon: Choose an appropriate eps value to avoid division by zero issues.

Returns

  • Tensor: The function returns a tensor that has been RMS normalized. It maintains the same shape as the input tensor.

Example Use Case

In a neural network layer, particularly in transformers used in large language models, RMS normalization can be applied to the output of layers (such as after a multi-head attention or feed-forward block). This normalization ensures that the scale of outputs is controlled, potentially leading to more stable and efficient training. RMS normalization is particularly useful when the variance of the features is of interest independently from the mean.

Last updated

Logo

Continuum - Accelerated Artificial Intelligence

Continuum WebsiteAxolotl Platform

Copyright Continuum Labs - 2023