sd_generate_multi_gpu: Parallel generation across multiple GPUs

View source: R/pipeline.R

sd_generate_multi_gpuR Documentation

Parallel generation across multiple GPUs

Description

Distributes prompts across available Vulkan GPUs, running one process per GPU via callr. Each process creates its own sd_ctx and calls sd_generate. Requires the callr package.

Usage

sd_generate_multi_gpu(
  model_path = NULL,
  prompts,
  negative_prompt = "",
  devices = NULL,
  seeds = NULL,
  width = 512L,
  height = 512L,
  model_type = "sd1",
  vram_gb = NULL,
  vae_decode_only = TRUE,
  progress = TRUE,
  diffusion_model_path = NULL,
  vae_path = NULL,
  clip_l_path = NULL,
  t5xxl_path = NULL,
  ...
)

Arguments

model_path

Path to the model file (single-file models like SD 1.x/2.x/SDXL)

prompts

Character vector of prompts (one image per prompt)

negative_prompt

Negative prompt applied to all images (default "")

devices

Integer vector of Vulkan device indices (0-based). Default NULL auto-detects all available devices.

seeds

Integer vector of seeds, same length as prompts. Default NULL generates random seeds.

width

Image width (default 512)

height

Image height (default 512)

model_type

Model type (default "sd1")

vram_gb

VRAM per GPU for auto-routing (default NULL)

vae_decode_only

VAE decode only (default TRUE)

progress

Print progress messages (default TRUE)

diffusion_model_path

Path to diffusion model (Flux/multi-file models)

vae_path

Path to VAE model

clip_l_path

Path to CLIP-L model

t5xxl_path

Path to T5-XXL model

...

Additional arguments passed to sd_generate

Value

List of SD images, one per prompt, in original order.

Note

Release any existing SD context (rm(ctx); gc()) before calling this function. Holding a Vulkan context in the main process while subprocesses try to use the same GPU can produce corrupted (grey) images.

Examples

## Not run: 
# Single-file model (SD 1.x/2.x/SDXL)
imgs <- sd_generate_multi_gpu(
  "model.safetensors",
  prompts = c("a cat", "a dog", "a bird", "a fish"),
  devices = 0:1
)

# Multi-file model (Flux)
imgs <- sd_generate_multi_gpu(
  diffusion_model_path = "flux1-dev-Q4_K_S.gguf",
  vae_path = "ae.safetensors",
  clip_l_path = "clip_l.safetensors",
  t5xxl_path = "t5-v1_1-xxl-encoder-Q5_K_M.gguf",
  prompts = c("a cat", "a dog"),
  model_type = "flux", devices = 0:1
)

## End(Not run)

sd2R documentation built on March 30, 2026, 5:08 p.m.