sd_sample: Run the sampling loop (low-level)

View source: R/lowlevel.R

sd_sampleR Documentation

Run the sampling loop (low-level)

Description

Runs the full denoising loop given pre-computed conditioning and an explicit noise tensor. Noise is supplied by the caller for determinism; use seed to generate it reproducibly, or pass noise directly.

Usage

sd_sample(
  ctx,
  cond,
  uncond = list(crossattn = NULL, vector = NULL, concat = NULL),
  latent_shape = NULL,
  init_latent = NULL,
  noise = NULL,
  strength = 1,
  sample_method = SAMPLE_METHOD$EULER,
  scheduler = SCHEDULER$DISCRETE,
  sample_steps = 20L,
  cfg_scale = 7,
  eta = 0,
  seed = 42L,
  custom_sigmas = NULL
)

Arguments

ctx

SD context

cond

Positive conditioning from sd_encode_text

uncond

Negative conditioning from sd_encode_text. Pass an empty conditioning (all NULL) to disable CFG.

latent_shape

Integer vector c(W, H, C) in latent space; used to generate noise when noise is not supplied. Ignored if noise is given.

init_latent

Optional starting latent for img2img (from sd_encode_image); NULL for txt2img.

noise

Optional explicit noise sd_tensor. When NULL, standard normal noise of latent_shape is generated using seed.

strength

img2img denoising strength (ignored for txt2img)

sample_method

Sampling method (name or SAMPLE_METHOD value)

scheduler

Scheduler (name or SCHEDULER value)

sample_steps

Number of steps

cfg_scale

CFG scale

eta

Eta for DDIM-like samplers

seed

Seed for noise generation when noise is NULL

custom_sigmas

Optional explicit sigma schedule (overrides scheduler)

Value

An sd_tensor list — the denoised latent x_0. Pass to sd_decode_latent.

See Also

sd_encode_text, sd_decode_latent


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