sd

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SDTypeF32 SDType = iota
	SDTypeF16
	SDTypeQ4_0
	SDTypeQ4_1
	// SDTypeQ4_2 = 4, support has been removed
	// SDTypeQ4_3 = 5, support has been removed
	SDTypeQ5_0    = 6
	SDTypeQ5_1    = 7
	SDTypeQ8_0    = 8
	SDTypeQ8_1    = 9
	SDTypeQ2_K    = 10
	SDTypeQ3_K    = 11
	SDTypeQ4_K    = 12
	SDTypeQ5_K    = 13
	SDTypeQ6_K    = 14
	SDTypeQ8_K    = 15
	SDTypeIQ2_XXS = 16
	SDTypeIQ2_XS  = 17
	SDTypeIQ3_XXS = 18
	SDTypeIQ1_S   = 19
	SDTypeIQ4_NL  = 20
	SDTypeIQ3_S   = 21
	SDTypeIQ2_S   = 22
	SDTypeIQ4_XS  = 23
	SDTypeI8      = 24
	SDTypeI16     = 25
	SDTypeI32     = 26
	SDTypeI64     = 27
	SDTypeF64     = 28
	SDTypeIQ1_M   = 29
	SDTypeBF16    = 30
	// SDTypeQ4_0_4_4 = 31, support has been removed from gguf files
	// SDTypeQ4_0_4_8 = 32,
	// SDTypeQ4_0_8_8 = 33,
	SDTypeTQ1_0 = 34
	SDTypeTQ2_0 = 35
	// SDTypeIQ4_NL_4_4 = 36,
	// SDTypeIQ4_NL_4_8 = 37,
	// SDTypeIQ4_NL_8_8 = 38,
	SDTypeMXFP4 = 39
	SDTypeCount = 40
)

Variables

This section is empty.

Functions

func CGoString

func CGoString(cStr *uint8) string

Helper function: Convert C string to Go string

func CString

func CString(str string) *uint8

Helper function: Convert Go string to C string

func CacheParamsInit

func CacheParamsInit(params *SDCacheParams)

CacheParamsInit initializes cache parameters

func CleanupTempDir

func CleanupTempDir(tempDir string) error

CleanupTempDir cleans up temporary directory

func Commit

func Commit() string

Commit gets commit information

func ContextParamsInit

func ContextParamsInit(params *SDContextParams)

ContextParamsInit initializes context parameters

func ContextParamsToStr

func ContextParamsToStr(params *SDContextParams) string

ContextParamsToStr converts context parameters to string

func Convert

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

Convert converts model

func EncodeVideo

func EncodeVideo(inputDir, outputPath string, framerate int) error

EncodeVideo encodes PNG frame sequence to video using FFmpeg

func FreeCString

func FreeCString(cStr *uint8)

Helper function: Free C string

func GetCpuAVX

func GetCpuAVX() string

GetCpuAVX gets CPU AVX instruction set

func GetGPUName

func GetGPUName() (string, error)

GetGPUName gets GPU name

func GetNumPhysicalCores

func GetNumPhysicalCores() int

GetNumPhysicalCores gets the number of physical cores

func GetSDLibPath

func GetSDLibPath(libName string) string

GetSDLibPath gets SD library path

func GetSystemInfo

func GetSystemInfo() string

GetSystemInfo gets system information

func GetVulkanGPU

func GetVulkanGPU() (string, error)

GetVulkanGPU gets Vulkan GPU information

func ImgGenParamsInit

func ImgGenParamsInit(params *SDImgGenParams)

ImgGenParamsInit initializes image generation parameters

func ImgGenParamsToStr

func ImgGenParamsToStr(params *SDImgGenParams) string

ImgGenParamsToStr converts image generation parameters to string

func LoraApplyModeName

func LoraApplyModeName(mode LoraApplyMode) string

LoraApplyModeName gets LoRA apply mode name

func PredictionName

func PredictionName(prediction Prediction) string

PredictionName gets prediction type name

func PreprocessCanny

func PreprocessCanny(image SDImage, highThreshold, lowThreshold, weak, strong float32, inverse bool) bool

