Tensara Logo

tensara

All Problems

RMS Normalization

EASY

Implement RMS (Root Mean Square) Normalization for a 2D tensor.

Normalize the input by dividing each element by the root mean square of the features in each sample. More formally, compute:

y=xmean(x2)+ϵ\text{y} = \frac{x}{\sqrt{\text{mean}(x^2) + \epsilon}}

where the mean is computed along the feature dimension for each sample in the batch independently. ϵ\epsilon is a small value added to the denominator for numerical stability.

Input:

  • Tensor X\text{X} of shape (B,N)(\text{B}, \text{N}) is the input data where B\text{B} = batch size and N\text{N} = number of features

Output:

  • Tensor Y\text{Y} with the same shape as input (normalized data)

Notes:

  • For each sample, the RMS is calculated over the feature dimension (dimension 1).
  • Use ϵ=105\epsilon = 10^{-5} for numerical stability.

Test Case Sizes

  • shape=(1024, 1024)
  • shape=(1024, 4096)
  • shape=(2048, 8192)
  • shape=(512, 16384)
Console

Sample Run Results

Hit "Run" to test your code with sample inputs

Loading...

Loading editor...

CUDA C++ environment

Desktop Required for Code Submission

For the best coding experience, please switch to a desktop device to write and submit your solution.