|
| 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