PreprocessCanny preprocesses Canny edge detection

func PreviewName

func PreviewName(preview Preview) string

PreviewName gets preview type name

func RNGTypeName

func RNGTypeName(rngType RngType) string

RNGTypeName gets RNG type name

func SDTypeName

func SDTypeName(typ SDType) string

SDTypeName gets SD type name

func SampleMethodName

func SampleMethodName(method SampleMethod) string

SampleMethodName gets sample method name

func SampleParamsInit

func SampleParamsInit(params *SDSampleParams)

SampleParamsInit initializes sample parameters

func SampleParamsToStr

func SampleParamsToStr(params *SDSampleParams) string

SampleParamsToStr converts sample parameters to string

func SaveFrames

func SaveFrames(frames []SDImage, outputDir string) error

SaveFrames saves all video frames as PNG files

func SaveImage

func SaveImage(img *SDImage, path string) error

SaveImage saves SDImage as PNG file

func SchedulerName

func SchedulerName(scheduler Scheduler) string

SchedulerName gets scheduler name

func SetLogCallback

func SetLogCallback(cb SDLogCallbackType, data interface{})

SetLogCallback sets log callback

func SetPreviewCallback

func SetPreviewCallback(cb func(step int, frameCount int, frames []SDImage, isNoisy bool, data interface{}), mode Preview, interval int, denoised bool, noisy bool, data interface{})

SetPreviewCallback sets preview callback

func SetProgressCallback

func SetProgressCallback(cb func(step int, steps int, time float32, data interface{}), data interface{})

SetProgressCallback sets progress callback

func Version

func Version() string

Version gets version information

func VidGenParamsInit

func VidGenParamsInit(params *SDVidGenParams)

VidGenParamsInit initializes video generation parameters

Types

type LoraApplyMode

type LoraApplyMode int32
const (
	LoraApplyAuto LoraApplyMode = iota
	LoraApplyImmediately
	LoraApplyAtRuntime
	LoraApplyModeCount
)

func StrToLoraApplyMode

func StrToLoraApplyMode(str string) LoraApplyMode

StrToLoraApplyMode converts string to LoRA apply mode

type Prediction

type Prediction int32
const (
	EPSPred Prediction = iota
	VPred
	EDMVPred
	FlowPred
	FluxFlowPred
	Flux2FlowPred
	PredictionCount
)

func StrToPrediction

func StrToPrediction(str string) Prediction

StrToPrediction converts string to prediction type

type Preview

type Preview int32
const (
	PreviewNone Preview = iota
	PreviewProj
	PreviewTAE
	PreviewVAE
	PreviewCount
)

func StrToPreview

func StrToPreview(str string) Preview

StrToPreview converts string to preview type

type RngType

type RngType int32
const (
	DefaultRNG RngType = iota
	CUDARNG
	CPURNG
	RNGTypeCount
)

func StrToRNGType

func StrToRNGType(str string) RngType

StrToRNGType converts string to RNG type

type SDCacheMode

type SDCacheMode int32
const (
	SDCacheDisabled SDCacheMode = iota
	SDCacheEasycache
	SDCacheUcache
	SDCacheDbcache
	SDCacheTaylorseer
	SDCacheCacheDit
)

type SDCacheParams

type SDCacheParams struct {
	Mode                     SDCacheMode
	ReuseThreshold           float32
	StartPercent             float32
	EndPercent               float32
	ErrorDecayRate           float32
	UseRelativeThreshold     bool
	ResetErrorOnCompute      bool
	FnComputeBlocks          int32
	BnComputeBlocks          int32
	ResidualDiffThreshold    float32
	MaxWarmupSteps           int32
	MaxCachedSteps           int32
	MaxContinuousCachedSteps int32
	TaylorseerNDerivatives   int32
	TaylorseerSkipInterval   int32
	ScmMask                  *uint8
	ScmPolicyDynamic         bool
}

type SDContext

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

Define context types

func NewContext

func NewContext(params *SDContextParams) *SDContext

NewContext creates a new context

func (*SDContext) Free

