sd_sample_stepwise: Run the sampling loop step-by-step in R (low-level)

View source: R/lowlevel.R

sd_sample_stepwiseR Documentation

Run the sampling loop step-by-step in R (low-level)

Description

Equivalent to sd_sample for the Euler / Euler-a samplers, but runs the loop in R so a callback can observe or interrupt each step (e.g. live preview). For Euler (no ancestral noise) the result is bit-for-bit equal to sd_sample; Euler-a differs (R RNG vs ggml RNG for the ancestral term). Other samplers are not supported here — use sd_sample.

Usage

sd_sample_stepwise(
  ctx,
  cond,
  uncond = list(crossattn = NULL, vector = NULL, concat = NULL),
  latent_shape = NULL,
  init_latent = NULL,
  noise = NULL,
  width = 512L,
  height = 512L,
  sample_method = SAMPLE_METHOD$EULER,
  scheduler = SCHEDULER$DISCRETE,
  sample_steps = 20L,
  cfg_scale = 7,
  seed = 42L,
  custom_sigmas = NULL,
  on_step = NULL
)

Arguments

ctx

SD context

cond

Positive conditioning from sd_encode_text

uncond

Negative conditioning; empty (all NULL) disables CFG

latent_shape

Integer c(W, H, C) in latent space, used to make noise when noise is NULL

init_latent

Optional starting latent (img2img); NULL for txt2img

noise

Optional explicit noise sd_tensor; generated from seed and latent_shape when NULL

width, height

Generation size in PIXELS (for the sigma schedule)

sample_method

SAMPLE_METHOD$EULER or $EULER_A

scheduler

Scheduler (name or SCHEDULER value)

sample_steps

Number of steps

cfg_scale

CFG scale

seed

Seed for noise generation when noise is NULL

custom_sigmas

Optional explicit sigma schedule (overrides scheduler)

on_step

Optional callback function(step, total, x, denoised) called after each step; return FALSE to stop early.

Value

An sd_tensor — the denoised latent x_0.

See Also

sd_sample, sd_decode_latent


sd2R documentation built on June 19, 2026, 9:08 a.m.