ollama2cpp 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ollama2cpp-0.1.1/LICENSE +21 -0
- ollama2cpp-0.1.1/PKG-INFO +210 -0
- ollama2cpp-0.1.1/README.md +191 -0
- ollama2cpp-0.1.1/pyproject.toml +64 -0
- ollama2cpp-0.1.1/setup.cfg +4 -0
- ollama2cpp-0.1.1/src/ollama2cpp/__init__.py +5 -0
- ollama2cpp-0.1.1/src/ollama2cpp/__main__.py +263 -0
- ollama2cpp-0.1.1/src/ollama2cpp/commands.py +648 -0
- ollama2cpp-0.1.1/src/ollama2cpp/config.py +233 -0
- ollama2cpp-0.1.1/src/ollama2cpp/constants.py +42 -0
- ollama2cpp-0.1.1/src/ollama2cpp/free_cmd.py +179 -0
- ollama2cpp-0.1.1/src/ollama2cpp/gguf.py +357 -0
- ollama2cpp-0.1.1/src/ollama2cpp/hardware.py +266 -0
- ollama2cpp-0.1.1/src/ollama2cpp/llamacpp.py +247 -0
- ollama2cpp-0.1.1/src/ollama2cpp/ollama.py +243 -0
- ollama2cpp-0.1.1/src/ollama2cpp/optimize_cmd.py +350 -0
- ollama2cpp-0.1.1/src/ollama2cpp/optimizer.py +873 -0
- ollama2cpp-0.1.1/src/ollama2cpp/proc.py +130 -0
- ollama2cpp-0.1.1/src/ollama2cpp/selector.py +150 -0
- ollama2cpp-0.1.1/src/ollama2cpp/server.py +640 -0
- ollama2cpp-0.1.1/src/ollama2cpp/ui.py +172 -0
- ollama2cpp-0.1.1/src/ollama2cpp/workflow.py +678 -0
- ollama2cpp-0.1.1/src/ollama2cpp.egg-info/PKG-INFO +210 -0
- ollama2cpp-0.1.1/src/ollama2cpp.egg-info/SOURCES.txt +42 -0
- ollama2cpp-0.1.1/src/ollama2cpp.egg-info/dependency_links.txt +1 -0
- ollama2cpp-0.1.1/src/ollama2cpp.egg-info/entry_points.txt +2 -0
- ollama2cpp-0.1.1/src/ollama2cpp.egg-info/requires.txt +3 -0
- ollama2cpp-0.1.1/src/ollama2cpp.egg-info/top_level.txt +1 -0
- ollama2cpp-0.1.1/tests/test_cli_basic.py +68 -0
- ollama2cpp-0.1.1/tests/test_cli_commands.py +1455 -0
- ollama2cpp-0.1.1/tests/test_cli_serve.py +961 -0
- ollama2cpp-0.1.1/tests/test_config.py +225 -0
- ollama2cpp-0.1.1/tests/test_free_cmd.py +274 -0
- ollama2cpp-0.1.1/tests/test_gguf.py +299 -0
- ollama2cpp-0.1.1/tests/test_hardware.py +334 -0
- ollama2cpp-0.1.1/tests/test_live.py +81 -0
- ollama2cpp-0.1.1/tests/test_llamacpp.py +251 -0
- ollama2cpp-0.1.1/tests/test_ollama.py +218 -0
- ollama2cpp-0.1.1/tests/test_optimizer_seed.py +186 -0
- ollama2cpp-0.1.1/tests/test_optimizer_sweep.py +1120 -0
- ollama2cpp-0.1.1/tests/test_proc.py +75 -0
- ollama2cpp-0.1.1/tests/test_selector.py +259 -0
- ollama2cpp-0.1.1/tests/test_server.py +494 -0
- ollama2cpp-0.1.1/tests/test_ui.py +82 -0
ollama2cpp-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jorge Albuquerque
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ollama2cpp
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Console app to start llama.cpp (llama-server) from Ollama available models
|
|
5
|
+
Author: Jorge Albuquerque
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: llm,ollama,llama.cpp,llama-server,gguf,cli,inference
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: psutil>=7
|
|
16
|
+
Requires-Dist: rich>=15.0.0
|
|
17
|
+
Requires-Dist: typer>=0.29.2
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# ollama2cpp
|
|
21
|
+
|
|
22
|
+
Start `llama-server` (llama.cpp) on the GGUF files of the models you already pulled with Ollama.
|
|
23
|
+
|
|
24
|
+
Ollama is convenient, but llama.cpp usually generates tokens faster once its settings fit your GPU
|
|
25
|
+
(layers offloaded, flash attention, threads, batch sizes). `ollama2cpp` reuses Ollama's model store, so
|
|
26
|
+
there is nothing to download or convert, picks sensible llama-server settings, and can benchmark your
|
|
27
|
+
machine to find the fastest ones. You get an OpenAI-compatible server at `http://127.0.0.1:8080`.
|
|
28
|
+
|
|
29
|
+
The Ollama directory is only ever read. Nothing is copied, moved or modified there.
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
- Python 3.12 or newer and [`uv`](https://docs.astral.sh/uv/).
|
|
36
|
+
- Ollama installed, with at least one model pulled (`ollama pull qwen3.5:9b`).
|
|
37
|
+
- llama.cpp (`llama-server`, `llama-bench`). On Windows the first run offers to install it with
|
|
38
|
+
`winget install ggml.llamacpp`; elsewhere install it yourself and put it on `PATH`.
|
|
39
|
+
|
|
40
|
+
## Install and run
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
uv sync
|
|
44
|
+
uv run ollama2cpp --help
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To get an `ollama2cpp` command on your `PATH`:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
uv tool install .
|
|
51
|
+
ollama2cpp --help
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
uv run ollama2cpp # same as `ollama2cpp serve`
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The first run, in order:
|
|
61
|
+
|
|
62
|
+
1. Installs llama.cpp with winget if `llama-server` is not found (asks first; `--yes` skips the question).
|
|
63
|
+
2. Finds the Ollama models directory (`--ollama-path`, `$OLLAMA_MODELS`, `~/.ollama/models`,
|
|
64
|
+
`%LOCALAPPDATA%\Ollama\models`, the Linux service path).
|
|
65
|
+
3. Picks the largest chat model that fits your VRAM (or the one you named with `--model`).
|
|
66
|
+
4. Writes `~/.ollama2cpp/config.json` and prints a summary.
|
|
67
|
+
5. Starts `llama-server` in the foreground. Ctrl-C stops it.
|
|
68
|
+
|
|
69
|
+
Later runs reuse the saved configuration. If the model has a saved profile (see `optimize`) its settings are
|
|
70
|
+
used, otherwise a heuristic seed is. Use `serve --dry-run` to see the exact command without running it.´
|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
Global options (before the command): `-v/--verbose`, `-m/--model NAME` (also read from `$OLLAMA_MODEL`),
|
|
77
|
+
`--version`.
|
|
78
|
+
|
|
79
|
+
| Command | What it does | Options |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| `serve` (default) | Start llama-server on a model. Extra llama-server arguments go after `--`. | `-m/--model`, `--ollama-path`, `--host`, `--port`, `--ctx`, `--detach`, `--restart`, `--dry-run`, `--vision`, `-y/--yes` |
|
|
82
|
+
| `list` | Installed models: kind, size, quantisation, whether it fits VRAM, optimized or not. | `--json` |
|
|
83
|
+
| `info MODEL` | GGUF details, layers, VRAM need and saved profiles of a model. | |
|
|
84
|
+
| `status` | Server state, config path, GPU memory, default model's profile. | |
|
|
85
|
+
| `stop` | Stop the server that ollama2cpp started. | |
|
|
86
|
+
| `free` | Unload Ollama's models, stop Ollama and the ollama2cpp server, and show the VRAM freed. Other GPU users are never touched. | `-y/--yes` |
|
|
87
|
+
| `doctor` | Check llama.cpp, Ollama, GPU, free VRAM and config, with fix hints. | |
|
|
88
|
+
| `update` | Upgrade llama.cpp with winget. | |
|
|
89
|
+
| `config` | Show the configuration and its path. | `--set KEY=VALUE` (repeatable), `--reset`, `-y/--yes` |
|
|
90
|
+
| `optimize [MODEL]` | Find the fastest settings for a model and save them. | `--quick`, `--all`, `--time-limit SECONDS`, `--ctx`, `--allow-kv-quant`, `--unload-ollama`, `--stop-server`, `-y/--yes` |
|
|
91
|
+
| `ver` | Print the version. | |
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
uv run ollama2cpp serve --model gemma4:12b --ctx 16384 --port 9000
|
|
97
|
+
uv run ollama2cpp serve --detach # return once the server is ready
|
|
98
|
+
uv run ollama2cpp serve -- --threads 8 # extra llama-server arguments
|
|
99
|
+
uv run ollama2cpp stop
|
|
100
|
+
uv run ollama2cpp free # stop Ollama and our server, free their VRAM
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Settable config keys: `host`, `port`, `device`, `ollama_path`, `default_model`, `llama_server`.
|
|
104
|
+
|
|
105
|
+
Sample `list` output (trimmed):
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
Ollama models in C:\Users\you\.ollama\models
|
|
109
|
+
┌───────────────────┬──────────┬────────┬────────┬────────┬─────────────┬───────────┬───────────┐
|
|
110
|
+
│ Name │ Size GiB │ Quant │ Arch │ Ctx │ Kind │ Fits VRAM │ Optimized │
|
|
111
|
+
├───────────────────┼──────────┼────────┼────────┼────────┼─────────────┼───────────┼───────────┤
|
|
112
|
+
│ gemma4:12b │ 6.9 │ Q4_K_M │ gemma4 │ 262144 │ chat │ no │ no │
|
|
113
|
+
│ lfm3-audio:2b │ 1.0 │ Q4_K_M │ lfm3 │ 128000 │ unsupported │ - │ - │
|
|
114
|
+
│ qwen3-embedding:4b│ 2.3 │ Q4_K_M │ qwen3 │ 40960 │ embedding │ - │ - │
|
|
115
|
+
│ qwen3.5:9b-q4_k_m │ 5.2 │ Q4_K_M │ qwen35 │ 262144 │ chat │ yes │ no │
|
|
116
|
+
└───────────────────┴──────────┴────────┴────────┴────────┴─────────────┴───────────┴───────────┘
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
(The real table also has a `Note` column. `list --json` prints only a JSON array on stdout.)
|
|
120
|
+
|
|
121
|
+
## How `optimize` works
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
uv run ollama2cpp optimize qwen3.5:9b-q4_k_m
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
1. Heuristic seed: from the GGUF metadata and your hardware it computes layers to offload, flash attention,
|
|
128
|
+
thread count and batch sizes.
|
|
129
|
+
2. `llama-bench` sweep: it benchmarks variations around the seed, within `--time-limit` seconds per model
|
|
130
|
+
(default 300), and keeps the one with the best generation speed (tokens/s).
|
|
131
|
+
3. Real-server validation: the winner is started in a real `llama-server` and must come up and answer
|
|
132
|
+
before it is accepted (a failure steps down once, then the unmeasured seed is saved).
|
|
133
|
+
4. The result is saved per model and context size in the config file; `serve` uses it automatically.
|
|
134
|
+
|
|
135
|
+
Options:
|
|
136
|
+
|
|
137
|
+
- `--quick`: skip the benchmark and save the heuristic seed (unmeasured). Seconds, not minutes.
|
|
138
|
+
- `--all`: optimize every chat model, one after another (a failure on one does not stop the rest).
|
|
139
|
+
- `--ctx N`: context size to optimize for (default 8192). Profiles are per model and context size.
|
|
140
|
+
- `--allow-kv-quant`: also try a `q8_0` KV cache. Faster or smaller, but it can affect output quality, so it is off by default.
|
|
141
|
+
- `--unload-ollama`: if Ollama holds the VRAM the model needs, ask it to unload its models first.
|
|
142
|
+
- `--stop-server`: stop the ollama2cpp server that is running (it holds VRAM) before benchmarking.
|
|
143
|
+
|
|
144
|
+
The sweep optimizes for the VRAM that is free right now. A model that does not fit completely is benchmarked
|
|
145
|
+
with a partial offload (the number of GPU layers is part of the sweep), and a model larger than the card is
|
|
146
|
+
always a partial offload. `optimize` refuses only when other processes hold a lot of VRAM (more than 1 GiB) and
|
|
147
|
+
the model needs memory that is not free; it then says how much is in use and how to free it (see
|
|
148
|
+
Troubleshooting). Ctrl-C keeps the best result measured so far: it is saved without the final validation and
|
|
149
|
+
`serve` says so.
|
|
150
|
+
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
Stored in `~/.ollama2cpp/config.json` (set `OLLAMA2CPP_HOME` to use another directory). It holds the
|
|
154
|
+
paths of `llama-server`/`llama-bench` and the Ollama directory, the default model, host, port, an optional
|
|
155
|
+
pinned `device`, and the saved `profiles`. Writes are atomic and a broken file is moved to `config.json.bak` and treated as missing, never a crash.
|
|
156
|
+
`ollama2cpp config` shows it; `config --set port=9000` edits it; `config --reset` deletes it.
|
|
157
|
+
|
|
158
|
+
Environment variables:
|
|
159
|
+
|
|
160
|
+
| Variable | Effect |
|
|
161
|
+
| --- | --- |
|
|
162
|
+
| `OLLAMA_MODELS` | Ollama models directory (same variable Ollama uses). |
|
|
163
|
+
| `OLLAMA_MODEL` | Default model name, as if `--model` were given. |
|
|
164
|
+
| `OLLAMA2CPP_HOME` | Where ollama2cpp keeps its config and server pid file. |
|
|
165
|
+
|
|
166
|
+
## Safety
|
|
167
|
+
|
|
168
|
+
- The Ollama directory is read-only for ollama2cpp.
|
|
169
|
+
- `stop`, `--restart` and `--stop-server` only affect a server that ollama2cpp started itself (tracked in
|
|
170
|
+
its own pid file). Other llama-server processes, and Ollama, are never killed.
|
|
171
|
+
- `--unload-ollama` only asks Ollama to unload models through its API; it does not stop Ollama.
|
|
172
|
+
|
|
173
|
+
## Troubleshooting
|
|
174
|
+
|
|
175
|
+
- Run `uv run ollama2cpp doctor` first; it names the failing check and a fix.
|
|
176
|
+
- `optimize` says VRAM is short: Ollama keeps models loaded for a while after use. Run `ollama stop MODEL`
|
|
177
|
+
or pass `--unload-ollama`. Also close other GPU users, or stop our own server (`stop` / `--stop-server`).
|
|
178
|
+
- Several GPUs (for example an NVIDIA card plus an integrated AMD GPU under Vulkan): `doctor` and `status`
|
|
179
|
+
list them. ollama2cpp picks the best one; to pin another, use `config --set device=Vulkan1`
|
|
180
|
+
(ids as printed by `llama-server --list-devices`). `config --set device=none` goes back to automatic.
|
|
181
|
+
- `Model 'x' not found`: a model you name with `--model` (or as the `optimize` argument) must be installed; the
|
|
182
|
+
error lists the installed models. An `OLLAMA_MODEL` that names a model you do not have is not an error:
|
|
183
|
+
ollama2cpp warns and falls back to the saved default, then to the automatic choice. Unset it to silence
|
|
184
|
+
the warning.
|
|
185
|
+
- `llama-bench was not found` (`optimize` without `--quick`): run `ollama2cpp doctor` to see what is missing, then
|
|
186
|
+
`ollama2cpp update` (or install the full llama.cpp release that ships `llama-bench`).
|
|
187
|
+
- `serve` says the server is already running: its settings may differ from the current profile or options (for
|
|
188
|
+
example after `optimize`); run `serve --restart` to stop it and start it again with the current ones.
|
|
189
|
+
- `llama-server was not found` and winget is missing (or this is not Windows): install llama.cpp from
|
|
190
|
+
<https://github.com/ggml-org/llama.cpp/releases>, put it on `PATH`, or `config --set llama_server=PATH`.
|
|
191
|
+
- Port in use: `serve --port 9000`, or `stop` if it is our own server.
|
|
192
|
+
|
|
193
|
+
## Development
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
uv run ruff format .
|
|
197
|
+
uv run ruff check . --fix
|
|
198
|
+
uv run pyrefly check
|
|
199
|
+
uv run pytest -x
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
`uv run pytest` skips the `live` tests and enforces 90% coverage. The live smoke tests use your real Ollama
|
|
203
|
+
directory and real `llama-server` (they never start a server or run a benchmark) and skip when either is
|
|
204
|
+
missing, or when your models live in a custom `OLLAMA_MODELS` directory (the tests clear that variable so they
|
|
205
|
+
only look at the default locations). Run them with `--no-cov`: they exercise a small part of the code, so the
|
|
206
|
+
90% coverage gate would fail a live-only run.
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
uv run pytest -m live --no-cov
|
|
210
|
+
```
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# ollama2cpp
|
|
2
|
+
|
|
3
|
+
Start `llama-server` (llama.cpp) on the GGUF files of the models you already pulled with Ollama.
|
|
4
|
+
|
|
5
|
+
Ollama is convenient, but llama.cpp usually generates tokens faster once its settings fit your GPU
|
|
6
|
+
(layers offloaded, flash attention, threads, batch sizes). `ollama2cpp` reuses Ollama's model store, so
|
|
7
|
+
there is nothing to download or convert, picks sensible llama-server settings, and can benchmark your
|
|
8
|
+
machine to find the fastest ones. You get an OpenAI-compatible server at `http://127.0.0.1:8080`.
|
|
9
|
+
|
|
10
|
+
The Ollama directory is only ever read. Nothing is copied, moved or modified there.
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- Python 3.12 or newer and [`uv`](https://docs.astral.sh/uv/).
|
|
17
|
+
- Ollama installed, with at least one model pulled (`ollama pull qwen3.5:9b`).
|
|
18
|
+
- llama.cpp (`llama-server`, `llama-bench`). On Windows the first run offers to install it with
|
|
19
|
+
`winget install ggml.llamacpp`; elsewhere install it yourself and put it on `PATH`.
|
|
20
|
+
|
|
21
|
+
## Install and run
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
uv sync
|
|
25
|
+
uv run ollama2cpp --help
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
To get an `ollama2cpp` command on your `PATH`:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
uv tool install .
|
|
32
|
+
ollama2cpp --help
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
uv run ollama2cpp # same as `ollama2cpp serve`
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The first run, in order:
|
|
42
|
+
|
|
43
|
+
1. Installs llama.cpp with winget if `llama-server` is not found (asks first; `--yes` skips the question).
|
|
44
|
+
2. Finds the Ollama models directory (`--ollama-path`, `$OLLAMA_MODELS`, `~/.ollama/models`,
|
|
45
|
+
`%LOCALAPPDATA%\Ollama\models`, the Linux service path).
|
|
46
|
+
3. Picks the largest chat model that fits your VRAM (or the one you named with `--model`).
|
|
47
|
+
4. Writes `~/.ollama2cpp/config.json` and prints a summary.
|
|
48
|
+
5. Starts `llama-server` in the foreground. Ctrl-C stops it.
|
|
49
|
+
|
|
50
|
+
Later runs reuse the saved configuration. If the model has a saved profile (see `optimize`) its settings are
|
|
51
|
+
used, otherwise a heuristic seed is. Use `serve --dry-run` to see the exact command without running it.´
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
## Commands
|
|
56
|
+
|
|
57
|
+
Global options (before the command): `-v/--verbose`, `-m/--model NAME` (also read from `$OLLAMA_MODEL`),
|
|
58
|
+
`--version`.
|
|
59
|
+
|
|
60
|
+
| Command | What it does | Options |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `serve` (default) | Start llama-server on a model. Extra llama-server arguments go after `--`. | `-m/--model`, `--ollama-path`, `--host`, `--port`, `--ctx`, `--detach`, `--restart`, `--dry-run`, `--vision`, `-y/--yes` |
|
|
63
|
+
| `list` | Installed models: kind, size, quantisation, whether it fits VRAM, optimized or not. | `--json` |
|
|
64
|
+
| `info MODEL` | GGUF details, layers, VRAM need and saved profiles of a model. | |
|
|
65
|
+
| `status` | Server state, config path, GPU memory, default model's profile. | |
|
|
66
|
+
| `stop` | Stop the server that ollama2cpp started. | |
|
|
67
|
+
| `free` | Unload Ollama's models, stop Ollama and the ollama2cpp server, and show the VRAM freed. Other GPU users are never touched. | `-y/--yes` |
|
|
68
|
+
| `doctor` | Check llama.cpp, Ollama, GPU, free VRAM and config, with fix hints. | |
|
|
69
|
+
| `update` | Upgrade llama.cpp with winget. | |
|
|
70
|
+
| `config` | Show the configuration and its path. | `--set KEY=VALUE` (repeatable), `--reset`, `-y/--yes` |
|
|
71
|
+
| `optimize [MODEL]` | Find the fastest settings for a model and save them. | `--quick`, `--all`, `--time-limit SECONDS`, `--ctx`, `--allow-kv-quant`, `--unload-ollama`, `--stop-server`, `-y/--yes` |
|
|
72
|
+
| `ver` | Print the version. | |
|
|
73
|
+
|
|
74
|
+
Examples:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
uv run ollama2cpp serve --model gemma4:12b --ctx 16384 --port 9000
|
|
78
|
+
uv run ollama2cpp serve --detach # return once the server is ready
|
|
79
|
+
uv run ollama2cpp serve -- --threads 8 # extra llama-server arguments
|
|
80
|
+
uv run ollama2cpp stop
|
|
81
|
+
uv run ollama2cpp free # stop Ollama and our server, free their VRAM
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Settable config keys: `host`, `port`, `device`, `ollama_path`, `default_model`, `llama_server`.
|
|
85
|
+
|
|
86
|
+
Sample `list` output (trimmed):
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
Ollama models in C:\Users\you\.ollama\models
|
|
90
|
+
┌───────────────────┬──────────┬────────┬────────┬────────┬─────────────┬───────────┬───────────┐
|
|
91
|
+
│ Name │ Size GiB │ Quant │ Arch │ Ctx │ Kind │ Fits VRAM │ Optimized │
|
|
92
|
+
├───────────────────┼──────────┼────────┼────────┼────────┼─────────────┼───────────┼───────────┤
|
|
93
|
+
│ gemma4:12b │ 6.9 │ Q4_K_M │ gemma4 │ 262144 │ chat │ no │ no │
|
|
94
|
+
│ lfm3-audio:2b │ 1.0 │ Q4_K_M │ lfm3 │ 128000 │ unsupported │ - │ - │
|
|
95
|
+
│ qwen3-embedding:4b│ 2.3 │ Q4_K_M │ qwen3 │ 40960 │ embedding │ - │ - │
|
|
96
|
+
│ qwen3.5:9b-q4_k_m │ 5.2 │ Q4_K_M │ qwen35 │ 262144 │ chat │ yes │ no │
|
|
97
|
+
└───────────────────┴──────────┴────────┴────────┴────────┴─────────────┴───────────┴───────────┘
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
(The real table also has a `Note` column. `list --json` prints only a JSON array on stdout.)
|
|
101
|
+
|
|
102
|
+
## How `optimize` works
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
uv run ollama2cpp optimize qwen3.5:9b-q4_k_m
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
1. Heuristic seed: from the GGUF metadata and your hardware it computes layers to offload, flash attention,
|
|
109
|
+
thread count and batch sizes.
|
|
110
|
+
2. `llama-bench` sweep: it benchmarks variations around the seed, within `--time-limit` seconds per model
|
|
111
|
+
(default 300), and keeps the one with the best generation speed (tokens/s).
|
|
112
|
+
3. Real-server validation: the winner is started in a real `llama-server` and must come up and answer
|
|
113
|
+
before it is accepted (a failure steps down once, then the unmeasured seed is saved).
|
|
114
|
+
4. The result is saved per model and context size in the config file; `serve` uses it automatically.
|
|
115
|
+
|
|
116
|
+
Options:
|
|
117
|
+
|
|
118
|
+
- `--quick`: skip the benchmark and save the heuristic seed (unmeasured). Seconds, not minutes.
|
|
119
|
+
- `--all`: optimize every chat model, one after another (a failure on one does not stop the rest).
|
|
120
|
+
- `--ctx N`: context size to optimize for (default 8192). Profiles are per model and context size.
|
|
121
|
+
- `--allow-kv-quant`: also try a `q8_0` KV cache. Faster or smaller, but it can affect output quality, so it is off by default.
|
|
122
|
+
- `--unload-ollama`: if Ollama holds the VRAM the model needs, ask it to unload its models first.
|
|
123
|
+
- `--stop-server`: stop the ollama2cpp server that is running (it holds VRAM) before benchmarking.
|
|
124
|
+
|
|
125
|
+
The sweep optimizes for the VRAM that is free right now. A model that does not fit completely is benchmarked
|
|
126
|
+
with a partial offload (the number of GPU layers is part of the sweep), and a model larger than the card is
|
|
127
|
+
always a partial offload. `optimize` refuses only when other processes hold a lot of VRAM (more than 1 GiB) and
|
|
128
|
+
the model needs memory that is not free; it then says how much is in use and how to free it (see
|
|
129
|
+
Troubleshooting). Ctrl-C keeps the best result measured so far: it is saved without the final validation and
|
|
130
|
+
`serve` says so.
|
|
131
|
+
|
|
132
|
+
## Configuration
|
|
133
|
+
|
|
134
|
+
Stored in `~/.ollama2cpp/config.json` (set `OLLAMA2CPP_HOME` to use another directory). It holds the
|
|
135
|
+
paths of `llama-server`/`llama-bench` and the Ollama directory, the default model, host, port, an optional
|
|
136
|
+
pinned `device`, and the saved `profiles`. Writes are atomic and a broken file is moved to `config.json.bak` and treated as missing, never a crash.
|
|
137
|
+
`ollama2cpp config` shows it; `config --set port=9000` edits it; `config --reset` deletes it.
|
|
138
|
+
|
|
139
|
+
Environment variables:
|
|
140
|
+
|
|
141
|
+
| Variable | Effect |
|
|
142
|
+
| --- | --- |
|
|
143
|
+
| `OLLAMA_MODELS` | Ollama models directory (same variable Ollama uses). |
|
|
144
|
+
| `OLLAMA_MODEL` | Default model name, as if `--model` were given. |
|
|
145
|
+
| `OLLAMA2CPP_HOME` | Where ollama2cpp keeps its config and server pid file. |
|
|
146
|
+
|
|
147
|
+
## Safety
|
|
148
|
+
|
|
149
|
+
- The Ollama directory is read-only for ollama2cpp.
|
|
150
|
+
- `stop`, `--restart` and `--stop-server` only affect a server that ollama2cpp started itself (tracked in
|
|
151
|
+
its own pid file). Other llama-server processes, and Ollama, are never killed.
|
|
152
|
+
- `--unload-ollama` only asks Ollama to unload models through its API; it does not stop Ollama.
|
|
153
|
+
|
|
154
|
+
## Troubleshooting
|
|
155
|
+
|
|
156
|
+
- Run `uv run ollama2cpp doctor` first; it names the failing check and a fix.
|
|
157
|
+
- `optimize` says VRAM is short: Ollama keeps models loaded for a while after use. Run `ollama stop MODEL`
|
|
158
|
+
or pass `--unload-ollama`. Also close other GPU users, or stop our own server (`stop` / `--stop-server`).
|
|
159
|
+
- Several GPUs (for example an NVIDIA card plus an integrated AMD GPU under Vulkan): `doctor` and `status`
|
|
160
|
+
list them. ollama2cpp picks the best one; to pin another, use `config --set device=Vulkan1`
|
|
161
|
+
(ids as printed by `llama-server --list-devices`). `config --set device=none` goes back to automatic.
|
|
162
|
+
- `Model 'x' not found`: a model you name with `--model` (or as the `optimize` argument) must be installed; the
|
|
163
|
+
error lists the installed models. An `OLLAMA_MODEL` that names a model you do not have is not an error:
|
|
164
|
+
ollama2cpp warns and falls back to the saved default, then to the automatic choice. Unset it to silence
|
|
165
|
+
the warning.
|
|
166
|
+
- `llama-bench was not found` (`optimize` without `--quick`): run `ollama2cpp doctor` to see what is missing, then
|
|
167
|
+
`ollama2cpp update` (or install the full llama.cpp release that ships `llama-bench`).
|
|
168
|
+
- `serve` says the server is already running: its settings may differ from the current profile or options (for
|
|
169
|
+
example after `optimize`); run `serve --restart` to stop it and start it again with the current ones.
|
|
170
|
+
- `llama-server was not found` and winget is missing (or this is not Windows): install llama.cpp from
|
|
171
|
+
<https://github.com/ggml-org/llama.cpp/releases>, put it on `PATH`, or `config --set llama_server=PATH`.
|
|
172
|
+
- Port in use: `serve --port 9000`, or `stop` if it is our own server.
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
uv run ruff format .
|
|
178
|
+
uv run ruff check . --fix
|
|
179
|
+
uv run pyrefly check
|
|
180
|
+
uv run pytest -x
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`uv run pytest` skips the `live` tests and enforces 90% coverage. The live smoke tests use your real Ollama
|
|
184
|
+
directory and real `llama-server` (they never start a server or run a benchmark) and skip when either is
|
|
185
|
+
missing, or when your models live in a custom `OLLAMA_MODELS` directory (the tests clear that variable so they
|
|
186
|
+
only look at the default locations). Run them with `--no-cov`: they exercise a small part of the code, so the
|
|
187
|
+
90% coverage gate would fail a live-only run.
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
uv run pytest -m live --no-cov
|
|
191
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ollama2cpp"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Console app to start llama.cpp (llama-server) from Ollama available models"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
authors = [{ name = "Jorge Albuquerque" }]
|
|
12
|
+
license = { text = "MIT" }
|
|
13
|
+
keywords = ["llm", "ollama", "llama.cpp", "llama-server", "gguf", "cli", "inference"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: End Users/Desktop",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"psutil>=7",
|
|
22
|
+
"rich>=15.0.0",
|
|
23
|
+
"typer>=0.29.2",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
ollama2cpp = "ollama2cpp.__main__:main"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools]
|
|
30
|
+
packages = ["ollama2cpp"]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.package-dir]
|
|
33
|
+
"" = "src"
|
|
34
|
+
|
|
35
|
+
[tool.pytest.ini_options]
|
|
36
|
+
testpaths = ["tests"]
|
|
37
|
+
python_files = ["test_*.py"]
|
|
38
|
+
addopts = "-v --strict-markers -m \"not live\" --cov=src/ollama2cpp --cov-report=term-missing --cov-fail-under=90"
|
|
39
|
+
markers = [
|
|
40
|
+
"slow: marks tests as slow",
|
|
41
|
+
"live: hits real external services (Ollama / llama-server); deselected by default",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.coverage.run]
|
|
45
|
+
branch = true
|
|
46
|
+
|
|
47
|
+
[tool.coverage.report]
|
|
48
|
+
exclude_lines = [
|
|
49
|
+
"pragma: no cover",
|
|
50
|
+
"if __name__ == .__main__.:",
|
|
51
|
+
"if TYPE_CHECKING:",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[tool.pyrefly]
|
|
55
|
+
project-includes = ["src/**/*.py", "tests/**/*.py"]
|
|
56
|
+
search-path = ["src", "."]
|
|
57
|
+
|
|
58
|
+
[dependency-groups]
|
|
59
|
+
dev = [
|
|
60
|
+
"pyrefly>=1.5.0",
|
|
61
|
+
"pytest>=9.2.0",
|
|
62
|
+
"pytest-cov>=7.1.0",
|
|
63
|
+
"ruff>=0.17.6"
|
|
64
|
+
]
|