ggml_set_seed: Set the random seed for reproducible ggmlR runs

View source: R/seed.R

ggml_set_seedR Documentation

Set the random seed for reproducible ggmlR runs

Description

Fixes the random seed used by ggmlR for everything that is stochastic:

  • weight initialisation (sequential, functional and autograd layers),

  • dropout masks (training-time),

  • data shuffling in the autograd dataloader / training loops.

Usage

ggml_set_seed(seed)

Arguments

seed

A single integer (or value coercible to integer) used as the RNG seed. NULL is a no-op, which lets callers thread an optional seed argument through without special-casing it.

Details

This is a thin wrapper around set.seed: all randomness in ggmlR is produced by the base R RNG, so a fixed seed gives identical starting weights, dropout masks and batch ordering across runs. It is the single point of control used by the mlr3 learners (seed hyperparameter) and the parsnip "ggml" engine (seed engine argument).

GPU note: this controls the random *inputs* to the computation, not the floating-point arithmetic itself. GPU (Vulkan) kernels are run-to-run stable on a given device/driver for the standard forward/backward paths, but ggmlR does not guarantee bit-for-bit identical results across different devices, drivers or backends (CPU vs Vulkan). Reproducibility is at the level of training dynamics, not exact bits.

Value

Invisibly returns seed.

See Also

set.seed

Examples

ggml_set_seed(42)
a <- runif(3)
ggml_set_seed(42)
b <- runif(3)
identical(a, b)  # TRUE


ggmlR documentation built on July 14, 2026, 1:08 a.m.