PitchHut logo
High-performance diffusion model inference in pure Go.
Pitch

gosd provides pure Go bindings for stable-diffusion.cpp, allowing seamless integration of image and video generation to Go applications. With features like high-resolution upscaling and hardware-accelerated inference, it delivers impressive performance without the complexity of C/C++.

Description

gosd: Pure Go Bindings for High-Performance Image Generation

gosd is a comprehensive suite of pure Go bindings designed for seamless integration with stable-diffusion.cpp, enabling high-performance diffusion model inference. The library allows for the effortless generation and editing of both images and videos while maintaining minimal performance overhead compared to traditional C/C++ implementations.

Key Features

  • Image and Video Generation: Effortlessly create stunning visuals with powerful diffusion models.
  • Image Editing: Utilize sophisticated techniques to enhance images seamlessly.
  • High-resolution Upscaling: Incorporate Neural ESRGAN models and latent-space methods to improve image quality.
  • Callback Support: Implement progressive previews during inference to monitor generation in real-time.
  • Model Conversion: Easily convert models to SafeTensors and GGUF formats, with options for VAE merging and tensor type rules.
  • Hardware Acceleration: Leverage various hardware backends, including CUDA, Metal, Vulkan, and ROCm, for optimal performance.

Quick Start

Integrating gosd into Go projects unlocks a wealth of possibilities for image and video creation. Below is a simplified Go code snippet demonstrating how to generate an image:

package main

import sd "github.com/l8bloom/gosd/pkg/gosd"

func main() {
    // Load the dynamic libraries
    if err := sd.Load(); err != nil {
        panic(err.Error())
    }

    // Create and configure the inference context
    ctxParams := sd.ContextParamsInit()
    ctxParams.DiffusionModelPath = "/tmp/stable.diffusion/flux-2-klein-9b-Q8_0.gguf"
    ctxParams.VAEPath = "/tmp/stable.diffusion/diffusion_pytorch_model.safetensors"
    ctxParams.LLMPath = "/tmp/stable.diffusion/Qwen3-8B-Q8_0.gguf"

    ctx := sd.NewContext(ctxParams)
    defer sd.FreeCtx(ctx)

    // Initialize image generation parameters
    imgParams := sd.ImageGenParamsInit()
    imgParams.Prompt = "An orange cat on palm beach playing with oranges."
    imgParams.NegativePrompt = "mascots, watermark, signature"

    genImage := sd.GenerateImage(ctx, imgParams)
    genImage.SavePNG("output.png")
}

Advanced Usage and Examples

The examples directory includes additional snippets showcasing classic use cases, such as generating images with previews and advanced preprocessing techniques, including Canny Edge Detection for precise AI model guidance.

Environment Variables

Set the GOSD_DYN_LIB environment variable to indicate the root of the stable-diffusion shared libraries for correct loading. For Linux, update the OS search path like this:

export LD_LIBRARY_PATH=$GOSD_DYN_LIB:$LD_LIBRARY_PATH

Portability and Compatibility

gosd supports multiple platforms, regularly testing CPU-based inference across Linux, Windows, and macOS while supporting GPU acceleration with Vulkan and AMD ROCm stacks. The following compatibility chart summarizes support:

PlatformCPU (AMD64)CPU (ARM64)GPU (Vulkan 1.4.3)GPU (ROCm 7.2.1)
Linux
Windows--
macOS---

For more information and insights into additional features, users can explore the stable-diffusion.cpp documentation.

0 comments

No comments yet.

Sign in to be the first to comment.