ggml_freeze_weights: Freeze Layer Weights

View source: R/nn_model.R

ggml_freeze_weightsR Documentation

Freeze Layer Weights

Description

Sets trainable = FALSE on layers, preventing their weights from being updated during training. Layers are chosen by layer_names and/or prefix; without either, by the index range from / to (sequential models), or all of them.

Usage

ggml_freeze_weights(
  model,
  from = 1L,
  to = length(model$layers),
  layer_names = NULL,
  prefix = NULL,
  ...
)

Arguments

model

A model object (ggml_sequential_model or ggml_functional_model)

from

Integer index of the first layer to freeze (default: 1)

to

Integer index of the last layer to freeze (default: last layer)

layer_names

Character vector of layer names to freeze (overrides from/to)

prefix

Character vector: freeze every layer whose name starts with one of these – a whole transformer block, say: prefix = "block1_" reaches block1_norm1, block1_attn, block1_norm2, block1_ff1 and block1_ff2 – not block10_*. Given with layer_names, the selection is the union of the two; every name and every prefix must match at least one layer, or the call stops.

...

Additional arguments passed to methods

Value

The model with selected layers frozen.

See Also

ggml_freeze_bn_stats to fix batch-norm statistics, which freezing the weights does not do.

Examples


model <- ggml_model_sequential() |>
  ggml_layer_dense(64, activation = "relu") |>
  ggml_layer_dense(10, activation = "softmax")

# Freeze all layers
model <- ggml_freeze_weights(model)

# Freeze only the first layer
model <- ggml_freeze_weights(model, from = 1, to = 1)


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