2584940016
release / setup-environment (push) Has been cancelled
release / windows-depends (amd64, , https://sdk.lunarg.com/sdk/download/1.4.321.1/windows/vulkansdk-windows-X64-1.4.321.1.exe, windows, Vulkan, vulkan) (push) Has been cancelled
release / windows-depends (amd64, -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="-parallel-jobs=4 -Wno-ignored-attributes -Wno-deprecated-pragma" -DCMAKE_CXX_FLAGS="-parallel-jobs=4 -Wno-ignored-attributes -Wno-deprecated-pragma", https:/… (push) Has been cancelled
release / windows-depends (amd64, ["cudart" "nvcc" "cublas" "cublas_dev" "crt" "nvvm" "nvptxcompiler"], 13.0, , https://developer.download.nvidia.com/compute/cuda/13.0.0/local_installers/cuda_13.0.0_windows.exe, windows, CUDA 13) (push) Has been cancelled
release / windows-depends (amd64, ["cudart" "nvcc" "cublas" "cublas_dev"], 12.8, , https://developer.download.nvidia.com/compute/cuda/12.8.0/local_installers/cuda_12.8.0_571.96_windows.exe, windows, CUDA 12) (push) Has been cancelled
release / windows-depends (amd64, windows, CPU) (push) Has been cancelled
release / darwin-build (push) Has been cancelled
release / windows-build (amd64, x86_64, windows) (push) Has been cancelled
release / windows-build (arm64, aarch64, windows) (push) Has been cancelled
release / windows-app (push) Has been cancelled
release / linux-build (amd64, linux, archive) (push) Has been cancelled
release / linux-build (amd64, linux, rocm) (push) Has been cancelled
release / linux-build (arm64, linux, archive) (push) Has been cancelled
release / docker-build-push (amd64, CGO_CFLAGS
CGO_CXXFLAGS
GOFLAGS
, linux) (push) Has been cancelled
release / docker-build-push (amd64, CGO_CFLAGS
CGO_CXXFLAGS
GOFLAGS
FLAVOR=rocm
, linux, -rocm) (push) Has been cancelled
release / docker-build-push (arm64, CGO_CFLAGS
CGO_CXXFLAGS
GOFLAGS
, linux) (push) Has been cancelled
release / docker-merge-push () (push) Has been cancelled
release / docker-merge-push (-rocm) (push) Has been cancelled
release / release (push) Has been cancelled
103 lines
3.3 KiB
Go
103 lines
3.3 KiB
Go
// Package imagegen provides experimental image generation capabilities for Ollama.
|
|
//
|
|
// This package is in x/ because the tensor model storage format is under development.
|
|
// The goal is to integrate these capabilities into the main Ollama packages once
|
|
// the format is stable.
|
|
//
|
|
// TODO (jmorganca): Integrate into main packages when stable:
|
|
// - CLI commands → cmd/
|
|
// - API endpoints → api/
|
|
// - Model creation → server/
|
|
package imagegen
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
// GB is a convenience constant for gigabytes.
|
|
const GB = 1024 * 1024 * 1024
|
|
|
|
// SupportedBackends lists the backends that support image generation.
|
|
var SupportedBackends = []string{"metal", "cuda", "cpu"}
|
|
|
|
// modelVRAMEstimates maps pipeline class names to their estimated VRAM requirements.
|
|
var modelVRAMEstimates = map[string]uint64{
|
|
"ZImagePipeline": 21 * GB, // ~21GB for Z-Image (text encoder + transformer + VAE)
|
|
"FluxPipeline": 21 * GB, // ~21GB for Flux (same architecture)
|
|
"QwenImagePipeline": 80 * GB, // TODO: verify actual requirements, using conservative estimate for now
|
|
}
|
|
|
|
// CheckPlatformSupport validates that image generation is supported on the current platform.
|
|
// Returns nil if supported, or an error describing why it's not supported.
|
|
func CheckPlatformSupport() error {
|
|
switch runtime.GOOS {
|
|
case "darwin":
|
|
// macOS: Metal is supported via MLX
|
|
if runtime.GOARCH != "arm64" {
|
|
return fmt.Errorf("image generation on macOS requires Apple Silicon (arm64), got %s", runtime.GOARCH)
|
|
}
|
|
return nil
|
|
case "linux", "windows":
|
|
// Linux/Windows: CUDA support (requires mlx or cuda build)
|
|
// The actual backend availability is checked at runtime
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("image generation is not supported on %s", runtime.GOOS)
|
|
}
|
|
}
|
|
|
|
// CheckMemoryRequirements validates that there's enough memory for image generation.
|
|
// Returns nil if memory is sufficient, or an error if not.
|
|
func CheckMemoryRequirements(modelName string, availableMemory uint64) error {
|
|
required := EstimateVRAM(modelName)
|
|
if availableMemory < required {
|
|
return fmt.Errorf("insufficient memory for image generation: need %d GB, have %d GB",
|
|
required/GB, availableMemory/GB)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ResolveModelName checks if a model name is a known image generation model.
|
|
// Returns the normalized model name if found, empty string otherwise.
|
|
func ResolveModelName(modelName string) string {
|
|
manifest, err := LoadManifest(modelName)
|
|
if err == nil && manifest.HasTensorLayers() {
|
|
return modelName
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// EstimateVRAM returns the estimated VRAM needed for an image generation model.
|
|
// Returns a conservative default of 21GB if the model type cannot be determined.
|
|
func EstimateVRAM(modelName string) uint64 {
|
|
manifest, err := LoadManifest(modelName)
|
|
if err != nil {
|
|
return 21 * GB
|
|
}
|
|
|
|
data, err := manifest.ReadConfig("model_index.json")
|
|
if err != nil {
|
|
return 21 * GB
|
|
}
|
|
|
|
// Parse just the class name
|
|
var index struct {
|
|
ClassName string `json:"_class_name"`
|
|
}
|
|
if err := json.Unmarshal(data, &index); err != nil {
|
|
return 21 * GB
|
|
}
|
|
|
|
if estimate, ok := modelVRAMEstimates[index.ClassName]; ok {
|
|
return estimate
|
|
}
|
|
return 21 * GB
|
|
}
|
|
|
|
// HasTensorLayers checks if the given model has tensor layers.
|
|
func HasTensorLayers(modelName string) bool {
|
|
return ResolveModelName(modelName) != ""
|
|
}
|