func (ctx *SDContext) Free()

FreeContext frees context

func (*SDContext) GenerateImage

func (ctx *SDContext) GenerateImage(params *SDImgGenParams) *SDImage

GenerateImage generates image

func (*SDContext) GenerateVideo

func (ctx *SDContext) GenerateVideo(params *SDVidGenParams) ([]SDImage, int)

GenerateVideo generates video

func (*SDContext) GetDefaultSampleMethod

func (ctx *SDContext) GetDefaultSampleMethod() SampleMethod

GetDefaultSampleMethod gets default sample method

func (*SDContext) GetDefaultScheduler

func (ctx *SDContext) GetDefaultScheduler(sampleMethod SampleMethod) Scheduler

GetDefaultScheduler gets default scheduler

type SDContextParams

type SDContextParams struct {
	ModelPath                   *uint8
	ClipLPath                   *uint8
	ClipGPath                   *uint8
	ClipVisionPath              *uint8
	T5XXLPath                   *uint8
	LLMPath                     *uint8
	LLMVisionPath               *uint8
	DiffusionModelPath          *uint8
	HighNoiseDiffusionModelPath *uint8
	VAEPath                     *uint8
	TAESDPath                   *uint8
	ControlNetPath              *uint8
	Embeddings                  *SDEmbedding
	EmbeddingCount              uint32
	PhotoMakerPath              *uint8
	TensorTypeRules             *uint8
	VAEDecodeOnly               bool
	FreeParamsImmediately       bool
	NThreads                    int32
	WType                       SDType
	RNGType                     RngType
	SamplerRNGType              RngType
	Prediction                  Prediction
	LoraApplyMode               LoraApplyMode
	OffloadParamsToCPU          bool
	EnableMmap                  bool
	KeepClipOnCPU               bool
	KeepControlNetOnCPU         bool
	KeepVAEOnCPU                bool
	DiffusionFlashAttn          bool
	TAEPreviewOnly              bool
	DiffusionConvDirect         bool
	VAEConvDirect               bool
	CircularX                   bool
	CircularY                   bool
	ForceSDXLVAConvScale        bool
	ChromaUseDitMask            bool
	ChromaUseT5Mask             bool
	ChromaT5MaskPad             int32
	QwenImageZeroCondT          bool
	FlowShift                   float32
}

type SDEmbedding

type SDEmbedding struct {
	Name *uint8
	Path *uint8
}

type SDGuidanceParams

type SDGuidanceParams struct {
	TxtCfg            float32
	ImgCfg            float32
	DistilledGuidance float32
	SLG               SDSLGParams
}

type SDImage

type SDImage struct {
	Width   uint32
	Height  uint32
	Channel uint32
	Data    *uint8
}

func GenerateImageFromPath

func GenerateImageFromPath(imagePath string) SDImage

GenerateImageFromPath generates SDImage from path

func GenerateImagesFromPaths

func GenerateImagesFromPaths(path []string) *SDImage

func LoadImage

func LoadImage(path string) (SDImage, error)

LoadImage loads image from file and converts to SDImage format

type SDImgGenParams

type SDImgGenParams struct {
	Loras              *SDLora
	LoraCount          uint32
	Prompt             *uint8
	NegativePrompt     *uint8
	ClipSkip           int32
	InitImage          SDImage
	RefImages          *SDImage
	RefImagesCount     int32
	AutoResizeRefImage bool
	IncreaseRefIndex   bool
	MaskImage          SDImage
	Width              int32
	Height             int32
	SampleParams       SDSampleParams
	Strength           float32
	Seed               int64
	BatchCount         int32
	ControlImage       SDImage
	ControlStrength    float32
	PMParams           SDPMParams
	VAETilingParams    SDTilingParams
	Cache              SDCacheParams
}

type SDLogCallback

type SDLogCallback func(level SDLogLevel, text *uint8, data unsafe.Pointer)

Define callback function types

type SDLogCallbackType

type SDLogCallbackType func(level SDLogLevelType, text string, data interface{})

type SDLogLevel

