Skip to content

Commit 580687d

Browse files
authored
feat: remove stablediffusion-ggml from main binary (#5861)
* feat: split stablediffusion-ggml from main binary Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Test CI Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Adapt ci tests Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Try to support nvidial4t Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Latest fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 1929eb2 commit 580687d

File tree

14 files changed

+297
-59
lines changed

14 files changed

+297
-59
lines changed

.github/workflows/backend.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,103 @@ jobs:
648648
backend: "llama-cpp"
649649
dockerfile: "./backend/Dockerfile.llama-cpp"
650650
context: "./"
651+
- build-type: 'vulkan'
652+
cuda-major-version: ""
653+
cuda-minor-version: ""
654+
platforms: 'linux/amd64'
655+
tag-latest: 'true'
656+
tag-suffix: '-gpu-vulkan-llama-cpp'
657+
runs-on: 'ubuntu-latest'
658+
base-image: "ubuntu:22.04"
659+
skip-drivers: 'false'
660+
backend: "llama-cpp"
661+
dockerfile: "./backend/Dockerfile.llama-cpp"
662+
context: "./"
663+
# Stablediffusion-ggml
664+
- build-type: ''
665+
cuda-major-version: ""
666+
cuda-minor-version: ""
667+
platforms: 'linux/amd64'
668+
tag-latest: 'true'
669+
tag-suffix: '-cpu-stablediffusion-ggml'
670+
runs-on: 'ubuntu-latest'
671+
base-image: "ubuntu:22.04"
672+
skip-drivers: 'false'
673+
backend: "stablediffusion-ggml"
674+
dockerfile: "./backend/Dockerfile.go"
675+
context: "./"
676+
- build-type: 'cublas'
677+
cuda-major-version: "12"
678+
cuda-minor-version: "0"
679+
platforms: 'linux/amd64'
680+
tag-latest: 'true'
681+
tag-suffix: '-gpu-nvidia-cuda-12-stablediffusion-ggml'
682+
runs-on: 'ubuntu-latest'
683+
base-image: "ubuntu:22.04"
684+
skip-drivers: 'false'
685+
backend: "stablediffusion-ggml"
686+
dockerfile: "./backend/Dockerfile.go"
687+
context: "./"
688+
- build-type: 'cublas'
689+
cuda-major-version: "11"
690+
cuda-minor-version: "7"
691+
platforms: 'linux/amd64'
692+
tag-latest: 'true'
693+
tag-suffix: '-gpu-nvidia-cuda-11-stablediffusion-ggml'
694+
runs-on: 'ubuntu-latest'
695+
base-image: "ubuntu:22.04"
696+
skip-drivers: 'false'
697+
backend: "stablediffusion-ggml"
698+
dockerfile: "./backend/Dockerfile.go"
699+
context: "./"
700+
- build-type: 'sycl_f32'
701+
cuda-major-version: ""
702+
cuda-minor-version: ""
703+
platforms: 'linux/amd64'
704+
tag-latest: 'true'
705+
tag-suffix: '-gpu-intel-sycl-f32-stablediffusion-ggml'
706+
runs-on: 'ubuntu-latest'
707+
base-image: "quay.io/go-skynet/intel-oneapi-base:latest"
708+
skip-drivers: 'false'
709+
backend: "stablediffusion-ggml"
710+
dockerfile: "./backend/Dockerfile.go"
711+
context: "./"
712+
- build-type: 'sycl_f16'
713+
cuda-major-version: ""
714+
cuda-minor-version: ""
715+
platforms: 'linux/amd64'
716+
tag-latest: 'true'
717+
tag-suffix: '-gpu-intel-sycl-f16-stablediffusion-ggml'
718+
runs-on: 'ubuntu-latest'
719+
base-image: "quay.io/go-skynet/intel-oneapi-base:latest"
720+
skip-drivers: 'false'
721+
backend: "stablediffusion-ggml"
722+
dockerfile: "./backend/Dockerfile.go"
723+
context: "./"
724+
- build-type: 'vulkan'
725+
cuda-major-version: ""
726+
cuda-minor-version: ""
727+
platforms: 'linux/amd64'
728+
tag-latest: 'true'
729+
tag-suffix: '-gpu-vulkan-stablediffusion-ggml'
730+
runs-on: 'ubuntu-latest'
731+
base-image: "ubuntu:22.04"
732+
skip-drivers: 'false'
733+
backend: "stablediffusion-ggml"
734+
dockerfile: "./backend/Dockerfile.go"
735+
context: "./"
736+
- build-type: 'cublas'
737+
cuda-major-version: "12"
738+
cuda-minor-version: "0"
739+
platforms: 'linux/arm64'
740+
skip-drivers: 'true'
741+
tag-latest: 'auto'
742+
tag-suffix: '-nvidia-l4t-arm64-stablediffusion-ggml'
743+
base-image: "nvcr.io/nvidia/l4t-jetpack:r36.4.0"
744+
runs-on: 'ubuntu-24.04-arm'
745+
backend: "stablediffusion-ggml"
746+
dockerfile: "./backend/Dockerfile.go"
747+
context: "./"
651748
llama-cpp-darwin:
652749
runs-on: macOS-14
653750
strategy:

.github/workflows/backend_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ on:
6464
required: true
6565

6666
jobs:
67-
reusable_python_backend-build:
67+
backend-build:
6868
runs-on: ${{ inputs.runs-on }}
6969
steps:
7070

.github/workflows/bump_deps.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ jobs:
2121
variable: "BARKCPP_VERSION"
2222
branch: "main"
2323
file: "Makefile"
24-
- repository: "leejet/stable-diffusion.cpp"
24+
- repository: "richiejp/stable-diffusion.cpp"
2525
variable: "STABLEDIFFUSION_GGML_VERSION"
2626
branch: "master"
27-
file: "Makefile"
28-
- repository: "mudler/go-stable-diffusion"
29-
variable: "STABLEDIFFUSION_VERSION"
30-
branch: "master"
31-
file: "Makefile"
27+
file: "backend/go/stablediffusion-ggml/Makefile"
3228
- repository: "mudler/go-piper"
3329
variable: "PIPER_VERSION"
3430
branch: "master"

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
104104
make -C backend/python/transformers
105105
106-
make backends/llama-cpp backends/piper
106+
make backends/llama-cpp backends/piper backends/stablediffusion-ggml
107107
env:
108108
CUDA_VERSION: 12-4
109109
- name: Test
@@ -168,7 +168,7 @@ jobs:
168168
PATH="$PATH:$HOME/go/bin" make protogen-go
169169
- name: Test
170170
run: |
171-
PATH="$PATH:$HOME/go/bin" make backends/llama-cpp backends/piper docker-build-aio e2e-aio
171+
PATH="$PATH:$HOME/go/bin" make backends/llama-cpp backends/piper backends/stablediffusion-ggml docker-build-aio e2e-aio
172172
- name: Setup tmate session if tests fail
173173
if: ${{ failure() }}
174174
uses: mxschmitt/action-tmate@v3.22

Makefile

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ DETECT_LIBS?=true
99
WHISPER_REPO?=https://github.com/ggml-org/whisper.cpp
1010
WHISPER_CPP_VERSION?=032697b9a850dc2615555e2a93a683cc3dd58559
1111

12-
# stablediffusion.cpp (ggml)
13-
STABLEDIFFUSION_GGML_REPO?=https://github.com/richiejp/stable-diffusion.cpp
14-
STABLEDIFFUSION_GGML_VERSION?=53e3b17eb3d0b5760ced06a1f98320b68b34aaae
15-
1612
# ONEAPI variables for SYCL
1713
export ONEAPI_VARS?=/opt/intel/oneapi/setvars.sh
1814
ONEAPI_VERSION=2025.1
@@ -207,13 +203,6 @@ endif
207203

208204
ALL_GRPC_BACKENDS=backend-assets/grpc/huggingface
209205
ALL_GRPC_BACKENDS+=backend-assets/grpc/whisper
210-
211-
ifeq ($(ONNX_OS),linux)
212-
ifeq ($(ONNX_ARCH),x64)
213-
ALL_GRPC_BACKENDS+=backend-assets/grpc/stablediffusion-ggml
214-
endif
215-
endif
216-
217206
ALL_GRPC_BACKENDS+=backend-assets/grpc/local-store
218207
ALL_GRPC_BACKENDS+=backend-assets/grpc/silero-vad
219208
ALL_GRPC_BACKENDS+=$(OPTIONAL_GRPC)
@@ -236,20 +225,6 @@ endif
236225

237226
all: help
238227

239-
## stablediffusion (ggml)
240-
sources/stablediffusion-ggml.cpp:
241-
git clone --recursive $(STABLEDIFFUSION_GGML_REPO) sources/stablediffusion-ggml.cpp && \
242-
cd sources/stablediffusion-ggml.cpp && \
243-
git checkout $(STABLEDIFFUSION_GGML_VERSION) && \
244-
git submodule update --init --recursive --depth 1 --single-branch
245-
246-
backend/go/image/stablediffusion-ggml/libsd.a: sources/stablediffusion-ggml.cpp
247-
$(MAKE) -C backend/go/image/stablediffusion-ggml build/libstable-diffusion.a
248-
$(MAKE) -C backend/go/image/stablediffusion-ggml libsd.a
249-
250-
backend-assets/grpc/stablediffusion-ggml: backend/go/image/stablediffusion-ggml/libsd.a backend-assets/grpc
251-
$(MAKE) -C backend/go/image/stablediffusion-ggml CGO_LDFLAGS="$(CGO_LDFLAGS)" stablediffusion-ggml
252-
253228
sources/onnxruntime:
254229
mkdir -p sources/onnxruntime
255230
curl -L https://github.com/microsoft/onnxruntime/releases/download/v$(ONNX_VERSION)/onnxruntime-$(ONNX_OS)-$(ONNX_ARCH)-$(ONNX_VERSION).tgz -o sources/onnxruntime/onnxruntime-$(ONNX_OS)-$(ONNX_ARCH)-$(ONNX_VERSION).tgz
@@ -278,7 +253,7 @@ sources/whisper.cpp/build/src/libwhisper.a: sources/whisper.cpp
278253
cd sources/whisper.cpp && cmake $(WHISPER_CMAKE_ARGS) . -B ./build
279254
cd sources/whisper.cpp/build && cmake --build . --config Release
280255

281-
get-sources: sources/stablediffusion-ggml.cpp sources/whisper.cpp
256+
get-sources: sources/whisper.cpp
282257

283258
replace:
284259
$(GOCMD) mod edit -replace github.com/ggerganov/whisper.cpp=$(CURDIR)/sources/whisper.cpp
@@ -307,7 +282,6 @@ clean: ## Remove build related file
307282
rm -rf release/
308283
rm -rf backend-assets/*
309284
$(MAKE) -C backend/cpp/grpc clean
310-
$(MAKE) -C backend/go/image/stablediffusion-ggml clean
311285
$(MAKE) dropreplace
312286
$(MAKE) protogen-clean
313287
rmdir pkg/grpc/proto || true
@@ -401,6 +375,9 @@ backends/llama-cpp: docker-build-llama-cpp docker-save-llama-cpp build-api
401375
backends/piper: docker-build-piper docker-save-piper build-api
402376
./local-ai backends install "ocifile://$(abspath ./backend-images/piper.tar)"
403377

378+
backends/stablediffusion-ggml: docker-build-stablediffusion-ggml docker-save-stablediffusion-ggml build-api
379+
./local-ai backends install "ocifile://$(abspath ./backend-images/stablediffusion-ggml.tar)"
380+
404381
########################################################
405382
## AIO tests
406383
########################################################
@@ -736,6 +713,12 @@ docker-save-llama-cpp: backend-images
736713
docker-save-bark-cpp: backend-images
737714
docker save local-ai-backend:bark-cpp -o backend-images/bark-cpp.tar
738715

716+
docker-build-stablediffusion-ggml:
717+
docker build -t local-ai-backend:stablediffusion-ggml -f backend/Dockerfile.go --build-arg BACKEND=stablediffusion-ggml .
718+
719+
docker-save-stablediffusion-ggml: backend-images
720+
docker save local-ai-backend:stablediffusion-ggml -o backend-images/stablediffusion-ggml.tar
721+
739722
docker-build-rerankers:
740723
docker build -t local-ai-backend:rerankers -f backend/Dockerfile.python --build-arg BACKEND=rerankers .
741724

backend/cpp/llama-cpp/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ else ifeq ($(BUILD_TYPE),hipblas)
3535
# AMDGPU_TARGETS ?= "$(GPU_TARGETS)"
3636
CMAKE_ARGS+=-DGGML_HIP=ON
3737
# CMAKE_ARGS+=-DGGML_HIP=ON -DAMDGPU_TARGETS="$(AMDGPU_TARGETS)" -DGPU_TARGETS="$(GPU_TARGETS)"
38+
else ifeq ($(BUILD_TYPE),vulkan)
39+
CMAKE_ARGS+=-DGGML_VULKAN=1
3840
else ifeq ($(OS),Darwin)
3941
ifeq ($(BUILD_TYPE),)
4042
BUILD_TYPE=metal

backend/go/image/stablediffusion-ggml/Makefile renamed to backend/go/stablediffusion-ggml/Makefile

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ LIBRARY_PATH := $(abspath ./)
44
AR?=ar
55
CMAKE_ARGS?=
66
BUILD_TYPE?=
7+
NATIVE?=false
8+
CUDA_LIBPATH?=/usr/local/cuda/lib64/
79
ONEAPI_VARS?=/opt/intel/oneapi/setvars.sh
810
# keep standard at C11 and C++11
9-
CXXFLAGS = -I. -I$(INCLUDE_PATH)/../../../../sources/stablediffusion-ggml.cpp/thirdparty -I$(INCLUDE_PATH)/../../../../sources/stablediffusion-ggml.cpp/ggml/include -I$(INCLUDE_PATH)/../../../../sources/stablediffusion-ggml.cpp -O3 -DNDEBUG -std=c++17 -fPIC
11+
CXXFLAGS = -I. -I$(INCLUDE_PATH)/sources/stablediffusion-ggml.cpp/thirdparty -I$(INCLUDE_PATH)/sources/stablediffusion-ggml.cpp/ggml/include -I$(INCLUDE_PATH)/sources/stablediffusion-ggml.cpp -O3 -DNDEBUG -std=c++17 -fPIC
1012

1113
GOCMD?=go
1214
CGO_LDFLAGS?=
@@ -15,12 +17,21 @@ CGO_LDFLAGS_SYCL=
1517
GO_TAGS?=
1618
LD_FLAGS?=
1719

20+
# stablediffusion.cpp (ggml)
21+
STABLEDIFFUSION_GGML_REPO?=https://github.com/richiejp/stable-diffusion.cpp
22+
STABLEDIFFUSION_GGML_VERSION?=53e3b17eb3d0b5760ced06a1f98320b68b34aaae
23+
1824
# Disable Shared libs as we are linking on static gRPC and we can't mix shared and static
1925
CMAKE_ARGS+=-DBUILD_SHARED_LIBS=OFF
2026

27+
ifeq ($(NATIVE),false)
28+
CMAKE_ARGS+=-DGGML_NATIVE=OFF
29+
endif
30+
2131
# If build type is cublas, then we set -DGGML_CUDA=ON to CMAKE_ARGS automatically
2232
ifeq ($(BUILD_TYPE),cublas)
23-
CMAKE_ARGS+=-DSD_CUDA=ON
33+
CMAKE_ARGS+=-DSD_CUDA=ON -DGGML_CUDA=ON
34+
CGO_LDFLAGS+=-lcublas -lcudart -L$(CUDA_LIBPATH) -L$(CUDA_LIBPATH)/stubs/ -lcuda
2435
# If build type is openblas then we set -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS
2536
# to CMAKE_ARGS automatically
2637
else ifeq ($(BUILD_TYPE),openblas)
@@ -30,14 +41,17 @@ else ifeq ($(BUILD_TYPE),clblas)
3041
CMAKE_ARGS+=-DGGML_CLBLAST=ON -DCLBlast_DIR=/some/path
3142
# If it's hipblas we do have also to set CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++
3243
else ifeq ($(BUILD_TYPE),hipblas)
33-
CMAKE_ARGS+=-DSD_HIPBLAS=ON
44+
CMAKE_ARGS+=-DSD_HIPBLAS=ON -DGGML_HIPBLAS=ON
3445
# If it's OSX, DO NOT embed the metal library - -DGGML_METAL_EMBED_LIBRARY=ON requires further investigation
3546
# But if it's OSX without metal, disable it here
47+
else ifeq ($(BUILD_TYPE),vulkan)
48+
CMAKE_ARGS+=-DSD_VULKAN=ON -DGGML_VULKAN=ON
49+
CGO_LDFLAGS+=-lvulkan
3650
else ifeq ($(OS),Darwin)
3751
ifneq ($(BUILD_TYPE),metal)
38-
CMAKE_ARGS+=-DSD_METAL=OFF
52+
CMAKE_ARGS+=-DSD_METAL=OFF -DGGML_METAL=OFF
3953
else
40-
CMAKE_ARGS+=-DSD_METAL=ON
54+
CMAKE_ARGS+=-DSD_METAL=ON -DGGML_METAL=ON
4155
CMAKE_ARGS+=-DGGML_METAL_EMBED_LIBRARY=ON
4256
TARGET+=--target ggml-metal
4357
endif
@@ -49,8 +63,8 @@ ifeq ($(BUILD_TYPE),sycl_f16)
4963
-DCMAKE_CXX_COMPILER=icpx \
5064
-DSD_SYCL=ON \
5165
-DGGML_SYCL_F16=ON
52-
CC=icx
53-
CXX=icpx
66+
export CC=icx
67+
export CXX=icpx
5468
CGO_LDFLAGS_SYCL += -fsycl -L${DNNLROOT}/lib -ldnnl ${MKLROOT}/lib/intel64/libmkl_sycl.a -fiopenmp -fopenmp-targets=spir64 -lOpenCL
5569
CGO_LDFLAGS_SYCL += $(shell pkg-config --libs mkl-static-lp64-gomp)
5670
CGO_CXXFLAGS += -fiopenmp -fopenmp-targets=spir64
@@ -62,8 +76,8 @@ ifeq ($(BUILD_TYPE),sycl_f32)
6276
-DCMAKE_C_COMPILER=icx \
6377
-DCMAKE_CXX_COMPILER=icpx \
6478
-DSD_SYCL=ON
65-
CC=icx
66-
CXX=icpx
79+
export CC=icx
80+
export CXX=icpx
6781
CGO_LDFLAGS_SYCL += -fsycl -L${DNNLROOT}/lib -ldnnl ${MKLROOT}/lib/intel64/libmkl_sycl.a -fiopenmp -fopenmp-targets=spir64 -lOpenCL
6882
CGO_LDFLAGS_SYCL += $(shell pkg-config --libs mkl-static-lp64-gomp)
6983
CGO_CXXFLAGS += -fiopenmp -fopenmp-targets=spir64
@@ -101,12 +115,12 @@ ifneq (,$(findstring sycl,$(BUILD_TYPE)))
101115
+bash -c "source $(ONEAPI_VARS); \
102116
mkdir -p build && \
103117
cd build && \
104-
cmake $(CMAKE_ARGS) ../../../../../sources/stablediffusion-ggml.cpp && \
118+
cmake $(CMAKE_ARGS) ../sources/stablediffusion-ggml.cpp && \
105119
cmake --build . --config Release"
106120
else
107121
mkdir -p build && \
108122
cd build && \
109-
cmake $(CMAKE_ARGS) ../../../../../sources/stablediffusion-ggml.cpp && \
123+
cmake $(CMAKE_ARGS) ../sources/stablediffusion-ggml.cpp && \
110124
cmake --build . --config Release
111125
endif
112126
$(MAKE) $(COMBINED_LIB)
@@ -119,17 +133,26 @@ else
119133
$(CXX) $(CXXFLAGS) gosd.cpp -o gosd.o -c
120134
endif
121135

122-
libsd.a: gosd.o
136+
## stablediffusion (ggml)
137+
sources/stablediffusion-ggml.cpp:
138+
git clone --recursive $(STABLEDIFFUSION_GGML_REPO) sources/stablediffusion-ggml.cpp && \
139+
cd sources/stablediffusion-ggml.cpp && \
140+
git checkout $(STABLEDIFFUSION_GGML_VERSION) && \
141+
git submodule update --init --recursive --depth 1 --single-branch
142+
143+
libsd.a: sources/stablediffusion-ggml.cpp build/libstable-diffusion.a gosd.o
123144
cp $(INCLUDE_PATH)/build/libstable-diffusion.a ./libsd.a
124145
$(AR) rcs libsd.a gosd.o
125146

126-
stablediffusion-ggml:
147+
stablediffusion-ggml: libsd.a
127148
CGO_LDFLAGS="$(CGO_LDFLAGS) $(CGO_LDFLAGS_SYCL)" C_INCLUDE_PATH="$(INCLUDE_PATH)" LIBRARY_PATH="$(LIBRARY_PATH)" \
128149
CC="$(CC)" CXX="$(CXX)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" \
129-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o ../../../../backend-assets/grpc/stablediffusion-ggml ./
130-
ifneq ($(UPX),)
131-
$(UPX) ../../../../backend-assets/grpc/stablediffusion-ggml
132-
endif
150+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o stablediffusion-ggml ./
151+
152+
package:
153+
bash package.sh
154+
155+
build: stablediffusion-ggml package
133156

134157
clean:
135158
rm -rf gosd.o libsd.a build $(COMBINED_LIB)

backend/go/image/stablediffusion-ggml/gosd.go renamed to backend/go/stablediffusion-ggml/gosd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
// #cgo CXXFLAGS: -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/thirdparty -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/ggml/include
3+
// #cgo CXXFLAGS: -I${SRCDIR}/sources/stablediffusion-ggml.cpp/thirdparty -I${SRCDIR}/sources/stablediffusion-ggml.cpp -I${SRCDIR}/sources/stablediffusion-ggml.cpp/ggml/include
44
// #cgo LDFLAGS: -L${SRCDIR}/ -lsd -lstdc++ -lm -lggmlall -lgomp
55
// #include <gosd.h>
66
// #include <stdlib.h>

0 commit comments

Comments
 (0)