ggml_fit_generator: Train a Sequential Model from a Generator

View source: R/fit_generator.R

ggml_fit_generatorR Documentation

Train a Sequential Model from a Generator

Description

Streaming counterpart of ggml_fit for sequential models: batches are pulled from a generator instead of being sliced out of a matrix held in memory. Reachable either directly or as ggml_fit(model, generator = ...).

Usage

ggml_fit_generator(
  model,
  generator,
  steps_per_epoch = NULL,
  epochs = 1L,
  batch_size = 32L,
  initial_epoch = 0L,
  validation_generator = NULL,
  validation_steps = NULL,
  calibration_generator = NULL,
  calibration_steps = NULL,
  verbose = 1,
  callbacks = list()
)

Arguments

model

A compiled ggml_sequential_model

generator

Function of no arguments yielding list(x, y) for one batch, or NULL to end the epoch. Mutually exclusive with x/ y. Batches are in the same R layout those arguments take, and must contain exactly batch_size samples. A finite generator has to reset its own state before returning NULL, so that the next epoch starts over; see ggml_fit_opt_gen for the full contract and an example.

steps_per_epoch

Batches per epoch. Required for a generator that never returns NULL; otherwise the epoch ends when it does.

epochs

Number of epochs to run

batch_size

Samples per batch. The graph is built for a fixed batch, so the generator must yield exactly this many; a short batch is an error rather than being padded.

initial_epoch

Epoch number to start counting from. Shifts the numbering seen by callbacks and learning-rate schedules; it does not restore optimizer state (see ggml_fit_opt_gen).

validation_generator

Optional generator for validation, same contract.

validation_steps

Validation batches per epoch.

calibration_generator

Generator used to recompute batch-norm running statistics after training. Defaults to generator; note that a finite generator already exhausted by training yields nothing, so pass a fresh one.

calibration_steps

Batches to draw for that calibration.

verbose

0 to silence per-epoch messages

callbacks

List of callback lists, as for ggml_fit

Details

Batches are given in the same R layout that x and y use; the column-major conversion ggml wants happens internally, which is also what lets a recorded batch feed batch-norm calibration unchanged.

Value

The trained model, invisibly.

See Also

ggml_fit_opt_gen for the low-level loop this wraps.


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