type SDLogLevel int32
const (
	SDLogDebug SDLogLevel = iota
	SDLogInfo
	SDLogWarn
	SDLogError
)

type SDLogLevelType

type SDLogLevelType int32

Wrapper functions

type SDLora

type SDLora struct {
	IsHighNoise bool
	Multiplier  float32
	Path        *uint8
}

type SDPMParams

type SDPMParams struct {
	IDImages      *SDImage
	IDImagesCount int32
	IDEmbedPath   *uint8
	StyleStrength float32
}

type SDPreviewCallback

type SDPreviewCallback func(step int32, frameCount int32, frames *SDImage, isNoisy bool, data unsafe.Pointer)

type SDProgressCallback

type SDProgressCallback func(step int32, steps int32, time float32, data unsafe.Pointer)

type SDSLGParams

type SDSLGParams struct {
	Layers     *int32
	LayerCount uintptr
	LayerStart float32
	LayerEnd   float32
	Scale      float32
}

type SDSampleParams

type SDSampleParams struct {
	Guidance          SDGuidanceParams
	Scheduler         Scheduler
	SampleMethod      SampleMethod
	SampleSteps       int32
	Eta               float32
	ShiftedTimestep   int32
	CustomSigmas      *float32
	CustomSigmasCount int32
}

type SDTilingParams

type SDTilingParams struct {
	Enabled       bool
	TileSizeX     int32
	TileSizeY     int32
	TargetOverlap float32
	RelSizeX      float32
	RelSizeY      float32
}

Define structs

type SDType

type SDType int32

func StrToSDType

func StrToSDType(str string) SDType

StrToSDType converts string to SD type

type SDVidGenParams

type SDVidGenParams struct {
	Loras                 *SDLora
	LoraCount             uint32
	Prompt                *uint8
	NegativePrompt        *uint8
	ClipSkip              int32
	InitImage             SDImage
	EndImage              SDImage
	ControlFrames         *SDImage
	ControlFramesSize     int32
	Width                 int32
	Height                int32
	SampleParams          SDSampleParams
	HighNoiseSampleParams SDSampleParams
	MOEBoundary           float32
	Strength              float32
	Seed                  int64
	VideoFrames           int32
	VaceStrength          float32
	Cache                 SDCacheParams
}

type SampleMethod

type SampleMethod int32
const (
	EulerSampleMethod SampleMethod = iota
	EulerASampleMethod
	HeunSampleMethod
	DPM2SampleMethod
	DPMPP2SASampleMethod
	DPMPP2MSampleMethod
	DPMPP2Mv2SampleMethod
	IPNDMSampleMethod
	IPNDMSampleMethodV
	LCMSampleMethod
	DDIMTrailingSampleMethod
	TCDSampleMethod
	SampleMethodCount
)

func StrToSampleMethod

func StrToSampleMethod(str string) SampleMethod

StrToSampleMethod converts string to sample method

type Scheduler

type Scheduler int32
const (
	DiscreteScheduler Scheduler = iota
	KarrasScheduler
	ExponentialScheduler
	AYSScheduler
	GITScheduler
	SGMUniformScheduler
	SimpleScheduler
	SmoothstepScheduler
	KLOptimalScheduler
	LCMScheduler
	SchedulerCount
)

func StrToScheduler

func StrToScheduler(str string) Scheduler

StrToScheduler converts string to scheduler

type UpscalerContext

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

func NewUpscalerContext

func NewUpscalerContext(esrganPath string, offloadParamsToCPU bool, direct bool, nThreads int, tileSize int) *UpscalerContext

NewUpscalerContext creates a new upscaler context

func (*UpscalerContext) Free

func (ctx *UpscalerContext) Free()

FreeUpscalerContext frees upscaler context

func (*UpscalerContext) GetUpscaleFactor

func (ctx *UpscalerContext) GetUpscaleFactor() int

GetUpscaleFactor gets upscale factor

func (*UpscalerContext) Upscale

func (ctx *UpscalerContext) Upscale(inputImage SDImage, upscaleFactor uint32) SDImage

Upscale upscales image

Jump to

Keyboard shortcuts

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