Ollama
(Manual) installation
The instructions for a
manual instruction point to a
self-contrained binary that can be downloaded and extracted:
$ curl -L https://ollama.com/download/ollama-linux-amd64.tgz -o /tmp/ollama-linux-amd64.tgz
$ tar tf /tmp/ollama-linux-amd64.tgz | grep -v '/$'
./bin/ollama
./lib/ollama/libcudart.so.12
./lib/ollama/libcublasLt.so.12.4.5.8
./lib/ollama/libcudart.so.11.0
./lib/ollama/libcublas.so.11
./lib/ollama/libcublas.so.12
./lib/ollama/libcudart.so.11.3.109
./lib/ollama/libcublas.so.12.4.5.8
./lib/ollama/libcudart.so.12.4.127
./lib/ollama/libcublasLt.so.11.5.1.109
./lib/ollama/libcublasLt.so.11
./lib/ollama/runners/cuda_v11_avx/ollama_llama_server
./lib/ollama/runners/cuda_v11_avx/libggml_cuda_v11.so
./lib/ollama/runners/rocm_avx/ollama_llama_server
./lib/ollama/runners/rocm_avx/libggml_rocm.so
./lib/ollama/runners/cuda_v12_avx/ollama_llama_server
./lib/ollama/runners/cuda_v12_avx/libggml_cuda_v12.so
./lib/ollama/runners/cpu_avx2/ollama_llama_server
./lib/ollama/runners/cpu_avx/ollama_llama_server
./lib/ollama/libcublas.so.11.5.1.109
./lib/ollama/libcublasLt.so.12
These files need to be extracted under
/usr:
$ sudo tar -C /usr -xzf /tmp/ollama-linux-amd64.tgz
Testing the installation
Start the Ollama server:
$ ollama serve
In another terminal:
$ ollama -v
ollama version is 0.5.7
As can be seen in the terminal where the server was started, ollama -v basically accesses the APi /api/version, i. e. something like
$ curl -s localhost:11434/api/version
Web API
$ curl -s http://localhost:11434/api/generate -d '{
"model" : "llama2",
"prompt": "tell me about programmers and coffe"
}' | jq
{
"error": "model 'llama2' not found"
}
The model is not available, we need to pull it:
$ curl -s http://localhost:11434/api/pull -d '{
"model": "llama2"
}' | jq
After downloading the model, query the available models:
$ curl -s http://localhost:11434/api/tags | jq -r '.models[].name'
Try again:
$ curl -s http://localhost:11434/api/generate -d '{
"model" : "llama2",
"prompt": "tell me about programmers and coffee"
}' | jq
{
"error": "model requires more system memory (8.4 GiB) than is available (1.8 GiB)"
}
Same thing, but on a machine with more memory:
$ curl -s http://localhost:11434/api/generate -d '{
"model" : "llama2",
"prompt": "tell me about programmers and coffee"
}' | jq
{
"model": "llama2",
"created_at": "2025-02-01T14:27:46.867393127Z",
"response": "\n",
"done": false
}
{
"model": "llama2",
"created_at": "2025-02-01T14:27:46.947556123Z",
"response": "Program",
"done": false
}
{
"model": "llama2",
"created_at": "2025-02-01T14:27:46.996489966Z",
"response": "mers",
"done": false
}
{
"model": "llama2",
"created_at": "2025-02-01T14:27:47.044551309Z",
"response": " and",
"done": false
}
…
{
"model": "llama2",
"created_at": "2025-02-01T14:28:57.985358597Z",
"response": "!",
"done": false
}
{
"model": "llama2",
"created_at": "2025-02-01T14:28:58.038683996Z",
"response": "",
"done": true,
"done_reason": "stop",
"context": [
518,
25580,
…
26529,
29991
],
"total_duration": 33946247078,
"load_duration": 7990899,
"prompt_eval_count": 29,
"prompt_eval_duration": 558000000,
"eval_count": 703,
"eval_duration": 33378000000
}
Checking if GPU is used
While a model is being used, ollama ps lists, among others, if a or the GPU is being used:
$ ollama ps
NAME ID SIZE PROCESSOR UNTIL
llama2:latest 78e26419b446 5.6 GB 100% GPU 4 minutes from now
Trying a model
Under
models/, I found some
*.gguf files which I believed I could use for a first test:
$ build/bin/llama-cli -m models/ggml-vocab-bert-bge.gguf --prompt "tell me a nice story" --predict 100
…
llama_model_load: error loading model: missing tensor 'token_embd.weight'
llama_model_load_from_file_impl: failed to load model
common_init_from_params: failed to load model 'models/ggml-vocab-bert-bge.gguf'
main: error: unable to load model
So, I download a couple of (small) models…
$ mkdir ~/llm-models
$ curl -L https://huggingface.co/aisuko/gpt2-117M-gguf/resolve/main/ggml-model-Q4_K_M.gguf -o ~/llm-models/ggml-model-Q4_K_M.gguf
$ curl -L https://huggingface.co/TheBloke/dolphin-2.2.1-mistral-7B-GGUF/resolve/main/dolphin-2.2.1-mistral-7b.Q4_K_M.gguf -o ~/llm-models/dolphin-2.2.1-mistral-7b.Q4_K_M.gguf
… show the sizes of the downloaded models …
$ (cd ~/llm-models; stat --printf '%s\t%n\n' *)
4368450304 dolphin-2.2.1-mistral-7b.Q4_K_M.gguf
112858624 ggml-model-Q4_K_M.gguf
… and test them with the CLI tool:
$ ./build/bin/llama-cli -m ~/llm-models/ggml-model-Q4_K_M.gguf -p "Tell me about programmers and coffee" -n 200
$ ./build/bin/llama-cli -m ~/llm-models/dolphin-2.2.1-mistral-7b.Q4_K_M.gguf -p "Tell me about programmers and coffee" -n 200
In Windows, with
PowerShell, a module can be downloaded with
PS:> $progressPreference = 'SilentlyContinue'
PS:> invoke-webRequest https://huggingface.co/TheBloke/dolphin-2.2.1-mistral-7B-GGUF/resolve/main/dolphin-2.2.1-mistral-7b.Q4_K_M.gguf -outfile ~/llm-models/dolphin-2.2.1-mistral-7b.Q4_K_M.gguf
Testing the webserver
A model can be run in a webserver and then accessed from a browser:
$ build/bin/llama-server -m ~/llm-models/dolphin-2.2.1-mistral-7b.Q4_K_M.gguf
By default, the server listens on port 8080, but this can be changed like so:
$ build/bin/llama-server -m ~/llm-models/dolphin-2.2.1-mistral-7b.Q4_K_M.gguf --port 8888
grammars/
GBNF (GGML BNF) as a format to constrain the output produced by llama.cpp (like, for example: only valid JSON, or emojis)
GBNF grammars can be useed in
-
llama-server (where the grammer is passed in the grammar body field)
-
llama-cli using the --grammar and --grammar-file flags
-
llama-gbnf-validator
-j (--json-schema) flag in action:
llama-cli \
-hfr bartowski/Phi-3-medium-128k-instruct-GGUF \
-hff Phi-3-medium-128k-instruct-Q8_0.gguf \
-j '{
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 100
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 150
}
},
"required": ["name", "age"],
"additionalProperties": false
},
"minItems": 10,
"maxItems": 100
}' \
-p 'Generate a {name, age}[] JSON array with famous actors of all ages.'
Any schema can be converted in the command line with
examples/json_schema_to_grammar.py name-age-schema.json
scripts
build-info.sh | |
check-requirements.sh | checks all requirements files for each top-level convert*.py script. |
ci-run.sh | What's the difference to ci/run.sh |
compare-commits.sh | Checks out two different commits from the repository, builds the project and then runs compare-llama-bench.py |
compare-llama-bench.py | |
debug-test.sh | |
gen-authors.sh | Adds new authors to the AUTHORS |
gen-unicode-data.py | |
get-flags.mk | |
get-hellaswag.sh | |
get_chat_template.py | Fetches the Jinja chat template of a HuggingFace model. |
get-pg.sh | |
get-wikitext-103.sh | |
get-wikitext-2.sh | |
get-winogrande.sh | |
hf.sh | Dowonload a Hugging Face (like for example ./llama-cli -m $(./scripts/hf.sh https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)) |
install-oneapi.bat | |
qnt-all.sh | |
run-all-perf.sh | |
run-all-ppl.sh | |
sync-ggml-am.sh | Synchronize ggml changes to llama.cpp |
sync-ggml.last | |
sync-ggml.sh | |
verify-checksum-models.py | |
xxd.cmake | |
cmake/x64-windows-llvm.cmake
The cmake directory contains a file named x64-windows-llvm.cmake.
Can this file explicitely be used for an LLVM build?