ggml_layer_layer_norm: Add Layer Normalization Layer

View source: R/nn_layers.R

ggml_layer_layer_normR Documentation

Add Layer Normalization Layer

Description

Normalizes each sample over its own features – subtract the mean, divide by the standard deviation – then scales by gamma and shifts by beta (both learnable). Like ggml_layer_rms_norm it keeps no running statistics and does not couple the samples in a batch, but unlike it, it does centre the input. This is the normalization of the original transformer.

Usage

ggml_layer_layer_norm(model, eps = 1e-05, name = NULL, trainable = TRUE)

Arguments

model

A ggml_sequential_model or a ggml_tensor_node (functional API).

eps

Small constant for numerical stability (default 1e-5)

name

Optional character name for the layer.

trainable

Logical; whether the layer weights are updated during training.

Value

The model with the layer appended, or a new ggml_tensor_node in the functional API.

See Also

ggml_layer_rms_norm, ggml_layer_batch_norm

Examples


x <- ggml_input(shape = c(10L, 32L))
h <- x |> ggml_layer_layer_norm()
h <- h |> ggml_layer_attention(d_model = 32L, n_heads = 4L)


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.