Skip to content

Commit 01e75d9

Browse files
committed
Start to try to attach some tests
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 5885711 commit 01e75d9

File tree

6 files changed

+85
-56
lines changed

6 files changed

+85
-56
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ jobs:
186186
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@1958fcbe2ca8bd93af633f11e97d44e567e945af
187187
go install github.com/GeertJohan/go.rice/rice@latest
188188
PATH="$PATH:$HOME/go/bin" make protogen-go
189+
- name: Build and install backends needed for tests
190+
run: |
191+
make docker-build-llama-cpp
192+
make docker-save-llama-cpp
193+
make build-api
194+
./local-ai backends install "ocifile://$PWD/backend-images/llama-cpp.tar"
189195
- name: Build images
190196
run: |
191197
docker build --build-arg FFMPEG=true --build-arg MAKEFLAGS="--jobs=5 --output-sync=target" -t local-ai:tests -f Dockerfile .

Dockerfile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,7 @@ COPY ./pkg/langchain ./pkg/langchain
299299
RUN ls -l ./
300300
RUN make backend-assets
301301
RUN make prepare
302-
RUN if [ "${TARGETARCH}" = "arm64" ] || [ "${BUILD_TYPE}" = "hipblas" ]; then \
303-
SKIP_GRPC_BACKEND="backend-assets/grpc/llama-cpp-avx512 backend-assets/grpc/llama-cpp-avx backend-assets/grpc/llama-cpp-avx2" make grpcs; \
304-
else \
305-
make grpcs; \
306-
fi
302+
RUN make grpcs
307303

308304
# The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry.
309305
# Adjustments to the build process should likely be made here.
@@ -316,11 +312,7 @@ COPY . .
316312
## Build the binary
317313
## If we're on arm64 AND using cublas/hipblas, skip some of the llama-compat backends to save space
318314
## Otherwise just run the normal build
319-
RUN if [ "${TARGETARCH}" = "arm64" ] || [ "${BUILD_TYPE}" = "hipblas" ]; then \
320-
SKIP_GRPC_BACKEND="backend-assets/grpc/llama-cpp-avx512 backend-assets/grpc/llama-cpp-avx backend-assets/grpc/llama-cpp-avx2" make build; \
321-
else \
322-
make build; \
323-
fi
315+
RUN make build
324316

325317
RUN if [ ! -d "/build/sources/go-piper/piper-phonemize/pi/lib/" ]; then \
326318
mkdir -p /build/sources/go-piper/piper-phonemize/pi/lib/ \

Makefile

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ sources/whisper.cpp/build/src/libwhisper.a: sources/whisper.cpp
327327
cd sources/whisper.cpp && cmake $(WHISPER_CMAKE_ARGS) . -B ./build
328328
cd sources/whisper.cpp/build && cmake --build . --config Release
329329

330-
get-sources: sources/go-piper sources/stablediffusion-ggml.cpp sources/bark.cpp sources/whisper.cpp backend/cpp/llama-cpp/llama.cpp
330+
get-sources: sources/go-piper sources/stablediffusion-ggml.cpp sources/bark.cpp sources/whisper.cpp
331331

