stable_diffusion

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 7 Imported by: 0

README

stable-diffusion-go

A pure-Go binding to leejet/stable-diffusion.cpp, built on ebitengine/purego so it calls the native library directly over FFI — no cgo required. It runs on Linux, macOS, and Windows and supports text-to-image, image-to-image, and text-to-video generation.

This project is a fork of orangelang/stable-diffusion-go. See Acknowledgements.

Highlights

  • No cgo — pure Go via purego; the native shared library is loaded at runtime.
  • Caller-controlled loading — you decide where and when the library is loaded; importing the package touches nothing.
  • Cross-platform — Linux, macOS, and Windows, with GPU (CUDA / ROCm / Vulkan) and CPU (AVX) variant selection.
  • Broad API coverage — txt2img, img2img, txt2vid, upscaling, and model conversion.

Installation

go get github.com/pendra-ai/stable-diffusion-go

The native library

This repository contains only the Go binding — the native shared library is not committed. The library is built from the upstream commit pinned in lib/version.txt (currently master-802-e92e86f).

Prebuilt archives

The binding and its libraries ship together on one tag. Every Release is a single vX.Y.Z that carries both the Go module (so go get …@vX.Y.Z resolves the binding) and the prebuilt lib archives + checksums.txt as assets, built by the build-libs.yml workflow (upstream ships no prebuilt release covering these variants). Pick the version you pinned, download the archive matching your host from that release, extract it into a directory, and pass that directory to Load. The asset names are version-less — the release tag carries the version:

stable-diffusion-libs-linux-amd64-cpu.tar.gz      # also -cuda, -vulkan
stable-diffusion-libs-linux-arm64-cpu.tar.gz
stable-diffusion-libs-darwin-arm64-metal.tar.gz
stable-diffusion-libs-windows-amd64.tar.gz        # carries the subdir tree

e.g. https://github.com/pendra-ai/stable-diffusion-go/releases/download/vX.Y.Z/stable-diffusion-libs-linux-amd64-cpu.tar.gz.

