Skip to content

Commit e2369f2

Browse files
authored
Added llamacpp model runtime with docker based deployment (#85)
* Add llama.cpp Dockerfile and README Added llamacpp as blueprint with docker based deployment Signed-off-by: AhmedSeemalK <ahmed.seemal@intel.com> * addressed review comments addressed review comments Signed-off-by: AhmedSeemalK <ahmed.seemal@intel.com> --------- Signed-off-by: AhmedSeemalK <ahmed.seemal@intel.com>
1 parent 4df0676 commit e2369f2

2 files changed

Lines changed: 160 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM intel/oneapi-basekit:latest
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG LLAMA_CPP_REPO=https://github.com/ggml-org/llama.cpp.git
5+
ARG LLAMA_CPP_REF=b8750
6+
7+
SHELL ["/bin/bash", "-lc"]
8+
9+
# Base packages needed for building llama.cpp
10+
RUN apt-get update && apt-get install -y --no-install-recommends \
11+
git \
12+
cmake \
13+
ninja-build \
14+
build-essential \
15+
pkg-config \
16+
ca-certificates \
17+
curl \
18+
libssl-dev \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
WORKDIR /opt
22+
23+
# Clone source
24+
RUN git clone --depth 1 --branch "${LLAMA_CPP_REF}" "${LLAMA_CPP_REPO}" llama.cpp
25+
26+
WORKDIR /opt/llama.cpp
27+
28+
# Build with Intel oneAPI compilers + oneMKL BLAS
29+
RUN source /opt/intel/oneapi/setvars.sh --force && \
30+
cmake -S . -B build -G Ninja \
31+
-DCMAKE_BUILD_TYPE=Release \
32+
-DCMAKE_C_COMPILER=icx \
33+
-DCMAKE_CXX_COMPILER=icpx \
34+
-DGGML_BLAS=ON \
35+
-DGGML_BLAS_VENDOR=Intel10_64lp \
36+
-DGGML_NATIVE=ON \
37+
-DLLAMA_CURL=ON \
38+
-DLLAMA_OPENSSL=ON && \
39+
cmake --build build -j"$(nproc)"
40+
41+
# Write startup wrapper inline
42+
RUN printf '#!/usr/bin/env bash\nset -euo pipefail\nsource /opt/intel/oneapi/setvars.sh --force\nexec "$@"\n' > /usr/local/bin/llama-env && \
43+
chmod +x /usr/local/bin/llama-env
44+
45+
ENV PATH="/opt/llama.cpp/build/bin:${PATH}"
46+
ENV OCL_ICD_FILENAMES=""
47+
WORKDIR /workspace
48+
49+
ENTRYPOINT ["/bin/bash", "-c", "set +u; source /opt/intel/oneapi/setvars.sh --force; mkdir -p /logs; /opt/llama.cpp/build/bin/llama-server --host 0.0.0.0 -c 8192 -t 6 \"$@\" 2>&1 | tee /logs/llama-server.log", "--"]

blueprints/llamacpp/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# llama.cpp — Intel oneAPI with VMWare Foundation
2+
3+
Runs [llama.cpp](https://github.com/ggml-org/llama.cpp) `llama-server` built with Intel oneAPI compilers and oneMKL BLAS for optimized CPU inference.
4+
5+
> **Note:** You can use any GGUF model from Hugging Face. The examples below use specific models, but you can replace them with any GGUF model by setting the appropriate environment variables.
6+
7+
## Build & Run
8+
9+
**1. Build the image** (output logged to `$HOME/logs/docker-build.log`):
10+
11+
```bash
12+
mkdir -p $HOME/logs
13+
sudo docker build -f Dockerfile-llamacpp -t llamacpp-intel:latest . \
14+
2>&1 | tee $HOME/logs/docker-build.log
15+
```
16+
17+
**2. Set environment variables for your model:**
18+
19+
```bash
20+
# Example 1: Gemma 3 1B IT (default)
21+
export MODEL_REPO="unsloth/gemma-3-1b-it-GGUF"
22+
export MODEL_FILE="gemma-3-1b-it-Q4_K_M.gguf"
23+
export MODEL_NAME="gemma-3-1b-it"
24+
25+
# Example 2: Gemma 3 4B IT
26+
# export MODEL_REPO="google/gemma-2-2b-it-GGUF"
27+
# export MODEL_FILE="gemma-2-2b-it-Q8_0.gguf"
28+
# export MODEL_NAME="gemma-3-4b-it"
29+
30+
# Example 3: Any other GGUF model from Hugging Face
31+
# export MODEL_REPO="<huggingface-username>/<repo-name>"
32+
# export MODEL_FILE="<model-filename>.gguf"
33+
# export MODEL_NAME="<model-name>"
34+
```
35+
36+
**3. Stop any existing container, then start a fresh one:**
37+
38+
```bash
39+
sudo docker stop llamacpp 2>/dev/null || true
40+
41+
sudo docker run --rm -d \
42+
--ipc=host --net=host \
43+
-v $HOME/models:/root/.cache/huggingface \
44+
-v $HOME/logs:/logs \
45+
--workdir /workspace \
46+
--name llamacpp \
47+
llamacpp-intel:latest \
48+
--hf-repo ${MODEL_REPO} \
49+
--hf-file ${MODEL_FILE}
50+
```
51+
52+
- `MODEL_REPO` — HuggingFace repository containing the GGUF model
53+
- `MODEL_FILE` — GGUF model file name
54+
- `MODEL_NAME` — Model name for API requests
55+
- Models are cached in `$HOME/models` — downloaded once, reused on subsequent runs
56+
- Build logs: `$HOME/logs/docker-build.log`
57+
- Server logs: `$HOME/logs/llama-server.log`
58+
- Server listens on `http://localhost:8080`
59+
60+
## Test
61+
62+
### Completions API
63+
64+
```bash
65+
curl http://localhost:8080/v1/completions \
66+
-X POST \
67+
-H "Content-Type: application/json" \
68+
-d '{"model": "'"${MODEL_NAME}"'", "prompt": "What is Deep Learning?", "max_tokens": 25, "temperature": 0}'
69+
```
70+
71+
### Chat Completions API
72+
73+
```bash
74+
# Set BASE_URL and TOKEN (if using with the gateway)
75+
export BASE_URL="http://localhost:8080"
76+
export TOKEN="your-token-here" # or leave empty if no auth
77+
78+
curl -k ${BASE_URL}/v1/chat/completions -X POST \
79+
-d '{
80+
"model": "'"${MODEL_NAME}"'",
81+
"messages": [
82+
{"role": "user", "content": "What is Deep Learning?"}
83+
],
84+
"max_tokens": 25,
85+
"temperature": 0
86+
}' \
87+
-H 'Content-Type: application/json'
88+
```
89+
90+
**Example with Gemma 3 1B IT:**
91+
92+
```bash
93+
export MODEL_NAME="gemma-3-1b-it"
94+
95+
curl -k ${BASE_URL}/v1/chat/completions -X POST \
96+
-d '{
97+
"model": "'"${MODEL_NAME}"'",
98+
"messages": [
99+
{"role": "user", "content": "What is Deep Learning?"}
100+
],
101+
"max_tokens": 25,
102+
"temperature": 0
103+
}' \
104+
-H 'Content-Type: application/json'
105+
```
106+
107+
## Stop
108+
109+
```bash
110+
sudo docker stop llamacpp
111+
```

0 commit comments

Comments
 (0)