332332
replace:
333333
$(GOCMD) mod edit -replace github.com/ggerganov/whisper.cpp=$(CURDIR)/sources/whisper.cpp
@@ -360,9 +360,7 @@ clean: ## Remove build related file
360360
rm -rf backend-assets/*
361361
$(MAKE) -C backend/cpp/grpc clean
362362
$(MAKE) -C backend/go/bark-cpp clean
363-
$(MAKE) -C backend/cpp/llama-cpp clean
364363
$(MAKE) -C backend/go/image/stablediffusion-ggml clean
365-
rm -rf backend/cpp/llama-cpp-* || true
366364
$(MAKE) dropreplace
367365
$(MAKE) protogen-clean
368366
rmdir pkg/grpc/proto || true
@@ -403,18 +401,6 @@ backend-assets/lib:
403401
mkdir -p backend-assets/lib
404402

405403
dist:
406-
$(MAKE) backend-assets/grpc/llama-cpp-avx2
407-
ifeq ($(DETECT_LIBS),true)
408-
scripts/prepare-libs.sh backend-assets/grpc/llama-cpp-avx2
409-
endif
410-
ifeq ($(OS),Darwin)
411-
BUILD_TYPE=none $(MAKE) backend-assets/grpc/llama-cpp-fallback
412-
else
413-
$(MAKE) backend-assets/grpc/llama-cpp-cuda
414-
$(MAKE) backend-assets/grpc/llama-cpp-hipblas
415-
$(MAKE) backend-assets/grpc/llama-cpp-sycl_f16
416-
$(MAKE) backend-assets/grpc/llama-cpp-sycl_f32
417-
endif
418404
GO_TAGS="tts p2p" $(MAKE) build
419405
ifeq ($(DETECT_LIBS),true)
420406
scripts/prepare-libs.sh backend-assets/grpc/piper
@@ -679,31 +665,6 @@ ifneq ($(UPX),)
679665
$(UPX) backend-assets/grpc/huggingface
680666
endif
681667

682-
backend/cpp/llama-cpp/llama.cpp:
683-
LLAMA_VERSION=$(CPPLLAMA_VERSION) $(MAKE) -C backend/cpp/llama-cpp llama.cpp
684-
685-
INSTALLED_PACKAGES=$(CURDIR)/backend/cpp/grpc/installed_packages
686-
INSTALLED_LIB_CMAKE=$(INSTALLED_PACKAGES)/lib/cmake
687-
ADDED_CMAKE_ARGS=-Dabsl_DIR=${INSTALLED_LIB_CMAKE}/absl \
688-
-DProtobuf_DIR=${INSTALLED_LIB_CMAKE}/protobuf \
689-
-Dutf8_range_DIR=${INSTALLED_LIB_CMAKE}/utf8_range \
690-
-DgRPC_DIR=${INSTALLED_LIB_CMAKE}/grpc \
691-
-DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES=${INSTALLED_PACKAGES}/include
692-
build-llama-cpp-grpc-server:
693-
# Conditionally build grpc for the llama backend to use if needed
694-
ifdef BUILD_GRPC_FOR_BACKEND_LLAMA
695-
$(MAKE) -C backend/cpp/grpc build
696-
_PROTOBUF_PROTOC=${INSTALLED_PACKAGES}/bin/proto \
697-
_GRPC_CPP_PLUGIN_EXECUTABLE=${INSTALLED_PACKAGES}/bin/grpc_cpp_plugin \
698-
PATH="${INSTALLED_PACKAGES}/bin:${PATH}" \
699-
CMAKE_ARGS="${CMAKE_ARGS} ${ADDED_CMAKE_ARGS}" \
700-
LLAMA_VERSION=$(CPPLLAMA_VERSION) \
701-
$(MAKE) -C backend/cpp/${VARIANT} grpc-server
702-
else
703-
echo "BUILD_GRPC_FOR_BACKEND_LLAMA is not defined."
704-
LLAMA_VERSION=$(CPPLLAMA_VERSION) $(MAKE) -C backend/cpp/${VARIANT} grpc-server
705-
endif
706-
707668
backend-assets/grpc/bark-cpp: protogen-go replace backend/go/bark-cpp/libbark.a backend-assets/grpc
708669
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(CURDIR)/backend/go/bark-cpp/ LIBRARY_PATH=$(CURDIR)/backend/go/bark-cpp/ \
709670
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/bark-cpp ./backend/go/bark-cpp/
@@ -795,6 +756,48 @@ docker-image-intel-xpu:
795756
--build-arg GRPC_BACKENDS="$(GRPC_BACKENDS)" \
796757
--build-arg BUILD_TYPE=sycl_f32 -t $(DOCKER_IMAGE) .
797758

759+
backend-images:
760+
mkdir -p backend-images
761+
762+
docker-build-llama-cpp:
763+
docker build -t local-ai-backend:llama-cpp -f backend/Dockerfile.llama-cpp .
764+
765+
docker-save-llama-cpp: backend-images
766+
docker save local-ai-backend:llama-cpp -o backend-images/llama-cpp.tar
767+
768+
769+
docker-build-rerankers:
770+
docker build -t local-ai-backend:rerankers -f backend/Dockerfile.python --build-arg BACKEND=rerankers .
771+
772+
docker-build-vllm:
773+
docker build -t local-ai-backend:vllm -f backend/Dockerfile.python --build-arg BACKEND=vllm .
774+
775+
docker-build-transformers:
776+
docker build -t local-ai-backend:transformers -f backend/Dockerfile.python --build-arg BACKEND=transformers .
777+
778+
docker-build-diffusers:
779+
docker build -t local-ai-backend:diffusers -f backend/Dockerfile.python --build-arg BACKEND=diffusers .
780+
781+
docker-build-kokoro:
782+
docker build -t local-ai-backend:kokoro -f backend/Dockerfile.python --build-arg BACKEND=kokoro .
783+
784+
docker-build-faster-whisper:
785+
docker build -t local-ai-backend:faster-whisper -f backend/Dockerfile.python --build-arg BACKEND=faster-whisper .
786+
787+
docker-build-coqui:
788+
docker build -t local-ai-backend:coqui -f backend/Dockerfile.python --build-arg BACKEND=coqui .
789+
790+
docker-build-bark:
791+
docker build -t local-ai-backend:bark -f backend/Dockerfile.python --build-arg BACKEND=bark .
792+
793+
docker-build-chatterbox:
794+
docker build -t local-ai-backend:chatterbox -f backend/Dockerfile.python --build-arg BACKEND=chatterbox .
795+
796+
docker-build-exllama2:
797+
docker build -t local-ai-backend:exllama2 -f backend/Dockerfile.python --build-arg BACKEND=exllama2 .
798+
799+
docker-build-backends: docker-build-llama-cpp docker-build-rerankers docker-build-vllm docker-build-transformers docker-build-diffusers docker-build-kokoro docker-build-faster-whisper docker-build-coqui docker-build-bark docker-build-chatterbox docker-build-exllama2
800+
798801
.PHONY: swagger
799802
swagger:
800803
swag init -g core/http/app.go --output swagger

backend/Dockerfile.llama-cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,20 @@ COPY --from=grpc /opt/grpc /usr/local
180180

181181
COPY . /LocalAI
182182

183-
RUN cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-avx
184-
RUN cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-avx2
185-
RUN cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-avx512
186-
RUN cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-fallback
187-
RUN cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-grpc
188-
RUN cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-rpc-server
183+
## Otherwise just run the normal build
184+
RUN <<EOT bash
185+
if [ "${TARGETARCH}" = "arm64" ] || [ "${BUILD_TYPE}" = "hipblas" ]; then \
186+
cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-fallback && \
187+
make llama-cpp-grpc && make llama-cpp-rpc-server; \
188+
else \
189+
cd /LocalAI/backend/cpp/llama-cpp && make llama-cpp-avx && \
190+
make llama-cpp-avx2 && \
191+
make llama-cpp-avx512 && \
192+
make llama-cpp-fallback && \
193+
make llama-cpp-grpc && \
194+
make llama-cpp-rpc-server; \
195+
fi
196+
EOT
189197

190198
FROM scratch
191199

backend/cpp/llama-cpp/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ ifeq ($(BUILD_TYPE),sycl_f32)
5252
-DCMAKE_CXX_FLAGS="-fsycl"
5353
endif
5454

55+
INSTALLED_PACKAGES=$(CURDIR)/../grpc/installed_packages
56+
INSTALLED_LIB_CMAKE=$(INSTALLED_PACKAGES)/lib/cmake
57+
ADDED_CMAKE_ARGS=-Dabsl_DIR=${INSTALLED_LIB_CMAKE}/absl \
58+
-DProtobuf_DIR=${INSTALLED_LIB_CMAKE}/protobuf \
59+
-Dutf8_range_DIR=${INSTALLED_LIB_CMAKE}/utf8_range \
60+
-DgRPC_DIR=${INSTALLED_LIB_CMAKE}/grpc \
61+
-DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES=${INSTALLED_PACKAGES}/include
5562
build-llama-cpp-grpc-server:
5663
# Conditionally build grpc for the llama backend to use if needed
5764
ifdef BUILD_GRPC_FOR_BACKEND_LLAMA

tests/e2e-aio/e2e_suite_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var client *openai.Client
2121
var containerImage = os.Getenv("LOCALAI_IMAGE")
2222
var containerImageTag = os.Getenv("LOCALAI_IMAGE_TAG")
2323
var modelsDir = os.Getenv("LOCALAI_MODELS_DIR")
24+
var backendDir = os.Getenv("LOCALAI_BACKEND_DIR")
2425
var apiEndpoint = os.Getenv("LOCALAI_API_ENDPOINT")
2526
var apiKey = os.Getenv("LOCALAI_API_KEY")
2627

@@ -82,6 +83,12 @@ func startDockerImage() {
8283
Expect(err).To(Not(HaveOccurred()))
8384
md := cwd + "/models"
8485

86+
bd := cwd + "/backends"
87+
88+
if backendDir != "" {
89+
bd = backendDir
90+
}
91+
8592
if modelsDir != "" {
8693
md = modelsDir
8794
}
@@ -99,6 +106,7 @@ func startDockerImage() {
99106
},
100107
Env: map[string]string{
101108
"MODELS_PATH": "/models",
109+
"BACKENDS_PATH": "/backends",
102110
"DEBUG": "true",
103111
"THREADS": fmt.Sprint(proc),
104112
"LOCALAI_SINGLE_ACTIVE_BACKEND": "true",
@@ -109,6 +117,11 @@ func startDockerImage() {
109117
ContainerFilePath: "/models",
110118
FileMode: 0o755,
111119
},
120+
{
121+
HostFilePath: bd,
122+
ContainerFilePath: "/backends",
123+
FileMode: 0o755,
124+
},
112125
},
113126
WaitingFor: wait.ForAll(
114127
wait.ForListeningPort(nat.Port(defaultApiPort)),

0 commit comments

Comments
 (0)