Each archive ships a single self-contained library (ggml is statically linked, with hidden visibility so only the stable-diffusion.cpp symbols are exported and the embedded ggml symbols stay local — they won't collide with another in-process library that has its own ggml). The Windows archive contains the GPU/CPU variant subdirectories the loader selects from (avx2/, avx512/, avx/, noavx/, vulkan/, cuda13/); extract it whole and point Load at its root. CUDA archives need a host CUDA runtime; Vulkan archives need a Vulkan loader/ICD.

Platform Library file
Linux libstable-diffusion.so
macOS libstable-diffusion.dylib
Windows stable-diffusion.dll (under a variant subdir)

To build it yourself instead, compile stable-diffusion.cpp at the pinned commit with -DSD_BUILD_SHARED_LIBS=ON. The binding registers the full stable-diffusion.cpp symbol set (lib/expected-symbols.txt), so the library must export all of them — keep the library version in lockstep with lib/version.txt.

Loading the library

The caller controls loading via Load(libDir). Importing the package performs no filesystem access and no dlopen; nothing native happens until you call Load, which is lazy, idempotent, and returns an error (never panics) when the library is missing or incompatible.

import stablediffusion "github.com/pendra-ai/stable-diffusion-go"

// Load from a directory you control...
if err := stablediffusion.Load("/path/to/libs"); err != nil {
    // The native library is absent or incompatible — handle gracefully.
    log.Fatal(err)
}

// ...or pass an empty dir to use the OS default library search path.
if err := stablediffusion.Load(""); err != nil {
    log.Fatal(err)
}

On Windows, GPU/CPU variant subdirectories (cuda13/, rocm/, vulkan/, avx2/, …) are resolved within the supplied directory.

Quick start

package main

import (
    "log"

    stablediffusion "github.com/pendra-ai/stable-diffusion-go"
)

func main() {
    // Resolve the native library (empty dir => OS default search path).
    if err := stablediffusion.Load(""); err != nil {
        log.Fatal(err)
    }

    // Create an instance — this loads the model and is reused across calls.
    sd, err := stablediffusion.NewStableDiffusion(&stablediffusion.ContextParams{
        DiffusionModelPath: "models/diffusion_model.gguf",
        LLMPath:            "models/llm_model.gguf",
        VAEPath:            "models/vae.safetensors",
        DiffusionFlashAttn: true,
    })
    if err != nil {
        log.Fatal(err)
    }
    defer sd.Free() // free the loaded model once, when you're done

    // Generate an image. The instance can serve many GenerateImage calls.
    if err := sd.GenerateImage(&stablediffusion.ImgGenParams{
        Prompt:      "A cute Corgi running on the grass",
        Width:       512,
        Height:      512,
        SampleSteps: 15,
        CfgScale:    2.0,
    }, "output.png"); err != nil {
        log.Fatal(err)
    }
}
Running the examples

Each example is its own main package:

go run ./examples/txt2img   # text-to-image
go run ./examples/txt2vid   # text-to-video (requires FFmpeg for encoding)

Usage notes

  • Reuse the instance. NewStableDiffusion loads a multi-GB model. Keep the instance and call GenerateImage repeatedly; release it once with defer sd.Free(). Don't create a new instance per request.
  • In-memory PNG. Need the encoded bytes instead of a file? The low-level package offers sd.EncodePNG(*sd.SDImage) ([]byte, error).
  • Freeing native images. If you work with raw results from the low-level pkg/sd API, free the native-allocated buffers with sd.FreeImage / sd.FreeImages. The high-level GenerateImage already does this for you.
  • Video generation uses FFmpeg to encode frames — make sure ffmpeg is on your PATH.
  • Performance. Tune NThreads, enable DiffusionFlashAttn, and use quantized weights (e.g. WType: stablediffusion.SDTypeQ4_K) to trade quality for speed and memory.

Project structure

stable-diffusion-go/
├── stable_diffusion.go   # high-level wrapper (NewStableDiffusion, GenerateImage, ...)
├── pkg/sd/               # low-level binding (Load, contexts, EncodePNG, FreeImage, ...)
├── examples/
│   ├── txt2img/          # text-to-image example
│   └── txt2vid/          # text-to-video example
└── lib/                  # version pin + license text (no native binaries)

Contributing

Issues and pull requests are welcome. Please keep tests passing and add coverage alongside your changes — see CLAUDE.md for the conventions this repo follows (lazy caller-controlled loading, no panics across the FFI boundary, freeing native memory, and keeping all platforms compiling). Before opening a PR:

gofmt -l .        # should print nothing
go vet ./...
go build ./...
go test ./...

Acknowledgements

Huge thanks to the projects and people this binding builds on:

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HiresUpscalerMap = map[string]sd.SDHiresUpscaler{
	"none":                       sd.HiresUpscalerNone,
	"latent":                     sd.HiresUpscalerLatent,
	"latent_nearest":             sd.HiresUpscalerLatentNearest,
	"latent_nearest_exact":       sd.HiresUpscalerLatentNearestExact,
	"latent_antialiased":         sd.HiresUpscalerLatentAntialiased,
	"latent_bicubic":             sd.HiresUpscalerLatentBicubic,
	"latent_bicubic_antialiased": sd.HiresUpscalerLatentBicubicAntialiased,
	"lanczos":                    sd.HiresUpscalerLanczos,
	"nearest":                    sd.HiresUpscalerNearest,
	"model":                      sd.HiresUpscalerModel,
}

HiresUpscalerMap hi-res-fix upscaler mapping

View Source
var LoraApplyModeMap = map[string]sd.LoraApplyMode{
	"auto":                  sd.LoraApplyAuto,
	"immediately":           sd.LoraApplyImmediately,
	"at_runtime":            sd.LoraApplyAtRuntime,
	"lora_apply_mode_count": sd.LoraApplyModeCount,
}

LoraApplyModeMap LoRA apply mode mapping

View Source
var PredictionMap = map[string]sd.Prediction{
	"eps":          sd.EPSPred,
	"v":            sd.VPred,
	"edm_v":        sd.EDMVPred,
	"flow":         sd.FlowPred,
	"sd3_flow":     sd.FlowPred,
	"flux_flow":    sd.FluxFlowPred,
	"sefi_flow":    sd.SefiFlowPred,
	"minit2i_flow": sd.Minit2iFlowPred,
	"default":      sd.PredictionCount,
}

PredictionMap prediction type mapping. Upstream master-802 replaced FLUX2_FLOW_PRED with SEFI_FLOW_PRED (same enum slot) and added MINIT2I_FLOW_PRED; its canonical name for FLOW_PRED is "sd3_flow" ("flow" is kept as this binding's legacy alias).

View Source
var PreviewMap = map[string]sd.Preview{
	"none":          sd.PreviewNone,
	"proj":          sd.PreviewProj,
	"tae":           sd.PreviewTAE,
	"vae":           sd.PreviewVAE,
	"preview_count": sd.PreviewCount,
}

PreviewMap preview type mapping

View Source
var RNGTypeMap = map[string]sd.RngType{
	"default":    sd.DefaultRNG,
	"cuda":       sd.CUDARNG,
	"cpu":        sd.CPURNG,
	"type_count": sd.RNGTypeCount,
}

RNGTypeMap RNG type mapping

View Source
var SDTypeMap = map[string]sd.SDType{
	"f32":  sd.SDTypeF32,
	"f16":  sd.SDTypeF16,
	"q4_0": sd.SDTypeQ4_0,
	"q4_1": sd.SDTypeQ4_1,
	"q5_0": sd.SDTypeQ5_0,
	"q5_1": sd.SDTypeQ5_1,
	"q8_0": sd.SDTypeQ8_0,
	"q8_1": sd.SDTypeQ8_1,

	"q2_k":    sd.SDTypeQ2_K,
	"q3_k":    sd.SDTypeQ3_K,
	"q4_k":    sd.SDTypeQ4_K,
	"q5_k":    sd.SDTypeQ5_K,
	"q6_k":    sd.SDTypeQ6_K,
	"q8_k":    sd.SDTypeQ8_K,
	"iq2_xxs": sd.SDTypeIQ2_XXS,
	"iq2_xs":  sd.SDTypeIQ2_XS,
	"iq3_xxs": sd.SDTypeIQ3_XXS,
	"iq1_s":   sd.SDTypeIQ1_S,
	"iq4_nl":  sd.SDTypeIQ4_NL,
	"iq3_s":   sd.SDTypeIQ3_S,
	"iq2_s":   sd.SDTypeIQ2_S,
	"iq4_xs":  sd.SDTypeIQ4_XS,
	"i8":      sd.SDTypeI8,
	"i16":     sd.SDTypeI16,
	"i32":     sd.SDTypeI32,
	"i64":     sd.SDTypeI64,
	"f64":     sd.SDTypeF64,
	"iq1_m":   sd.SDTypeIQ1_M,
	"bf16":    sd.SDTypeBF16,

	"tq1_0": sd.SDTypeTQ1_0,
	"tq2_0": sd.SDTypeTQ2_0,

	"mxfp4":   sd.SDTypeMXFP4,
	"nvfp4":   sd.SDTypeNVFP4,
	"q1_0":    sd.SDTypeQ1_0,
	"default": sd.SDTypeCount,
}

SDTypeMap SDType mapping

View Source
var SampleMethodMap = map[string]sd.SampleMethod{
	"default":             -1,
	"euler":               sd.EulerSampleMethod,
	"euler_a":             sd.EulerASampleMethod,
	"heun":                sd.HeunSampleMethod,
	"dpm2":                sd.DPM2SampleMethod,
	"dpm++2s_a":           sd.DPMPP2SASampleMethod,
	"dpm++2m":             sd.DPMPP2MSampleMethod,
	"dpm++2mv2":           sd.DPMPP2Mv2SampleMethod,
	"ipndm":               sd.IPNDMSampleMethod,
	"ipndm_v":             sd.IPNDMSampleMethodV,
	"lcm":                 sd.LCMSampleMethod,
	"ddim_trailing":       sd.DDIMTrailingSampleMethod,
	"tcd":                 sd.TCDSampleMethod,
	"res_multistep":       sd.ResMultistepSampleMethod,
	"res_2s":              sd.Res2SSampleMethod,
	"er_sde":              sd.ERSDESampleMethod,
	"euler_cfg_pp":        sd.EulerCFGPPSampleMethod,
	"euler_a_cfg_pp":      sd.EulerACFGPPSampleMethod,
	"euler_ge":            sd.EulerGESampleMethod,
	"dpm++2m_sde":         sd.DPMPP2MSDESampleMethod,
	"dpm++2m_sde_bt":      sd.DPMPP2MSDEBTSampleMethod,
	"sample_method_count": sd.SampleMethodCount,
}

SampleMethodMap sampling method mapping

View Source
var SchedulerMap = map[string]sd.Scheduler{
	"default":         -1,
	"discrete":        sd.DiscreteScheduler,
	"karras":          sd.KarrasScheduler,
	"exponential":     sd.ExponentialScheduler,
	"ays":             sd.AYSScheduler,
	"gits":            sd.GITScheduler,
	"sgm_uniform":     sd.SGMUniformScheduler,
	"simple":          sd.SimpleScheduler,
	"smoothstep":      sd.SmoothstepScheduler,
	"kl_optimal":      sd.KLOptimalScheduler,
	"lcm":             sd.LCMScheduler,
	"bong_tangent":    sd.BongTangentScheduler,
	"ltx2":            sd.LTX2Scheduler,
	"logit_normal":    sd.LogitNormalScheduler,
	"flux2":           sd.Flux2Scheduler,
	"flux":            sd.FluxScheduler,
	"beta":            sd.BetaScheduler,
	"scheduler_count": sd.SchedulerCount,
}

SchedulerMap scheduler mapping

View Source
var VAEFormatMap = map[string]sd.SDVAEFormat{
	"auto":  sd.VAEFormatAuto,
	"flux":  sd.FluxVAEFormat,
	"sd3":   sd.SD3VAEFormat,
	"flux2": sd.Flux2VAEFormat,
	"wan":   sd.WanVAEFormat,
}

VAEFormatMap VAE format mapping (controls how the VAE weights are interpreted)

Functions

func Convert

func Convert(inputPath, vaePath, outputPath, outputType, tensorTypeRules string, convertName bool) error

Convert model conversion function, convert a model to gguf format. inputPath: Path to the input model. vaePath: Path to the vae. outputPath: Path to save the converted model. outputType: The weight type (default: auto). tensorTypeRules: Weight type per tensor pattern (example: "^vae\\\\.=f16,model\\\\.=q8_0")

func Load

func Load(libDir string) error

Load loads the stable-diffusion shared library from libDir. An empty libDir falls back to the OS default search path. It must be called once before creating a context or generating; it is idempotent and returns an error (never panics) when the library is absent or incompatible.

Types

type ContextParams

type ContextParams struct {
	ModelPath                   string     // Full model path
	ClipLPath                   string     // CLIP-L text encoder path
	ClipGPath                   string     // CLIP-G text encoder path
	ClipVisionPath              string     // CLIP Vision encoder path
	T5XXLPath                   string     // T5-XXL text encoder path
	LLMPath                     string     // LLM text encoder path (e.g., qwenvl2.5 for qwen-image, mistral-small3.2 for flux2)
	LLMVisionPath               string     // LLM Vision encoder path
	DiffusionModelPath          string     // Standalone diffusion model path
	HighNoiseDiffusionModelPath string     // Standalone high noise diffusion model path
	UncondDiffusionModelPath    string     // Standalone unconditional diffusion model path
	EmbeddingsConnectorsPath    string     // Embeddings connectors model path
	VAEPath                     string     // VAE model path
	AudioVAEPath                string     // Audio VAE model path (for audio-capable video models)
	TAESDPath                   string     // TAE-SD model path, uses Tiny AutoEncoder for fast decoding (low quality)
	ControlNetPath              string     // ControlNet model path
	IPAdapterPath               string     // IP-Adapter model path
	MotionModulePath            string     // Motion module model path (AnimateDiff)
	Embeddings                  *Embedding // Embedding information
	EmbeddingCount              uint32     // Number of embeddings
	PhotoMakerPath              string     // PhotoMaker model path
	PulidWeightsPath            string     // PuLID weights path
	TensorTypeRules             string     // Weight type rules per tensor pattern (e.g., "^vae\.=f16,model\.=q8_0")
	NThreads                    int32      // Number of threads to use for generation
	WType                       string     // Weight type (default: auto-detect from model file)
	RNGType                     string     // Random number generator type (default: "cuda")
	SamplerRNGType              string     // Sampler random number generator type (default: "cuda")
	Prediction                  string     // Prediction type override
	LoraApplyMode               string     // LoRA application mode (default: "auto")
	OffloadParamsToCPU          bool       // Keep weights in RAM to save VRAM, auto-load to VRAM when needed (translated to the params-backend assignment "*=cpu", as upstream's --offload-to-cpu now is)
	EnableMmap                  bool       // Whether to enable memory mapping
	KeepClipOnCPU               bool       // Keep CLIP on CPU (for low VRAM; translated to the backend assignment "te=cpu")
	KeepControlNetOnCPU         bool       // Keep ControlNet on CPU (for low VRAM; translated to the backend assignment "controlnet=cpu")
	KeepVAEOnCPU                bool       // Keep VAE on CPU (for low VRAM; translated to the backend assignment "vae=cpu")
	FlashAttn                   bool       // Use Flash attention across the whole model (significantly reduces memory usage)
	DiffusionFlashAttn          bool       // Use Flash attention in diffusion model (significantly reduces memory usage)
	TAEPreviewOnly              bool       // Prevent decoding final image with taesd (for preview="tae")
	DiffusionConvDirect         bool       // Use Conv2d direct in diffusion model
	VAEConvDirect               bool       // Use Conv2d direct in VAE model (should improve performance)
	ForceSDXLVAConvScale        bool       // Force conv scale on SDXL VAE
	VAEFormat                   string     // VAE weight format override: "auto" (default), "flux", "sd3", "flux2", "wan"
	MaxVRAM                     string     // GiB budget or backend assignment spec for graph-cut segmented param offload ("" = disabled, "-1" = auto)
	StreamLayers                bool       // Stream model weights from CPU during generation (residency+prefetch on top of MaxVRAM; no effect unless MaxVRAM is set)
	EagerLoad                   bool       // Load all params into the params backend at model-load time instead of lazily on first use
	Backend                     string     // Compute backend override or assignment spec (empty = library default)
	ParamsBackend               string     // Params/storage backend override or assignment spec (empty = library default)
	SplitMode                   string     // Weight distribution for multi-device modules: "layer" (default), "row", or per-module assignments e.g. "diffusion=row"
	AutoFit                     bool       // Automatically fit the model across available devices
	RPCServers                  string     // Comma-separated list of RPC servers (host:port) for offloading
	ModelArgs                   string     // Extra model args, key=value list (supports chroma_use_dit_mask, chroma_use_t5_mask, chroma_t5_mask_pad, qwen_image_zero_cond_t)
}

ContextParams context parameters structure for initializing Stable Diffusion context

type Embedding

type Embedding struct {
	Name string // Embedding name
	Path string // Embedding file path
}

Embedding embedding structure for defining model embeddings

type ImgGenParams

type ImgGenParams struct {
	Loras              *Lora             // LoRA parameters
	LoraCount          uint32            // Number of LoRAs
	Prompt             string            // Prompt to render
	NegativePrompt     string            // Negative prompt
	ClipSkip           int32             // Skip last layers of CLIP network (1 = no skip, 2 = skip one layer, <=0 = not specified)
	InitImagePath      string            // Initial image path for guidance
	RefImagesPath      []string          // Array of reference image paths for Flux Kontext models
	RefImagesCount     int32             // Number of reference images
	AutoResizeRefImage bool              // Whether to auto-resize reference images (translated to the ref-image arg "resize_before_vae=0" when false, as upstream's CLI does)
	IncreaseRefIndex   bool              // Whether to auto-increase index based on reference image list order (translated to the ref-image arg "ref_index_mode=increase", as upstream's CLI does)
	RefImageArgs       string            // Extra ref-image args, key=value list (advanced; appended after the translated flags above)
	MaskImagePath      string            // Inpainting mask image path
	Width              int32             // Image width (pixels)
	Height             int32             // Image height (pixels)
	CfgScale           float32           // Unconditional guidance scale.
	ImageCfgScale      float32           // Image guidance scale for inpaint or instruct-pix2pix models (default: same as `CfgScale`).
	DistilledGuidance  float32           // Distilled guidance scale for models with guidance input.
	SkipLayers         []int32           // Layers to skip for SLG steps (SLG will be enabled at step int([STEPS]x[START]) and disabled at int([STEPS]x[END])).
	SkipLayerStart     float32           // SLG enabling point.
	SkipLayerEnd       float32           // SLG disabling point.
	SlgScale           float32           // Skip layer guidance (SLG) scale, only for DiT models.
	Scheduler          string            // Denoiser sigma scheduler (default: discrete).
	SampleMethod       string            // Sampling method (default: euler for Flux/SD3/Wan, euler_a otherwise).
	SampleSteps        int32             // Number of sample steps.
	Eta                float32           // Eta in DDIM, only for DDIM and TCD.
	ShiftedTimestep    int32             // Shift timestep for NitroFusion models, default: 0, recommended N for NitroSD-Realism around 250 and 500 for NitroSD-Vibrant.
	CustomSigmas       []float32         // Custom sigma values for the sampler, comma-separated (e.g. "14.61,7.8,3.5,0.0").
	Strength           float32           // Noise/denoise strength (range [0.0, 1.0])
	Seed               int64             // RNG seed (< 0 for random seed)
	BatchCount         int32             // Number of images to generate
	ControlImagePath   string            // Control condition image path for ControlNet
	ControlStrength    float32           // Strength to apply ControlNet
	PMParams           *PMParams         // PhotoMaker parameters
	VAETilingParams    sd.SDTilingParams // VAE tiling parameters for reducing memory usage
	CacheParams        sd.SDCacheParams  // Cache parameters for DiT models
	FlowShift          float32           // Shift value for flow models (e.g. SD3.x, Flux); 0 = library default
	ExtraSampleArgs    string            // Extra model-specific sampler arguments (advanced)
	CircularX          bool              // Enable circular padding on X axis (moved here from ContextParams by the master-802 upstream resync)
	CircularY          bool              // Enable circular padding on Y axis (moved here from ContextParams by the master-802 upstream resync)

	// Hi-res fix: optionally run a second high-resolution refinement pass.
	HiresEnabled           bool      // Enable hi-res fix
	HiresUpscaler          string    // Hi-res upscaler (see HiresUpscalerMap, e.g. "latent", "model"); empty = "none"
	HiresModelPath         string    // Upscaler model path (for HiresUpscaler == "model")
	HiresScale             float32   // Upscale factor (used when target dimensions are unset)
	HiresTargetWidth       int32     // Explicit hi-res target width (overrides HiresScale)
	HiresTargetHeight      int32     // Explicit hi-res target height (overrides HiresScale)
	HiresSteps             int32     // Sample steps for the hi-res pass
	HiresDenoisingStrength float32   // Denoising strength for the hi-res pass
	HiresUpscaleTileSize   int32     // Tile size for the hi-res upscale
	HiresCustomSigmas      []float32 // Custom sigmas for the hi-res pass
}

ImgGenParams image generation parameters structure for defining image generation related parameters

type Lora

type Lora struct {
	IsHighNoise bool    // Whether it's a high noise LoRA
	Multiplier  float32 // LoRA multiplier
	Path        string  // LoRA file path
}

Lora LoRA structure for defining LoRA model parameters

type PMParams

type PMParams struct {
	IDImages      *sd.SDImage // ID images pointer
	IDImagesCount int32       // Number of ID images
	IDEmbedPath   string      // PhotoMaker v2 ID embedding path
	StyleStrength float32     // Strength to keep PhotoMaker input identity
}

PMParams PhotoMaker parameters structure for defining PhotoMaker related parameters

type StableDiffusion

type StableDiffusion struct {
	// contains filtered or unexported fields
}

StableDiffusion Stable Diffusion structure containing context pointer

func NewStableDiffusion

func NewStableDiffusion(ctxParams *ContextParams) (*StableDiffusion, error)

NewStableDiffusion creates a stable diffusion instance

func (*StableDiffusion) Free

func (sDiffusion *StableDiffusion) Free()

Free frees the stable diffusion context

func (*StableDiffusion) GenerateImage

func (sDiffusion *StableDiffusion) GenerateImage(imgGenParams *ImgGenParams, newImagePath string) error

GenerateImage generates image from text or image

func (*StableDiffusion) GenerateVideo

func (sDiffusion *StableDiffusion) GenerateVideo(vidGenParams *VidGenParams, newVideoPath string) error

GenerateVideo generates video

type Upscaler

type Upscaler struct {
	// contains filtered or unexported fields
}

func NewUpscaler

func NewUpscaler(params *UpscalerParams) *Upscaler

NewUpscaler creates a new upscaler context

func (*Upscaler) Upscale

func (us *Upscaler) Upscale(inputImagePath string, upscaleFactor uint32, outputImagePath string) error

Upscale upscaling function

type UpscalerParams

type UpscalerParams struct {
	EsrganPath         string // ESRGAN model path
	OffloadParamsToCPU bool   // Whether to save parameters to CPU (translated to the params-backend assignment "*=cpu"; upstream removed the dedicated flag)
	Direct             bool   // Whether to use direct mode
	NThreads           int    // Number of threads to use
	TileSize           int    // Tile size
	Backend            string // Compute backend override (empty = library default)
	ParamsBackend      string // Params/storage backend override or assignment spec (empty = library default)
}

type VidGenParams

type VidGenParams struct {
	Loras             *Lora    // LoRA parameters
	LoraCount         uint32   // Number of LoRAs
	Prompt            string   // Prompt to render
	NegativePrompt    string   // Negative prompt
	ClipSkip          int32    // Skip last layers of CLIP network (1 = no skip, 2 = skip one layer, <=0 = not specified)
	InitImagePath     string   // Initial image path for starting generation
	EndImagePath      string   // End image path for ending generation (required for flf2v)
	ControlFramesPath []string // Array of control frame image paths for video
	ControlFramesSize int32    // Control frame size
	Width             int32    // Video width (pixels)
	Height            int32    // Video height (pixels)

	CfgScale          float32   // Unconditional guidance scale.
	ImageCfgScale     float32   // Image guidance scale for inpaint or instruct-pix2pix models (default: same as `CfgScale`).
	DistilledGuidance float32   // Distilled guidance scale for models with guidance input.
	SkipLayers        []int32   // Layers to skip for SLG steps (SLG will be enabled at step int([STEPS]x[START]) and disabled at int([STEPS]x[END])).
	SkipLayerStart    float32   // SLG enabling point.
	SkipLayerEnd      float32   // SLG disabling point.
	SlgScale          float32   // Skip layer guidance (SLG) scale, only for DiT models.
	Scheduler         string    // Denoiser sigma scheduler (default: discrete).
	SampleMethod      string    // Sampling method (default: euler for Flux/SD3/Wan, euler_a otherwise).
	SampleSteps       int32     // Number of sample steps.
	Eta               float32   // Eta in DDIM, only for DDIM and TCD.
	ShiftedTimestep   int32     // Shift timestep for NitroFusion models, default: 0, recommended N for NitroSD-Realism around 250 and 500 for NitroSD-Vibrant.
	CustomSigmas      []float32 // Custom sigma values for the sampler, comma-separated (e.g. "14.61,7.8,3.5,0.0").
	FlowShift         float32   // Shift value for flow models (e.g. SD3.x, Wan); 0 = library default.

	HighNoiseCfgScale          float32   // High noise diffusion model equivalent of `cfg_scale`.
	HighNoiseImageCfgScale     float32   // High noise diffusion model equivalent of `image_cfg_scale`.
	HighNoiseDistilledGuidance float32   // High noise diffusion model equivalent of `guidance`.
	HighNoiseSkipLayers        []int32   // High noise diffusion model equivalent of `skip_layers`.
	HighNoiseSkipLayerStart    float32   // High noise diffusion model equivalent of `skip_layer_start`.
	HighNoiseSkipLayerEnd      float32   // High noise diffusion model equivalent of `skip_layer_end`.
	HighNoiseSlgScale          float32   // High noise diffusion model equivalent of `slg_scale`.
	HighNoiseScheduler         string    // High noise diffusion model equivalent of `scheduler`.
	HighNoiseSampleMethod      string    // High noise diffusion model equivalent of `sample_method`.
	HighNoiseSampleSteps       int32     // High noise diffusion model equivalent of `sample_steps` (default: -1 = auto).
	HighNoiseEta               float32   // High noise diffusion model equivalent of `eta`.
	HighNoiseShiftedTimestep   int32     // Shift timestep for NitroFusion models, default: 0, recommended N for NitroSD-Realism around 250 and 500 for NitroSD-Vibrant.
	HighNoiseCustomSigmas      []float32 // Custom sigma values for the sampler, comma-separated (e.g. "14.61,7.8,3.5,0.0").
	HighNoiseFlowShift         float32   // High noise diffusion model equivalent of `FlowShift`.

	MOEBoundary  float32          // Timestep boundary for Wan2.2 MoE models
	Strength     float32          // Noise/denoise strength (range [0.0, 1.0])
	Seed         int64            // RNG seed (< 0 for random seed)
	VideoFrames  int32            // Number of video frames to generate
	VaceStrength float32          // Wan VACE strength
	CacheParams  sd.SDCacheParams // Cache parameters for DiT models
	CircularX    bool             // Enable circular padding on X axis (moved here from ContextParams by the master-802 upstream resync)
	CircularY    bool             // Enable circular padding on Y axis (moved here from ContextParams by the master-802 upstream resync)
}

VidGenParams video generation parameters structure for defining video generation related parameters

Directories

Path Synopsis
examples
txt2img command
txt2vid command
pkg
sd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL