Skip to content

Commit 8173a5b

Browse files
authored
ci: add GPU tests (#245)
Signed-off-by: mudler <[email protected]>
1 parent b8a1245 commit 8173a5b

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

.github/workflows/test-gpu.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: 'GPU tests'
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
tags:
10+
- '*'
11+
12+
concurrency:
13+
group: ci-gpu-tests-${{ github.head_ref || github.ref }}-${{ github.repository }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
ubuntu-latest:
18+
runs-on: self-hosted
19+
strategy:
20+
matrix:
21+
go-version: ['1.21.x']
22+
steps:
23+
- name: Clone
24+
uses: actions/checkout@v3
25+
with:
26+
submodules: true
27+
- name: Setup Go ${{ matrix.go-version }}
28+
uses: actions/setup-go@v4
29+
with:
30+
go-version: ${{ matrix.go-version }}
31+
# You can test your matrix by printing the current Go version
32+
- name: Display Go version
33+
run: go version
34+
- name: Dependencies
35+
run: |
36+
sudo apt-get update
37+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y make wget
38+
- name: Dependencies
39+
run: |
40+
# This fixes libc6-dev installations errors on containers...
41+
sudo rm -rfv /run/systemd/system
42+
sudo apt-get update
43+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential ffmpeg nvidia-cuda-toolkit cmake
44+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates cmake curl patch
45+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y pip wget
46+
- name: Build and test
47+
run: |
48+
GPU_TESTS=true BUILD_TYPE=cublas CMAKE_ARGS="-DLLAMA_METAL=OFF -DLLAMA_F16C=OFF -DLLAMA_AVX512=OFF -DLLAMA_AVX2=OFF -DLLAMA_FMA=OFF" \
49+
make test 2>&1 | tee test_log.log
50+
if grep -q "using CUDA for GPU acceleration" test_log.log; then
51+
echo "All good";
52+
else
53+
echo "No CUDA found";
54+
exit 1;
55+
fi
56+
- name: Release space from worker ♻
57+
if: always()
58+
run: |
59+
sudo rm -rf build || true
60+
sudo rm -rf bin || true
61+
sudo rm -rf dist || true
62+
sudo rm -rf *.log || true
63+
make clean || true

Makefile

+13-3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ ifdef CLBLAST_DIR
170170
CMAKE_ARGS+=-DCLBlast_dir=$(CLBLAST_DIR)
171171
endif
172172

173+
# TODO: support Windows
174+
ifeq ($(GPU_TESTS),true)
175+
CGO_LDFLAGS="-lcublas -lcudart -L/usr/local/cuda/lib64/"
176+
TEST_LABEL=gpu
177+
else
178+
TEST_LABEL=!gpu
179+
endif
180+
173181
#
174182
# Print build information
175183
#
@@ -236,6 +244,8 @@ clean:
236244
$(MAKE) -C llama.cpp clean
237245
rm -rf build
238246

239-
test: libbinding.a
240-
test -f ggllm-test-model.bin || wget -q https://huggingface.co/TheBloke/CodeLlama-7B-Instruct-GGUF/resolve/main/codellama-7b-instruct.Q2_K.gguf -O ggllm-test-model.bin
241-
C_INCLUDE_PATH=${INCLUDE_PATH} CGO_LDFLAGS=${CGO_LDFLAGS} LIBRARY_PATH=${LIBRARY_PATH} TEST_MODEL=ggllm-test-model.bin go test -v ./...
247+
ggllm-test-model.bin:
248+
wget -q https://huggingface.co/TheBloke/CodeLlama-7B-Instruct-GGUF/resolve/main/codellama-7b-instruct.Q2_K.gguf -O ggllm-test-model.bin
249+
250+
test: ggllm-test-model.bin libbinding.a
251+
C_INCLUDE_PATH=${INCLUDE_PATH} CGO_LDFLAGS=${CGO_LDFLAGS} LIBRARY_PATH=${LIBRARY_PATH} TEST_MODEL=ggllm-test-model.bin go run github.com/onsi/ginkgo/v2/ginkgo --label-filter="$(TEST_LABEL)" --flake-attempts 5 -v -r ./...

llama_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,29 @@ how much is 2+2?
9292
Expect(int(l)).To(Equal(len(tokens)))
9393
})
9494
})
95+
96+
Context("Inferencing tests with GPU (using "+testModelPath+") ", Label("gpu"), func() {
97+
getModel := func() (*LLama, error) {
98+
model, err := New(
99+
testModelPath,
100+
llama.EnableF16Memory, llama.SetContext(128), llama.EnableEmbeddings, llama.SetGPULayers(10),
101+
)
102+
Expect(err).ToNot(HaveOccurred())
103+
Expect(model).ToNot(BeNil())
104+
return model, err
105+
}
106+
107+
It("predicts successfully", func() {
108+
if testModelPath == "" {
109+
Skip("test skipped - only makes sense if the TEST_MODEL environment variable is set.")
110+
}
111+
112+
model, err := getModel()
113+
text, err := model.Predict(`[INST] Answer to the following question:
114+
how much is 2+2?
115+
[/INST]`)
116+
Expect(err).ToNot(HaveOccurred(), text)
117+
Expect(text).To(ContainSubstring("4"), text)
118+
})
119+
})
95120
})

0 commit comments

Comments
 (0)