TensorTonic
Study Plans
Study Plan
RMSNorm Forward Pass
Language ModelsNeural Networks
Easy

Implement RMSNorm independently over each final-dimension feature vector, without subtracting its mean.

RMSNorm⁡(x)=x1d∑i=1dxi2+ϵ⊙g.\operatorname{RMSNorm}(x)=\frac{x}{\sqrt{\frac{1}{d}\sum_{i=1}^{d}x_i^2+\epsilon}}\odot g.RMSNorm(x)=d1​∑i=1d​xi2​+ϵ​x​⊙g.

Here x is one feature vector, d is its width, i indexes a feature, g is the learned scale vector, epsilon is the supplied positive stabilizer, and the circled-dot operator means elementwise multiplication.

Return a PyTorch tensor with the same shape, dtype, and device as x.

Loading visualization...

Examples

Input: x = [[1,2],[3,4]], g = [1,1], epsilon = 0.00001

Output: [[0.632454,1.264909],[0.848528,1.13137]]

Explanation: Each row is divided by its own root mean square. The learned scale is [1,1], so it does not change the normalized values.

Input: x = [[3,4]], g = [2,0.5], epsilon = 0.000001

Output: [[1.697056,0.565685]]

Input: x = [[0,0,0]], g = [1,2,3], epsilon = 0.0001

Output: [[0,0,0]]

Hint 1

Tensor.mean with keepdim=True retains a broadcastable final axis.

Hint 2

torch.rsqrt computes a reciprocal square root.

Requirements

  • Use PyTorch with float32 arithmetic for normalization and learned scaling, preserving x's dtype in the result.
  • Supported input dtypes are float32 and bfloat16; public cases and custom Run inputs use float32.
  • Leave x and g unchanged.

Constraints

  • x is a floating-point PyTorch tensor with final dimension d at least 1.
  • g is a floating-point PyTorch tensor with shape (d) on the same device as x.
  • epsilon is a positive finite number.
  • Supported input dtypes are float32 and bfloat16.
  • All supplied tensor values are finite.
Try Similar Problems
Parallel and Recurrent Linear AttentionMediumMamba 2 Gated State ScanMediumParameter-Matched SwiGLU BlockMediumRoPE: Rotary Query and Key EmbeddingsMediumTop-k MoE Router with Load StatisticsHardGated DeltaNet State UpdateHardCausal Grouped-Query AttentionHardOrthogonalize a Muon Momentum UpdateEasyActivation FunctionsEasyDouble DQN TargetEasyPerceptronEasyBatch NormalizationEasy

Accepts: array

Accepts: array

Accepts: number

You must run your code first.

RMSNorm Forward Pass

Language ModelsNeural Networks
Easy

Implement RMSNorm independently over each final-dimension feature vector, without subtracting its mean.

RMSNorm⁡(x)=x1d∑i=1dxi2+ϵ⊙g.\operatorname{RMSNorm}(x)=\frac{x}{\sqrt{\frac{1}{d}\sum_{i=1}^{d}x_i^2+\epsilon}}\odot g.RMSNorm(x)=d1​∑i=1d​xi2​+ϵ​x​⊙g.

Here x is one feature vector, d is its width, i indexes a feature, g is the learned scale vector, epsilon is the supplied positive stabilizer, and the circled-dot operator means elementwise multiplication.

Return a PyTorch tensor with the same shape, dtype, and device as x.

Loading visualization...

Examples

Input: x = [[1,2],[3,4]], g = [1,1], epsilon = 0.00001

Output: [[0.632454,1.264909],[0.848528,1.13137]]

Explanation: Each row is divided by its own root mean square. The learned scale is [1,1], so it does not change the normalized values.

Input: x = [[3,4]], g = [2,0.5], epsilon = 0.000001

Output: [[1.697056,0.565685]]

Input: x = [[0,0,0]], g = [1,2,3], epsilon = 0.0001

Output: [[0,0,0]]

Hint 1

Tensor.mean with keepdim=True retains a broadcastable final axis.

Hint 2

torch.rsqrt computes a reciprocal square root.

Requirements

  • Use PyTorch with float32 arithmetic for normalization and learned scaling, preserving x's dtype in the result.
  • Supported input dtypes are float32 and bfloat16; public cases and custom Run inputs use float32.
  • Leave x and g unchanged.

Constraints

  • x is a floating-point PyTorch tensor with final dimension d at least 1.
  • g is a floating-point PyTorch tensor with shape (d) on the same device as x.
  • epsilon is a positive finite number.
  • Supported input dtypes are float32 and bfloat16.
  • All supplied tensor values are finite.
Try Similar Problems
Parallel and Recurrent Linear AttentionMediumMamba 2 Gated State ScanMediumParameter-Matched SwiGLU BlockMediumRoPE: Rotary Query and Key EmbeddingsMediumTop-k MoE Router with Load StatisticsHardGated DeltaNet State UpdateHardCausal Grouped-Query AttentionHardOrthogonalize a Muon Momentum UpdateEasyActivation FunctionsEasyDouble DQN TargetEasyPerceptronEasyBatch NormalizationEasy

Accepts: array

Accepts: array

Accepts: number

You must run your code first.