Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
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
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).
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
var RNGTypeMap = map[string]sd.RngType{ "default": sd.DefaultRNG, "cuda": sd.CUDARNG, "cpu": sd.CPURNG, "type_count": sd.RNGTypeCount, }
RNGTypeMap RNG type mapping
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
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
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
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")
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 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
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