v0.2 step 14 — top_k, min_p, repetition_penalty (#49)
Accepts the sampling settings mlx-swift-lm implements beyond OpenAI's, under the names vLLM, llama-server, Ollama and mlx-lm use, in requests and in the configuration's defaults / locked blocks. With a penalty active, the prompt cache leaves the penalty window to be computed again, so answers match a full prefill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17b9753 parent: a485576 modified
.memory/handoffs/2026-11-25-v0-2-server-foundation.md +5 -0 | @@ -116,3 +116,8 @@ already exists), #49 (sampling params; scope to decide with the user). Suggested | ||
| 116 | 116 | `cached=N` in the `rzb serve` log on a long conversation, and run `scripts/compat.sh` on the Mac |
| 117 | 117 | (not run since #44). Trap seen: `host.sh test` started with `&` inside a Bash call survives, but use |
| 118 | 118 | run_in_background so a notification arrives. |
| 119 | + | |
| 120 | +## Update — #49 done | |
| 121 | +Sampling extensions in (see summary). v0.2 milestone: only #47 left open (spike leftovers, tasks | |
| 122 | +3–6; proposed to move them to a later milestone — user not asked yet). Still to suggest: Mac compat | |
| 123 | +run, real `rzb serve` check of `cached=N`, release (version still 0.1.0). | |
| @@ -116,3 +116,8 @@ already exists), #49 (sampling params; scope to decide with the user). Suggested | |||
| 116 | `cached=N` in the `rzb serve` log on a long conversation, and run `scripts/compat.sh` on the Mac | 116 | `cached=N` in the `rzb serve` log on a long conversation, and run `scripts/compat.sh` on the Mac |
| 117 | (not run since #44). Trap seen: `host.sh test` started with `&` inside a Bash call survives, but use | 117 | (not run since #44). Trap seen: `host.sh test` started with `&` inside a Bash call survives, but use |
| 118 | run_in_background so a notification arrives. | 118 | run_in_background so a notification arrives. |
| 119 | + | ||
| 120 | +## Update — #49 done | ||
| 121 | +Sampling extensions in (see summary). v0.2 milestone: only #47 left open (spike leftovers, tasks | ||
| 122 | +3–6; proposed to move them to a later milestone — user not asked yet). Still to suggest: Mac compat | ||
| 123 | +run, real `rzb serve` check of `cached=N`, release (version still 0.1.0). | ||
modified
.memory/history.md +13 -0 | @@ -294,3 +294,16 @@ Mac 193 incl. a smoke test (second turn reuses the cache, same answer as a fresh | ||
| 294 | 294 | fixed by a struct, splitting send, moving MLXSession to its own file → PASS. Docs EN+FR: lifecycle |
| 295 | 295 | section "Reusing the previous prompt", http-api usage field, cli log suffix, architecture step 4. |
| 296 | 296 | Not done: real `rzb serve` measurement and Mac compat run (need the user). |
| 297 | + | |
| 298 | +## 2026-11-26 — #49 sampling parameters (what mlx-swift-lm implements) | |
| 299 | + | |
| 300 | +User asked which sampling parameters exist beyond those handled; listed OpenAI's (logit_bias ignored, | |
| 301 | +penalties on a 20-token window), the common extensions (top_k, min_p, repetition_penalty — in mlx) | |
| 302 | +and llama-server/vLLM-only ones (typical_p, XTC, DRY, Mirostat, top_n_sigma, min_tokens — not in | |
| 303 | +mlx). User: implement only what mlx knows. Added top_k, min_p, repetition_penalty, | |
| 304 | +repetition_context_size (request + config defaults/locked), passed to GenerateParameters. Found and | |
| 305 | +fixed an interaction with #48: mlx penalties seed their window from the prompt tokens fed, so the | |
| 306 | +prompt cache now leaves at least the window to compute. Not done (by the user's rule): logit_bias | |
| 307 | +(still ignored), generation_config.json defaults, OpenAI-style whole-answer penalties. Tests Linux | |
| 308 | +172, Mac 198 (cache smoke test parametrized with repetition_penalty 1.3), compat Linux 51/20. Gate | |
| 309 | +PASS first time. Docs EN+FR: http-api, configuration, openai-compatibility, examples/server.yaml. | |
| @@ -294,3 +294,16 @@ Mac 193 incl. a smoke test (second turn reuses the cache, same answer as a fresh | |||
| 294 | fixed by a struct, splitting send, moving MLXSession to its own file → PASS. Docs EN+FR: lifecycle | 294 | fixed by a struct, splitting send, moving MLXSession to its own file → PASS. Docs EN+FR: lifecycle |
| 295 | section "Reusing the previous prompt", http-api usage field, cli log suffix, architecture step 4. | 295 | section "Reusing the previous prompt", http-api usage field, cli log suffix, architecture step 4. |
| 296 | Not done: real `rzb serve` measurement and Mac compat run (need the user). | 296 | Not done: real `rzb serve` measurement and Mac compat run (need the user). |
| 297 | + | ||
| 298 | +## 2026-11-26 — #49 sampling parameters (what mlx-swift-lm implements) | ||
| 299 | + | ||
| 300 | +User asked which sampling parameters exist beyond those handled; listed OpenAI's (logit_bias ignored, | ||
| 301 | +penalties on a 20-token window), the common extensions (top_k, min_p, repetition_penalty — in mlx) | ||
| 302 | +and llama-server/vLLM-only ones (typical_p, XTC, DRY, Mirostat, top_n_sigma, min_tokens — not in | ||
| 303 | +mlx). User: implement only what mlx knows. Added top_k, min_p, repetition_penalty, | ||
| 304 | +repetition_context_size (request + config defaults/locked), passed to GenerateParameters. Found and | ||
| 305 | +fixed an interaction with #48: mlx penalties seed their window from the prompt tokens fed, so the | ||
| 306 | +prompt cache now leaves at least the window to compute. Not done (by the user's rule): logit_bias | ||
| 307 | +(still ignored), generation_config.json defaults, OpenAI-style whole-answer penalties. Tests Linux | ||
| 308 | +172, Mac 198 (cache smoke test parametrized with repetition_penalty 1.3), compat Linux 51/20. Gate | ||
| 309 | +PASS first time. Docs EN+FR: http-api, configuration, openai-compatibility, examples/server.yaml. | ||
modified
.memory/summary.md +9 -1 | @@ -207,7 +207,15 @@ Mac (MLX, Qwen3-4B + bge-small + Llama-3.2-3B): 45/46 before the #43 fixes; re-r | ||
| 207 | 207 | 46 pass, 1 skip (docs curl, until #45), 80 s. compat.sh always rebuilds rzb (incremental) unless RZB_BIN is set. |
| 208 | 208 | Tests 2026-11-25 after #43 fixes: Linux 155, Mac 178. After #44: Linux 161, Mac 185, compat on |
| 209 | 209 | Linux 34 pass / 21 skip (Mac compat not re-run after #44). After #48 (prompt cache): Linux 168, Mac 193, |
| 210 | -compat on Linux 48 pass / 20 skip (Mac compat not re-run since #44). | |
| 210 | +compat on Linux 48 pass / 20 skip. After #49: Linux 172, Mac 198, compat Linux 51 / 20 (Mac compat | |
| 211 | +not re-run since #44). | |
| 212 | + | |
| 213 | +Sampling (#49, user's rule: only what mlx-swift-lm implements): temperature, top_p, max_tokens, | |
| 214 | +stop, seed, presence/frequency_penalty (mlx window: last 20 tokens incl. prompt), plus extensions | |
| 215 | +top_k, min_p, repetition_penalty, repetition_context_size — request (`SamplingExtensions`, decoded | |
| 216 | +from the same body) and config defaults/locked (imposed). logit_bias, typical_p, XTC, DRY, Mirostat | |
| 217 | +are ignored (not in mlx-swift-lm); generation_config.json sampling values are not read. With a | |
| 218 | +penalty active, the prompt cache recomputes at least the penalty window (`PromptPrefix computing:`). | |
| 211 | 219 | |
| 212 | 220 | ## mlx-swift-lm API version trap |
| 213 | 221 | |
| @@ -207,7 +207,15 @@ Mac (MLX, Qwen3-4B + bge-small + Llama-3.2-3B): 45/46 before the #43 fixes; re-r | |||
| 207 | 46 pass, 1 skip (docs curl, until #45), 80 s. compat.sh always rebuilds rzb (incremental) unless RZB_BIN is set. | 207 | 46 pass, 1 skip (docs curl, until #45), 80 s. compat.sh always rebuilds rzb (incremental) unless RZB_BIN is set. |
| 208 | Tests 2026-11-25 after #43 fixes: Linux 155, Mac 178. After #44: Linux 161, Mac 185, compat on | 208 | Tests 2026-11-25 after #43 fixes: Linux 155, Mac 178. After #44: Linux 161, Mac 185, compat on |
| 209 | Linux 34 pass / 21 skip (Mac compat not re-run after #44). After #48 (prompt cache): Linux 168, Mac 193, | 209 | Linux 34 pass / 21 skip (Mac compat not re-run after #44). After #48 (prompt cache): Linux 168, Mac 193, |
| 210 | -compat on Linux 48 pass / 20 skip (Mac compat not re-run since #44). | 210 | +compat on Linux 48 pass / 20 skip. After #49: Linux 172, Mac 198, compat Linux 51 / 20 (Mac compat |
| 211 | +not re-run since #44). | ||
| 212 | + | ||
| 213 | +Sampling (#49, user's rule: only what mlx-swift-lm implements): temperature, top_p, max_tokens, | ||
| 214 | +stop, seed, presence/frequency_penalty (mlx window: last 20 tokens incl. prompt), plus extensions | ||
| 215 | +top_k, min_p, repetition_penalty, repetition_context_size — request (`SamplingExtensions`, decoded | ||
| 216 | +from the same body) and config defaults/locked (imposed). logit_bias, typical_p, XTC, DRY, Mirostat | ||
| 217 | +are ignored (not in mlx-swift-lm); generation_config.json sampling values are not read. With a | ||
| 218 | +penalty active, the prompt cache recomputes at least the penalty window (`PromptPrefix computing:`). | ||
| 211 | 219 | ||
| 212 | ## mlx-swift-lm API version trap | 220 | ## mlx-swift-lm API version trap |
| 213 | 221 | ||
modified
.quality/history.jsonl +2 -0 | @@ -24,3 +24,5 @@ | ||
| 24 | 24 | {"branch": "feature/v0.2-openai-server", "breaches": ["warning-level issues: 1 (max 0)", "code smells: 1 (max 0)"], "commit": "b5ef2e8", "counts": {"warning": 1}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": false, "metrics": {"classes": 231, "complex": 559, "cyclo": 603, "fields": 1178, "funcs": 571, "lcom": 113, "lines": 10467, "loc": 8320}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 24, "smells": 1, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:37:24Z"} |
| 25 | 25 | {"branch": "feature/v0.2-openai-server", "breaches": ["warning-level issues: 1 (max 0)"], "commit": "b5ef2e8", "counts": {"warning": 1}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": false, "metrics": {"classes": 232, "complex": 544, "cyclo": 601, "fields": 1182, "funcs": 573, "lcom": 114, "lines": 10488, "loc": 8337}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 25, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:37:51Z"} |
| 26 | 26 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "b5ef2e8", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 232, "complex": 544, "cyclo": 602, "fields": 1189, "funcs": 573, "lcom": 115, "lines": 10494, "loc": 8343}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 26, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:38:24Z"} |
| 27 | +{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "a485576", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 546, "cyclo": 604, "fields": 1209, "funcs": 582, "lcom": 115, "lines": 10665, "loc": 8489}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 27, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T22:01:44Z"} | |
| 28 | +{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "a485576", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 546, "cyclo": 604, "fields": 1209, "funcs": 582, "lcom": 115, "lines": 10669, "loc": 8492}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 28, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T22:03:59Z"} | |
| @@ -24,3 +24,5 @@ | |||
| 24 | {"branch": "feature/v0.2-openai-server", "breaches": ["warning-level issues: 1 (max 0)", "code smells: 1 (max 0)"], "commit": "b5ef2e8", "counts": {"warning": 1}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": false, "metrics": {"classes": 231, "complex": 559, "cyclo": 603, "fields": 1178, "funcs": 571, "lcom": 113, "lines": 10467, "loc": 8320}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 24, "smells": 1, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:37:24Z"} | 24 | {"branch": "feature/v0.2-openai-server", "breaches": ["warning-level issues: 1 (max 0)", "code smells: 1 (max 0)"], "commit": "b5ef2e8", "counts": {"warning": 1}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": false, "metrics": {"classes": 231, "complex": 559, "cyclo": 603, "fields": 1178, "funcs": 571, "lcom": 113, "lines": 10467, "loc": 8320}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 24, "smells": 1, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:37:24Z"} |
| 25 | {"branch": "feature/v0.2-openai-server", "breaches": ["warning-level issues: 1 (max 0)"], "commit": "b5ef2e8", "counts": {"warning": 1}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": false, "metrics": {"classes": 232, "complex": 544, "cyclo": 601, "fields": 1182, "funcs": 573, "lcom": 114, "lines": 10488, "loc": 8337}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 25, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:37:51Z"} | 25 | {"branch": "feature/v0.2-openai-server", "breaches": ["warning-level issues: 1 (max 0)"], "commit": "b5ef2e8", "counts": {"warning": 1}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": false, "metrics": {"classes": 232, "complex": 544, "cyclo": 601, "fields": 1182, "funcs": 573, "lcom": 114, "lines": 10488, "loc": 8337}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 25, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:37:51Z"} |
| 26 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "b5ef2e8", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 232, "complex": 544, "cyclo": 602, "fields": 1189, "funcs": 573, "lcom": 115, "lines": 10494, "loc": 8343}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 26, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:38:24Z"} | 26 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "b5ef2e8", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 232, "complex": 544, "cyclo": 602, "fields": 1189, "funcs": 573, "lcom": 115, "lines": 10494, "loc": 8343}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 26, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T21:38:24Z"} |
| 27 | +{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "a485576", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 546, "cyclo": 604, "fields": 1209, "funcs": 582, "lcom": 115, "lines": 10665, "loc": 8489}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 27, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T22:01:44Z"} | ||
| 28 | +{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "a485576", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 546, "cyclo": 604, "fields": 1209, "funcs": 582, "lcom": 115, "lines": 10669, "loc": 8492}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 28, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T22:03:59Z"} | ||
added
.quality/report-20261125T220144Z.md +73 -0 | new file mode 100644 | ||
| @@ -0,0 +1,73 @@ | ||
| 1 | +# Quality report — 2026-11-25T22:01:44Z | |
| 2 | + | |
| 3 | +- **Gate**: ✅ **PASS** | |
| 4 | +- **Commit**: `a485576` on `feature/v0.2-openai-server` | |
| 5 | +- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | |
| 6 | +- **swiftlint**: 0.65.1 (run directly, merged into lint issues) | |
| 7 | +- **Run**: #27 (previous: 2026-11-25T21:38:24Z) | |
| 8 | + | |
| 9 | +## Lint issues (`qlty check`) | |
| 10 | + | |
| 11 | +_none_ | |
| 12 | + | |
| 13 | +### Top rules | |
| 14 | + | |
| 15 | +_none_ | |
| 16 | + | |
| 17 | +### Most affected files | |
| 18 | + | |
| 19 | +_none_ | |
| 20 | + | |
| 21 | +## Code smells (`qlty smells`) | |
| 22 | + | |
| 23 | +Total: **0** (vs previous: ±0) | |
| 24 | + | |
| 25 | +_none_ | |
| 26 | + | |
| 27 | +## Metrics (`qlty metrics`) | |
| 28 | + | |
| 29 | +| metric | total | vs previous | | |
| 30 | +|---|---|---| | |
| 31 | +| funcs | 582 | +9 | | |
| 32 | +| classes | 234 | +2 | | |
| 33 | +| fields | 1209 | +20 | | |
| 34 | +| cyclo | 604 | +2 | | |
| 35 | +| complex | 546 | +2 | | |
| 36 | +| lcom | 115 | ±0 | | |
| 37 | +| lines | 10665 | +171 | | |
| 38 | +| loc | 8489 | +146 | | |
| 39 | + | |
| 40 | +### Most complex files | |
| 41 | + | |
| 42 | +| file | complex | cyclo | loc | | |
| 43 | +|---|---|---|---| | |
| 44 | +| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 242 | | |
| 45 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 31 | 20 | 125 | | |
| 46 | +| samples/02-kv-cache-reuse/Sources/KVCacheReuse/KVCacheReuse.swift | 26 | 20 | 285 | | |
| 47 | +| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 246 | | |
| 48 | +| tools/host-runner/host_runner.py | 22 | 22 | 141 | | |
| 49 | +| Sources/RazorbillCore/Config/ConfigValue+JSON.swift | 20 | 25 | 71 | | |
| 50 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 227 | | |
| 51 | +| Sources/RazorbillServer/Chat/ToolsAndFormats.swift | 18 | 30 | 170 | | |
| 52 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 276 | | |
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 137 | | |
| 54 | +| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | |
| 55 | +| Sources/RazorbillCore/Config/OrderedJSONReader.swift | 15 | 24 | 140 | | |
| 56 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 14 | 15 | 67 | | |
| 57 | +| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | |
| 58 | +| Sources/RazorbillServer/EmbeddingsRoute.swift | 13 | 13 | 143 | | |
| 59 | + | |
| 60 | +## Trend | |
| 61 | + | |
| 62 | +| run | timestamp | error | warning | smells | complex | gate | | |
| 63 | +|---|---|---|---|---|---|---| | |
| 64 | +| 18 | 2026-11-25T17:55:49Z | 0 | 0 | 0 | 449 | PASS | | |
| 65 | +| 19 | 2026-11-25T18:44:20Z | 0 | 0 | 2 | 513 | FAIL | | |
| 66 | +| 20 | 2026-11-25T18:44:58Z | 0 | 0 | 0 | 512 | PASS | | |
| 67 | +| 21 | 2026-11-25T19:12:45Z | 0 | 0 | 0 | 512 | PASS | | |
| 68 | +| 22 | 2026-11-25T21:27:49Z | 4 | 1 | 0 | 538 | FAIL | | |
| 69 | +| 23 | 2026-11-25T21:28:10Z | 0 | 0 | 0 | 538 | PASS | | |
| 70 | +| 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL | | |
| 71 | +| 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL | | |
| 72 | +| 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS | | |
| 73 | +| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS | | |
| new file mode 100644 | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | +# Quality report — 2026-11-25T22:01:44Z | ||
| 2 | + | ||
| 3 | +- **Gate**: ✅ **PASS** | ||
| 4 | +- **Commit**: `a485576` on `feature/v0.2-openai-server` | ||
| 5 | +- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | ||
| 6 | +- **swiftlint**: 0.65.1 (run directly, merged into lint issues) | ||
| 7 | +- **Run**: #27 (previous: 2026-11-25T21:38:24Z) | ||
| 8 | + | ||
| 9 | +## Lint issues (`qlty check`) | ||
| 10 | + | ||
| 11 | +_none_ | ||
| 12 | + | ||
| 13 | +### Top rules | ||
| 14 | + | ||
| 15 | +_none_ | ||
| 16 | + | ||
| 17 | +### Most affected files | ||
| 18 | + | ||
| 19 | +_none_ | ||
| 20 | + | ||
| 21 | +## Code smells (`qlty smells`) | ||
| 22 | + | ||
| 23 | +Total: **0** (vs previous: ±0) | ||
| 24 | + | ||
| 25 | +_none_ | ||
| 26 | + | ||
| 27 | +## Metrics (`qlty metrics`) | ||
| 28 | + | ||
| 29 | +| metric | total | vs previous | | ||
| 30 | +|---|---|---| | ||
| 31 | +| funcs | 582 | +9 | | ||
| 32 | +| classes | 234 | +2 | | ||
| 33 | +| fields | 1209 | +20 | | ||
| 34 | +| cyclo | 604 | +2 | | ||
| 35 | +| complex | 546 | +2 | | ||
| 36 | +| lcom | 115 | ±0 | | ||
| 37 | +| lines | 10665 | +171 | | ||
| 38 | +| loc | 8489 | +146 | | ||
| 39 | + | ||
| 40 | +### Most complex files | ||
| 41 | + | ||
| 42 | +| file | complex | cyclo | loc | | ||
| 43 | +|---|---|---|---| | ||
| 44 | +| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 242 | | ||
| 45 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 31 | 20 | 125 | | ||
| 46 | +| samples/02-kv-cache-reuse/Sources/KVCacheReuse/KVCacheReuse.swift | 26 | 20 | 285 | | ||
| 47 | +| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 246 | | ||
| 48 | +| tools/host-runner/host_runner.py | 22 | 22 | 141 | | ||
| 49 | +| Sources/RazorbillCore/Config/ConfigValue+JSON.swift | 20 | 25 | 71 | | ||
| 50 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 227 | | ||
| 51 | +| Sources/RazorbillServer/Chat/ToolsAndFormats.swift | 18 | 30 | 170 | | ||
| 52 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 276 | | ||
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 137 | | ||
| 54 | +| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | ||
| 55 | +| Sources/RazorbillCore/Config/OrderedJSONReader.swift | 15 | 24 | 140 | | ||
| 56 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 14 | 15 | 67 | | ||
| 57 | +| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | ||
| 58 | +| Sources/RazorbillServer/EmbeddingsRoute.swift | 13 | 13 | 143 | | ||
| 59 | + | ||
| 60 | +## Trend | ||
| 61 | + | ||
| 62 | +| run | timestamp | error | warning | smells | complex | gate | | ||
| 63 | +|---|---|---|---|---|---|---| | ||
| 64 | +| 18 | 2026-11-25T17:55:49Z | 0 | 0 | 0 | 449 | PASS | | ||
| 65 | +| 19 | 2026-11-25T18:44:20Z | 0 | 0 | 2 | 513 | FAIL | | ||
| 66 | +| 20 | 2026-11-25T18:44:58Z | 0 | 0 | 0 | 512 | PASS | | ||
| 67 | +| 21 | 2026-11-25T19:12:45Z | 0 | 0 | 0 | 512 | PASS | | ||
| 68 | +| 22 | 2026-11-25T21:27:49Z | 4 | 1 | 0 | 538 | FAIL | | ||
| 69 | +| 23 | 2026-11-25T21:28:10Z | 0 | 0 | 0 | 538 | PASS | | ||
| 70 | +| 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL | | ||
| 71 | +| 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL | | ||
| 72 | +| 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS | | ||
| 73 | +| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS | | ||
added
.quality/report-20261125T220359Z.md +73 -0 | new file mode 100644 | ||
| @@ -0,0 +1,73 @@ | ||
| 1 | +# Quality report — 2026-11-25T22:03:59Z | |
| 2 | + | |
| 3 | +- **Gate**: ✅ **PASS** | |
| 4 | +- **Commit**: `a485576` on `feature/v0.2-openai-server` | |
| 5 | +- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | |
| 6 | +- **swiftlint**: 0.65.1 (run directly, merged into lint issues) | |
| 7 | +- **Run**: #28 (previous: 2026-11-25T22:01:44Z) | |
| 8 | + | |
| 9 | +## Lint issues (`qlty check`) | |
| 10 | + | |
| 11 | +_none_ | |
| 12 | + | |
| 13 | +### Top rules | |
| 14 | + | |
| 15 | +_none_ | |
| 16 | + | |
| 17 | +### Most affected files | |
| 18 | + | |
| 19 | +_none_ | |
| 20 | + | |
| 21 | +## Code smells (`qlty smells`) | |
| 22 | + | |
| 23 | +Total: **0** (vs previous: ±0) | |
| 24 | + | |
| 25 | +_none_ | |
| 26 | + | |
| 27 | +## Metrics (`qlty metrics`) | |
| 28 | + | |
| 29 | +| metric | total | vs previous | | |
| 30 | +|---|---|---| | |
| 31 | +| funcs | 582 | ±0 | | |
| 32 | +| classes | 234 | ±0 | | |
| 33 | +| fields | 1209 | ±0 | | |
| 34 | +| cyclo | 604 | ±0 | | |
| 35 | +| complex | 546 | ±0 | | |
| 36 | +| lcom | 115 | ±0 | | |
| 37 | +| lines | 10669 | +4 | | |
| 38 | +| loc | 8492 | +3 | | |
| 39 | + | |
| 40 | +### Most complex files | |
| 41 | + | |
| 42 | +| file | complex | cyclo | loc | | |
| 43 | +|---|---|---|---| | |
| 44 | +| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 242 | | |
| 45 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 31 | 20 | 125 | | |
| 46 | +| samples/02-kv-cache-reuse/Sources/KVCacheReuse/KVCacheReuse.swift | 26 | 20 | 285 | | |
| 47 | +| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 246 | | |
| 48 | +| tools/host-runner/host_runner.py | 22 | 22 | 141 | | |
| 49 | +| Sources/RazorbillCore/Config/ConfigValue+JSON.swift | 20 | 25 | 71 | | |
| 50 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 227 | | |
| 51 | +| Sources/RazorbillServer/Chat/ToolsAndFormats.swift | 18 | 30 | 170 | | |
| 52 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 276 | | |
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 137 | | |
| 54 | +| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | |
| 55 | +| Sources/RazorbillCore/Config/OrderedJSONReader.swift | 15 | 24 | 140 | | |
| 56 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 14 | 15 | 67 | | |
| 57 | +| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | |
| 58 | +| Sources/RazorbillServer/EmbeddingsRoute.swift | 13 | 13 | 143 | | |
| 59 | + | |
| 60 | +## Trend | |
| 61 | + | |
| 62 | +| run | timestamp | error | warning | smells | complex | gate | | |
| 63 | +|---|---|---|---|---|---|---| | |
| 64 | +| 19 | 2026-11-25T18:44:20Z | 0 | 0 | 2 | 513 | FAIL | | |
| 65 | +| 20 | 2026-11-25T18:44:58Z | 0 | 0 | 0 | 512 | PASS | | |
| 66 | +| 21 | 2026-11-25T19:12:45Z | 0 | 0 | 0 | 512 | PASS | | |
| 67 | +| 22 | 2026-11-25T21:27:49Z | 4 | 1 | 0 | 538 | FAIL | | |
| 68 | +| 23 | 2026-11-25T21:28:10Z | 0 | 0 | 0 | 538 | PASS | | |
| 69 | +| 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL | | |
| 70 | +| 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL | | |
| 71 | +| 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS | | |
| 72 | +| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS | | |
| 73 | +| 28 | 2026-11-25T22:03:59Z | 0 | 0 | 0 | 546 | PASS | | |
| new file mode 100644 | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | +# Quality report — 2026-11-25T22:03:59Z | ||
| 2 | + | ||
| 3 | +- **Gate**: ✅ **PASS** | ||
| 4 | +- **Commit**: `a485576` on `feature/v0.2-openai-server` | ||
| 5 | +- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | ||
| 6 | +- **swiftlint**: 0.65.1 (run directly, merged into lint issues) | ||
| 7 | +- **Run**: #28 (previous: 2026-11-25T22:01:44Z) | ||
| 8 | + | ||
| 9 | +## Lint issues (`qlty check`) | ||
| 10 | + | ||
| 11 | +_none_ | ||
| 12 | + | ||
| 13 | +### Top rules | ||
| 14 | + | ||
| 15 | +_none_ | ||
| 16 | + | ||
| 17 | +### Most affected files | ||
| 18 | + | ||
| 19 | +_none_ | ||
| 20 | + | ||
| 21 | +## Code smells (`qlty smells`) | ||
| 22 | + | ||
| 23 | +Total: **0** (vs previous: ±0) | ||
| 24 | + | ||
| 25 | +_none_ | ||
| 26 | + | ||
| 27 | +## Metrics (`qlty metrics`) | ||
| 28 | + | ||
| 29 | +| metric | total | vs previous | | ||
| 30 | +|---|---|---| | ||
| 31 | +| funcs | 582 | ±0 | | ||
| 32 | +| classes | 234 | ±0 | | ||
| 33 | +| fields | 1209 | ±0 | | ||
| 34 | +| cyclo | 604 | ±0 | | ||
| 35 | +| complex | 546 | ±0 | | ||
| 36 | +| lcom | 115 | ±0 | | ||
| 37 | +| lines | 10669 | +4 | | ||
| 38 | +| loc | 8492 | +3 | | ||
| 39 | + | ||
| 40 | +### Most complex files | ||
| 41 | + | ||
| 42 | +| file | complex | cyclo | loc | | ||
| 43 | +|---|---|---|---| | ||
| 44 | +| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 242 | | ||
| 45 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 31 | 20 | 125 | | ||
| 46 | +| samples/02-kv-cache-reuse/Sources/KVCacheReuse/KVCacheReuse.swift | 26 | 20 | 285 | | ||
| 47 | +| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 246 | | ||
| 48 | +| tools/host-runner/host_runner.py | 22 | 22 | 141 | | ||
| 49 | +| Sources/RazorbillCore/Config/ConfigValue+JSON.swift | 20 | 25 | 71 | | ||
| 50 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 227 | | ||
| 51 | +| Sources/RazorbillServer/Chat/ToolsAndFormats.swift | 18 | 30 | 170 | | ||
| 52 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 276 | | ||
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 137 | | ||
| 54 | +| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | ||
| 55 | +| Sources/RazorbillCore/Config/OrderedJSONReader.swift | 15 | 24 | 140 | | ||
| 56 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 14 | 15 | 67 | | ||
| 57 | +| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | ||
| 58 | +| Sources/RazorbillServer/EmbeddingsRoute.swift | 13 | 13 | 143 | | ||
| 59 | + | ||
| 60 | +## Trend | ||
| 61 | + | ||
| 62 | +| run | timestamp | error | warning | smells | complex | gate | | ||
| 63 | +|---|---|---|---|---|---|---| | ||
| 64 | +| 19 | 2026-11-25T18:44:20Z | 0 | 0 | 2 | 513 | FAIL | | ||
| 65 | +| 20 | 2026-11-25T18:44:58Z | 0 | 0 | 0 | 512 | PASS | | ||
| 66 | +| 21 | 2026-11-25T19:12:45Z | 0 | 0 | 0 | 512 | PASS | | ||
| 67 | +| 22 | 2026-11-25T21:27:49Z | 4 | 1 | 0 | 538 | FAIL | | ||
| 68 | +| 23 | 2026-11-25T21:28:10Z | 0 | 0 | 0 | 538 | PASS | | ||
| 69 | +| 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL | | ||
| 70 | +| 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL | | ||
| 71 | +| 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS | | ||
| 72 | +| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS | | ||
| 73 | +| 28 | 2026-11-25T22:03:59Z | 0 | 0 | 0 | 546 | PASS | | ||
modified
.quality/report-latest.md +19 -21 | @@ -1,16 +1,14 @@ | ||
| 1 | -# Quality report — 2026-11-25T21:38:24Z | |
| 1 | +# Quality report — 2026-11-25T22:03:59Z | |
| 2 | 2 | |
| 3 | 3 | - **Gate**: ✅ **PASS** |
| 4 | -- **Commit**: `b5ef2e8` on `feature/v0.2-openai-server` | |
| 4 | +- **Commit**: `a485576` on `feature/v0.2-openai-server` | |
| 5 | 5 | - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) |
| 6 | 6 | - **swiftlint**: 0.65.1 (run directly, merged into lint issues) |
| 7 | -- **Run**: #26 (previous: 2026-11-25T21:37:51Z) | |
| 7 | +- **Run**: #28 (previous: 2026-11-25T22:01:44Z) | |
| 8 | 8 | |
| 9 | 9 | ## Lint issues (`qlty check`) |
| 10 | 10 | |
| 11 | -| level | count | vs previous | | |
| 12 | -|---|---|---| | |
| 13 | -| warning | 0 | -1 | | |
| 11 | +_none_ | |
| 14 | 12 | |
| 15 | 13 | ### Top rules |
| 16 | 14 | |
| @@ -30,41 +28,39 @@ _none_ | ||
| 30 | 28 | |
| 31 | 29 | | metric | total | vs previous | |
| 32 | 30 | |---|---|---| |
| 33 | -| funcs | 573 | ±0 | | |
| 34 | -| classes | 232 | ±0 | | |
| 35 | -| fields | 1189 | +7 | | |
| 36 | -| cyclo | 602 | +1 | | |
| 37 | -| complex | 544 | ±0 | | |
| 38 | -| lcom | 115 | +1 | | |
| 39 | -| lines | 10494 | +6 | | |
| 40 | -| loc | 8343 | +6 | | |
| 31 | +| funcs | 582 | ±0 | | |
| 32 | +| classes | 234 | ±0 | | |
| 33 | +| fields | 1209 | ±0 | | |
| 34 | +| cyclo | 604 | ±0 | | |
| 35 | +| complex | 546 | ±0 | | |
| 36 | +| lcom | 115 | ±0 | | |
| 37 | +| lines | 10669 | +4 | | |
| 38 | +| loc | 8492 | +3 | | |
| 41 | 39 | |
| 42 | 40 | ### Most complex files |
| 43 | 41 | |
| 44 | 42 | | file | complex | cyclo | loc | |
| 45 | 43 | |---|---|---|---| |
| 46 | -| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 238 | | |
| 44 | +| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 242 | | |
| 47 | 45 | | Sources/RazorbillServer/Chat/CompletionStream.swift | 31 | 20 | 125 | |
| 48 | 46 | | samples/02-kv-cache-reuse/Sources/KVCacheReuse/KVCacheReuse.swift | 26 | 20 | 285 | |
| 49 | -| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 242 | | |
| 47 | +| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 246 | | |
| 50 | 48 | | tools/host-runner/host_runner.py | 22 | 22 | 141 | |
| 51 | 49 | | Sources/RazorbillCore/Config/ConfigValue+JSON.swift | 20 | 25 | 71 | |
| 52 | -| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 | | |
| 50 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 227 | | |
| 53 | 51 | | Sources/RazorbillServer/Chat/ToolsAndFormats.swift | 18 | 30 | 170 | |
| 54 | -| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 271 | | |
| 52 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 276 | | |
| 55 | 53 | | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 137 | |
| 56 | 54 | | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | |
| 57 | 55 | | Sources/RazorbillCore/Config/OrderedJSONReader.swift | 15 | 24 | 140 | |
| 56 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 14 | 15 | 67 | | |
| 58 | 57 | | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | |
| 59 | 58 | | Sources/RazorbillServer/EmbeddingsRoute.swift | 13 | 13 | 143 | |
| 60 | -| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 | | |
| 61 | 59 | |
| 62 | 60 | ## Trend |
| 63 | 61 | |
| 64 | 62 | | run | timestamp | error | warning | smells | complex | gate | |
| 65 | 63 | |---|---|---|---|---|---|---| |
| 66 | -| 17 | 2026-11-25T17:55:15Z | 0 | 3 | 0 | 449 | FAIL | | |
| 67 | -| 18 | 2026-11-25T17:55:49Z | 0 | 0 | 0 | 449 | PASS | | |
| 68 | 64 | | 19 | 2026-11-25T18:44:20Z | 0 | 0 | 2 | 513 | FAIL | |
| 69 | 65 | | 20 | 2026-11-25T18:44:58Z | 0 | 0 | 0 | 512 | PASS | |
| 70 | 66 | | 21 | 2026-11-25T19:12:45Z | 0 | 0 | 0 | 512 | PASS | |
| @@ -73,3 +69,5 @@ _none_ | ||
| 73 | 69 | | 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL | |
| 74 | 70 | | 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL | |
| 75 | 71 | | 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS | |
| 72 | +| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS | | |
| 73 | +| 28 | 2026-11-25T22:03:59Z | 0 | 0 | 0 | 546 | PASS | | |
| @@ -1,16 +1,14 @@ | |||
| 1 | -# Quality report — 2026-11-25T21:38:24Z | 1 | +# Quality report — 2026-11-25T22:03:59Z |
| 2 | 2 | ||
| 3 | - **Gate**: ✅ **PASS** | 3 | - **Gate**: ✅ **PASS** |
| 4 | -- **Commit**: `b5ef2e8` on `feature/v0.2-openai-server` | 4 | +- **Commit**: `a485576` on `feature/v0.2-openai-server` |
| 5 | - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | 5 | - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) |
| 6 | - **swiftlint**: 0.65.1 (run directly, merged into lint issues) | 6 | - **swiftlint**: 0.65.1 (run directly, merged into lint issues) |
| 7 | -- **Run**: #26 (previous: 2026-11-25T21:37:51Z) | 7 | +- **Run**: #28 (previous: 2026-11-25T22:01:44Z) |
| 8 | 8 | ||
| 9 | ## Lint issues (`qlty check`) | 9 | ## Lint issues (`qlty check`) |
| 10 | 10 | ||
| 11 | -| level | count | vs previous | | 11 | +_none_ |
| 12 | -|---|---|---| | ||
| 13 | -| warning | 0 | -1 | | ||
| 14 | 12 | ||
| 15 | ### Top rules | 13 | ### Top rules |
| 16 | 14 | ||
| @@ -30,41 +28,39 @@ _none_ | |||
| 30 | 28 | ||
| 31 | | metric | total | vs previous | | 29 | | metric | total | vs previous | |
| 32 | |---|---|---| | 30 | |---|---|---| |
| 33 | -| funcs | 573 | ±0 | | 31 | +| funcs | 582 | ±0 | |
| 34 | -| classes | 232 | ±0 | | 32 | +| classes | 234 | ±0 | |
| 35 | -| fields | 1189 | +7 | | 33 | +| fields | 1209 | ±0 | |
| 36 | -| cyclo | 602 | +1 | | 34 | +| cyclo | 604 | ±0 | |
| 37 | -| complex | 544 | ±0 | | 35 | +| complex | 546 | ±0 | |
| 38 | -| lcom | 115 | +1 | | 36 | +| lcom | 115 | ±0 | |
| 39 | -| lines | 10494 | +6 | | 37 | +| lines | 10669 | +4 | |
| 40 | -| loc | 8343 | +6 | | 38 | +| loc | 8492 | +3 | |
| 41 | 39 | ||
| 42 | ### Most complex files | 40 | ### Most complex files |
| 43 | 41 | ||
| 44 | | file | complex | cyclo | loc | | 42 | | file | complex | cyclo | loc | |
| 45 | |---|---|---|---| | 43 | |---|---|---|---| |
| 46 | -| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 238 | | 44 | +| Sources/RazorbillServer/CompletionsRoute.swift | 47 | 20 | 242 | |
| 47 | | Sources/RazorbillServer/Chat/CompletionStream.swift | 31 | 20 | 125 | | 45 | | Sources/RazorbillServer/Chat/CompletionStream.swift | 31 | 20 | 125 | |
| 48 | | samples/02-kv-cache-reuse/Sources/KVCacheReuse/KVCacheReuse.swift | 26 | 20 | 285 | | 46 | | samples/02-kv-cache-reuse/Sources/KVCacheReuse/KVCacheReuse.swift | 26 | 20 | 285 | |
| 49 | -| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 242 | | 47 | +| Sources/RazorbillMLX/MLXEngine.swift | 23 | 35 | 246 | |
| 50 | | tools/host-runner/host_runner.py | 22 | 22 | 141 | | 48 | | tools/host-runner/host_runner.py | 22 | 22 | 141 | |
| 51 | | Sources/RazorbillCore/Config/ConfigValue+JSON.swift | 20 | 25 | 71 | | 49 | | Sources/RazorbillCore/Config/ConfigValue+JSON.swift | 20 | 25 | 71 | |
| 52 | -| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 | | 50 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 227 | |
| 53 | | Sources/RazorbillServer/Chat/ToolsAndFormats.swift | 18 | 30 | 170 | | 51 | | Sources/RazorbillServer/Chat/ToolsAndFormats.swift | 18 | 30 | 170 | |
| 54 | -| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 271 | | 52 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 17 | 24 | 276 | |
| 55 | | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 137 | | 53 | | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 137 | |
| 56 | | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | 54 | | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | |
| 57 | | Sources/RazorbillCore/Config/OrderedJSONReader.swift | 15 | 24 | 140 | | 55 | | Sources/RazorbillCore/Config/OrderedJSONReader.swift | 15 | 24 | 140 | |
| 56 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 14 | 15 | 67 | | ||
| 58 | | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | 57 | | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | |
| 59 | | Sources/RazorbillServer/EmbeddingsRoute.swift | 13 | 13 | 143 | | 58 | | Sources/RazorbillServer/EmbeddingsRoute.swift | 13 | 13 | 143 | |
| 60 | -| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 | | ||
| 61 | 59 | ||
| 62 | ## Trend | 60 | ## Trend |
| 63 | 61 | ||
| 64 | | run | timestamp | error | warning | smells | complex | gate | | 62 | | run | timestamp | error | warning | smells | complex | gate | |
| 65 | |---|---|---|---|---|---|---| | 63 | |---|---|---|---|---|---|---| |
| 66 | -| 17 | 2026-11-25T17:55:15Z | 0 | 3 | 0 | 449 | FAIL | | ||
| 67 | -| 18 | 2026-11-25T17:55:49Z | 0 | 0 | 0 | 449 | PASS | | ||
| 68 | | 19 | 2026-11-25T18:44:20Z | 0 | 0 | 2 | 513 | FAIL | | 64 | | 19 | 2026-11-25T18:44:20Z | 0 | 0 | 2 | 513 | FAIL | |
| 69 | | 20 | 2026-11-25T18:44:58Z | 0 | 0 | 0 | 512 | PASS | | 65 | | 20 | 2026-11-25T18:44:58Z | 0 | 0 | 0 | 512 | PASS | |
| 70 | | 21 | 2026-11-25T19:12:45Z | 0 | 0 | 0 | 512 | PASS | | 66 | | 21 | 2026-11-25T19:12:45Z | 0 | 0 | 0 | 512 | PASS | |
| @@ -73,3 +69,5 @@ _none_ | |||
| 73 | | 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL | | 69 | | 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL | |
| 74 | | 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL | | 70 | | 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL | |
| 75 | | 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS | | 71 | | 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS | |
| 72 | +| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS | | ||
| 73 | +| 28 | 2026-11-25T22:03:59Z | 0 | 0 | 0 | 546 | PASS | | ||
modified
.tickets/issues/0049-sampling-parameters-top-k-min-p-repetition-penalty.yaml +34 -5 | @@ -1,12 +1,12 @@ | ||
| 1 | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | 2 | id: 49 |
| 3 | 3 | title: "Sampling parameters: top_k, min_p, repetition_penalty, logit_bias" |
| 4 | -state: open | |
| 4 | +state: closed | |
| 5 | 5 | author: |
| 6 | 6 | name: k33g |
| 7 | 7 | email: ph.charriere@gmail.com |
| 8 | 8 | createdAt: 2026-11-25T21:45:00.000Z |
| 9 | -updatedAt: 2026-11-25T21:45:00.000Z | |
| 9 | +updatedAt: 2026-11-26T00:30:00.000Z | |
| 10 | 10 | labels: |
| 11 | 11 | - "kind::feature" |
| 12 | 12 | - "area::server" |
| @@ -30,18 +30,47 @@ body: | | ||
| 30 | 30 | tasks: |
| 31 | 31 | - id: 1 |
| 32 | 32 | title: "Decide the scope (fields, generation_config.json defaults)" |
| 33 | - state: open | |
| 33 | + state: closed | |
| 34 | 34 | priority: high |
| 35 | 35 | author: |
| 36 | 36 | name: k33g |
| 37 | 37 | email: ph.charriere@gmail.com |
| 38 | 38 | createdAt: 2026-11-25T21:45:00.000Z |
| 39 | + updatedAt: 2026-11-26T00:30:00.000Z | |
| 40 | + closedAt: 2026-11-26T00:30:00.000Z | |
| 39 | 41 | - id: 2 |
| 40 | 42 | title: "Implement, test, document EN + FR" |
| 41 | - state: open | |
| 43 | + state: closed | |
| 42 | 44 | priority: medium |
| 43 | 45 | author: |
| 44 | 46 | name: k33g |
| 45 | 47 | email: ph.charriere@gmail.com |
| 46 | 48 | createdAt: 2026-11-25T21:45:00.000Z |
| 47 | -comments: [] | |
| 49 | + updatedAt: 2026-11-26T00:30:00.000Z | |
| 50 | + closedAt: 2026-11-26T00:30:00.000Z | |
| 51 | +comments: | |
| 52 | + - id: 1 | |
| 53 | + author: | |
| 54 | + name: k33g | |
| 55 | + email: ph.charriere@gmail.com | |
| 56 | + createdAt: 2026-11-26T00:30:00.000Z | |
| 57 | + body: | | |
| 58 | + Scope decided by the user (2026-11-25): implement only what mlx-swift-lm implements. | |
| 59 | + | |
| 60 | + Done: | |
| 61 | + - `top_k` (≥ 0, 0 = off), `min_p` (0–1, 0 = off), `repetition_penalty` (> 0) and `repetition_context_size` (≥ 1, default 20) are accepted: | |
| 62 | + - on `/v1/chat/completions` and `/v1/completions`, decoded with `SamplingExtensions`; a value out of range is a 400 naming the field; | |
| 63 | + - in configuration `defaults` / `locked`, where they are imposed when locked; | |
| 64 | + - they are passed to `GenerateParameters`. | |
| 65 | + - Interaction with the prompt cache (#48): mlx's penalties load the last N tokens of the prompt they are given. When a penalty is active, `PromptCache` therefore computes at least N prompt tokens again (`PromptPrefix(..., computing:)`), so the result matches a full prefill. A Mac smoke test checks this with `repetition_penalty: 1.3`: same answer as a fresh engine, and the cache is still reused. | |
| 66 | + - Not done: | |
| 67 | + - `logit_bias` and other servers' samplers (`typical_p`, XTC, DRY, Mirostat…) are not in mlx-swift-lm, so they stay ignored like unknown fields; | |
| 68 | + - `generation_config.json` sampling values are not read (mlx-swift-lm reads only its EOS and stop strings); | |
| 69 | + - presence/frequency penalties keep mlx's 20-token window (documented as a deliberate difference). | |
| 70 | + - Tests: | |
| 71 | + - Linux, 172 tests: config keys and errors, resolve order, request fields to the engine, four 400 cases; | |
| 72 | + - Mac, 198 tests; | |
| 73 | + - Linux compatibility suite, 51 passed / 20 skipped: `extra_body` fields accepted, `top_k` / `min_p` out of range are 400s. | |
| 74 | + - Gate PASS. | |
| 75 | + - Docs EN + FR: HTTP API fields, configuration table, OpenAI-compatibility explanation (extension rows, the penalty window), `examples/server.yaml`. | |
| 76 | + | |
| @@ -1,12 +1,12 @@ | |||
| 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | id: 49 | 2 | id: 49 |
| 3 | title: "Sampling parameters: top_k, min_p, repetition_penalty, logit_bias" | 3 | title: "Sampling parameters: top_k, min_p, repetition_penalty, logit_bias" |
| 4 | -state: open | 4 | +state: closed |
| 5 | author: | 5 | author: |
| 6 | name: k33g | 6 | name: k33g |
| 7 | email: ph.charriere@gmail.com | 7 | email: ph.charriere@gmail.com |
| 8 | createdAt: 2026-11-25T21:45:00.000Z | 8 | createdAt: 2026-11-25T21:45:00.000Z |
| 9 | -updatedAt: 2026-11-25T21:45:00.000Z | 9 | +updatedAt: 2026-11-26T00:30:00.000Z |
| 10 | labels: | 10 | labels: |
| 11 | - "kind::feature" | 11 | - "kind::feature" |
| 12 | - "area::server" | 12 | - "area::server" |
| @@ -30,18 +30,47 @@ body: | | |||
| 30 | tasks: | 30 | tasks: |
| 31 | - id: 1 | 31 | - id: 1 |
| 32 | title: "Decide the scope (fields, generation_config.json defaults)" | 32 | title: "Decide the scope (fields, generation_config.json defaults)" |
| 33 | - state: open | 33 | + state: closed |
| 34 | priority: high | 34 | priority: high |
| 35 | author: | 35 | author: |
| 36 | name: k33g | 36 | name: k33g |
| 37 | email: ph.charriere@gmail.com | 37 | email: ph.charriere@gmail.com |
| 38 | createdAt: 2026-11-25T21:45:00.000Z | 38 | createdAt: 2026-11-25T21:45:00.000Z |
| 39 | + updatedAt: 2026-11-26T00:30:00.000Z | ||
| 40 | + closedAt: 2026-11-26T00:30:00.000Z | ||
| 39 | - id: 2 | 41 | - id: 2 |
| 40 | title: "Implement, test, document EN + FR" | 42 | title: "Implement, test, document EN + FR" |
| 41 | - state: open | 43 | + state: closed |
| 42 | priority: medium | 44 | priority: medium |
| 43 | author: | 45 | author: |
| 44 | name: k33g | 46 | name: k33g |
| 45 | email: ph.charriere@gmail.com | 47 | email: ph.charriere@gmail.com |
| 46 | createdAt: 2026-11-25T21:45:00.000Z | 48 | createdAt: 2026-11-25T21:45:00.000Z |
| 47 | -comments: [] | 49 | + updatedAt: 2026-11-26T00:30:00.000Z |
| 50 | + closedAt: 2026-11-26T00:30:00.000Z | ||
| 51 | +comments: | ||
| 52 | + - id: 1 | ||
| 53 | + author: | ||
| 54 | + name: k33g | ||
| 55 | + email: ph.charriere@gmail.com | ||
| 56 | + createdAt: 2026-11-26T00:30:00.000Z | ||
| 57 | + body: | | ||
| 58 | + Scope decided by the user (2026-11-25): implement only what mlx-swift-lm implements. | ||
| 59 | + | ||
| 60 | + Done: | ||
| 61 | + - `top_k` (≥ 0, 0 = off), `min_p` (0–1, 0 = off), `repetition_penalty` (> 0) and `repetition_context_size` (≥ 1, default 20) are accepted: | ||
| 62 | + - on `/v1/chat/completions` and `/v1/completions`, decoded with `SamplingExtensions`; a value out of range is a 400 naming the field; | ||
| 63 | + - in configuration `defaults` / `locked`, where they are imposed when locked; | ||
| 64 | + - they are passed to `GenerateParameters`. | ||
| 65 | + - Interaction with the prompt cache (#48): mlx's penalties load the last N tokens of the prompt they are given. When a penalty is active, `PromptCache` therefore computes at least N prompt tokens again (`PromptPrefix(..., computing:)`), so the result matches a full prefill. A Mac smoke test checks this with `repetition_penalty: 1.3`: same answer as a fresh engine, and the cache is still reused. | ||
| 66 | + - Not done: | ||
| 67 | + - `logit_bias` and other servers' samplers (`typical_p`, XTC, DRY, Mirostat…) are not in mlx-swift-lm, so they stay ignored like unknown fields; | ||
| 68 | + - `generation_config.json` sampling values are not read (mlx-swift-lm reads only its EOS and stop strings); | ||
| 69 | + - presence/frequency penalties keep mlx's 20-token window (documented as a deliberate difference). | ||
| 70 | + - Tests: | ||
| 71 | + - Linux, 172 tests: config keys and errors, resolve order, request fields to the engine, four 400 cases; | ||
| 72 | + - Mac, 198 tests; | ||
| 73 | + - Linux compatibility suite, 51 passed / 20 skipped: `extra_body` fields accepted, `top_k` / `min_p` out of range are 400s. | ||
| 74 | + - Gate PASS. | ||
| 75 | + - Docs EN + FR: HTTP API fields, configuration table, OpenAI-compatibility explanation (extension rows, the penalty window), `examples/server.yaml`. | ||
| 76 | + | ||
modified
Sources/RazorbillCore/Config/GenerationOverrides.swift +27 -10 | @@ -16,10 +16,16 @@ public struct GenerationOverrides: Sendable, Equatable { | ||
| 16 | 16 | public var thinkingBudget: Int? |
| 17 | 17 | /// `show_reasoning`: send the model's reasoning to clients. |
| 18 | 18 | public var showReasoning: Bool? |
| 19 | + public var topK: Int? | |
| 20 | + public var minP: Double? | |
| 21 | + public var repetitionPenalty: Double? | |
| 22 | + public var repetitionContextSize: Int? | |
| 19 | 23 | |
| 20 | 24 | public init( |
| 21 | 25 | temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil, |
| 22 | - thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil | |
| 26 | + thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil, | |
| 27 | + topK: Int? = nil, minP: Double? = nil, repetitionPenalty: Double? = nil, | |
| 28 | + repetitionContextSize: Int? = nil | |
| 23 | 29 | ) { |
| 24 | 30 | self.temperature = temperature |
| 25 | 31 | self.topP = topP |
| @@ -27,6 +33,10 @@ public struct GenerationOverrides: Sendable, Equatable { | ||
| 27 | 33 | self.thinking = thinking |
| 28 | 34 | self.thinkingBudget = thinkingBudget |
| 29 | 35 | self.showReasoning = showReasoning |
| 36 | + self.topK = topK | |
| 37 | + self.minP = minP | |
| 38 | + self.repetitionPenalty = repetitionPenalty | |
| 39 | + self.repetitionContextSize = repetitionContextSize | |
| 30 | 40 | } |
| 31 | 41 | |
| 32 | 42 | /// No setting given. |
| @@ -35,22 +45,17 @@ public struct GenerationOverrides: Sendable, Equatable { | ||
| 35 | 45 | /// `settings` with every value given here replacing its own. |
| 36 | 46 | public func replacing(in settings: GenerationSettings) -> GenerationSettings { |
| 37 | 47 | var result = settings |
| 38 | - if let temperature { result.temperature = temperature } | |
| 39 | - if let topP { result.topP = topP } | |
| 40 | 48 | if let maxTokens { result.maxTokens = maxTokens } |
| 41 | 49 | if let thinking { result.thinking = thinking } |
| 42 | 50 | if let thinkingBudget { result.thinkingBudget = thinkingBudget } |
| 43 | 51 | if let showReasoning { result.showReasoning = showReasoning } |
| 44 | - return result | |
| 52 | + return imposingSampling(on: result) | |
| 45 | 53 | } |
| 46 | 54 | |
| 47 | - /// `settings` with this block enforced as locked values: `temperature`, `topP`, `thinking` | |
| 48 | - /// and `showReasoning` are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller | |
| 49 | - /// request is kept). | |
| 55 | + /// `settings` with this block enforced as locked values: `maxTokens` and `thinkingBudget` | |
| 56 | + /// are ceilings (a smaller request is kept); every other value is imposed. | |
| 50 | 57 | public func enforcing(on settings: GenerationSettings) -> GenerationSettings { |
| 51 | - var result = settings | |
| 52 | - if let temperature { result.temperature = temperature } | |
| 53 | - if let topP { result.topP = topP } | |
| 58 | + var result = imposingSampling(on: settings) | |
| 54 | 59 | if let thinking { result.thinking = thinking } |
| 55 | 60 | if let showReasoning { result.showReasoning = showReasoning } |
| 56 | 61 | if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) } |
| @@ -60,6 +65,18 @@ public struct GenerationOverrides: Sendable, Equatable { | ||
| 60 | 65 | return result |
| 61 | 66 | } |
| 62 | 67 | |
| 68 | + /// `settings` with the sampling values given here replacing its own. | |
| 69 | + private func imposingSampling(on settings: GenerationSettings) -> GenerationSettings { | |
| 70 | + var result = settings | |
| 71 | + if let temperature { result.temperature = temperature } | |
| 72 | + if let topP { result.topP = topP } | |
| 73 | + if let topK { result.topK = topK } | |
| 74 | + if let minP { result.minP = minP } | |
| 75 | + if let repetitionPenalty { result.repetitionPenalty = repetitionPenalty } | |
| 76 | + if let repetitionContextSize { result.repetitionContextSize = repetitionContextSize } | |
| 77 | + return result | |
| 78 | + } | |
| 79 | + | |
| 63 | 80 | /// The settings of one request: built-in defaults, then each `defaults` block in order, then |
| 64 | 81 | /// the client's values, then each `locked` block in order. |
| 65 | 82 | public static func resolve( |
| @@ -16,10 +16,16 @@ public struct GenerationOverrides: Sendable, Equatable { | |||
| 16 | public var thinkingBudget: Int? | 16 | public var thinkingBudget: Int? |
| 17 | /// `show_reasoning`: send the model's reasoning to clients. | 17 | /// `show_reasoning`: send the model's reasoning to clients. |
| 18 | public var showReasoning: Bool? | 18 | public var showReasoning: Bool? |
| 19 | + public var topK: Int? | ||
| 20 | + public var minP: Double? | ||
| 21 | + public var repetitionPenalty: Double? | ||
| 22 | + public var repetitionContextSize: Int? | ||
| 19 | 23 | ||
| 20 | public init( | 24 | public init( |
| 21 | temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil, | 25 | temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil, |
| 22 | - thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil | 26 | + thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil, |
| 27 | + topK: Int? = nil, minP: Double? = nil, repetitionPenalty: Double? = nil, | ||
| 28 | + repetitionContextSize: Int? = nil | ||
| 23 | ) { | 29 | ) { |
| 24 | self.temperature = temperature | 30 | self.temperature = temperature |
| 25 | self.topP = topP | 31 | self.topP = topP |
| @@ -27,6 +33,10 @@ public struct GenerationOverrides: Sendable, Equatable { | |||
| 27 | self.thinking = thinking | 33 | self.thinking = thinking |
| 28 | self.thinkingBudget = thinkingBudget | 34 | self.thinkingBudget = thinkingBudget |
| 29 | self.showReasoning = showReasoning | 35 | self.showReasoning = showReasoning |
| 36 | + self.topK = topK | ||
| 37 | + self.minP = minP | ||
| 38 | + self.repetitionPenalty = repetitionPenalty | ||
| 39 | + self.repetitionContextSize = repetitionContextSize | ||
| 30 | } | 40 | } |
| 31 | 41 | ||
| 32 | /// No setting given. | 42 | /// No setting given. |
| @@ -35,22 +45,17 @@ public struct GenerationOverrides: Sendable, Equatable { | |||
| 35 | /// `settings` with every value given here replacing its own. | 45 | /// `settings` with every value given here replacing its own. |
| 36 | public func replacing(in settings: GenerationSettings) -> GenerationSettings { | 46 | public func replacing(in settings: GenerationSettings) -> GenerationSettings { |
| 37 | var result = settings | 47 | var result = settings |
| 38 | - if let temperature { result.temperature = temperature } | ||
| 39 | - if let topP { result.topP = topP } | ||
| 40 | if let maxTokens { result.maxTokens = maxTokens } | 48 | if let maxTokens { result.maxTokens = maxTokens } |
| 41 | if let thinking { result.thinking = thinking } | 49 | if let thinking { result.thinking = thinking } |
| 42 | if let thinkingBudget { result.thinkingBudget = thinkingBudget } | 50 | if let thinkingBudget { result.thinkingBudget = thinkingBudget } |
| 43 | if let showReasoning { result.showReasoning = showReasoning } | 51 | if let showReasoning { result.showReasoning = showReasoning } |
| 44 | - return result | 52 | + return imposingSampling(on: result) |
| 45 | } | 53 | } |
| 46 | 54 | ||
| 47 | - /// `settings` with this block enforced as locked values: `temperature`, `topP`, `thinking` | 55 | + /// `settings` with this block enforced as locked values: `maxTokens` and `thinkingBudget` |
| 48 | - /// and `showReasoning` are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller | 56 | + /// are ceilings (a smaller request is kept); every other value is imposed. |
| 49 | - /// request is kept). | ||
| 50 | public func enforcing(on settings: GenerationSettings) -> GenerationSettings { | 57 | public func enforcing(on settings: GenerationSettings) -> GenerationSettings { |
| 51 | - var result = settings | 58 | + var result = imposingSampling(on: settings) |
| 52 | - if let temperature { result.temperature = temperature } | ||
| 53 | - if let topP { result.topP = topP } | ||
| 54 | if let thinking { result.thinking = thinking } | 59 | if let thinking { result.thinking = thinking } |
| 55 | if let showReasoning { result.showReasoning = showReasoning } | 60 | if let showReasoning { result.showReasoning = showReasoning } |
| 56 | if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) } | 61 | if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) } |
| @@ -60,6 +65,18 @@ public struct GenerationOverrides: Sendable, Equatable { | |||
| 60 | return result | 65 | return result |
| 61 | } | 66 | } |
| 62 | 67 | ||
| 68 | + /// `settings` with the sampling values given here replacing its own. | ||
| 69 | + private func imposingSampling(on settings: GenerationSettings) -> GenerationSettings { | ||
| 70 | + var result = settings | ||
| 71 | + if let temperature { result.temperature = temperature } | ||
| 72 | + if let topP { result.topP = topP } | ||
| 73 | + if let topK { result.topK = topK } | ||
| 74 | + if let minP { result.minP = minP } | ||
| 75 | + if let repetitionPenalty { result.repetitionPenalty = repetitionPenalty } | ||
| 76 | + if let repetitionContextSize { result.repetitionContextSize = repetitionContextSize } | ||
| 77 | + return result | ||
| 78 | + } | ||
| 79 | + | ||
| 63 | /// The settings of one request: built-in defaults, then each `defaults` block in order, then | 80 | /// The settings of one request: built-in defaults, then each `defaults` block in order, then |
| 64 | /// the client's values, then each `locked` block in order. | 81 | /// the client's values, then each `locked` block in order. |
| 65 | public static func resolve( | 82 | public static func resolve( |
modified
Sources/RazorbillCore/Config/ServerConfigLoader.swift +25 -11 | @@ -56,6 +56,7 @@ public struct ServerConfigLoader: Sendable { | ||
| 56 | 56 | static let serverKeys = ["host", "port", "api_key_env", "cors_origin"] |
| 57 | 57 | static let generationKeys = [ |
| 58 | 58 | "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", "show_reasoning", |
| 59 | + "top_k", "min_p", "repetition_penalty", "repetition_context_size", | |
| 59 | 60 | ] |
| 60 | 61 | static let modelKeys = [ |
| 61 | 62 | "id", "source", "revision", "path", "kind", "preload", "defaults", "locked", |
| @@ -104,17 +105,11 @@ private struct Context { | ||
| 104 | 105 | |
| 105 | 106 | func generation(_ mapping: Node.Mapping, path: String) -> GenerationOverrides { |
| 106 | 107 | reader.rejectUnknownKeys(mapping, allowed: ServerConfigLoader.generationKeys, path: path) |
| 107 | - let block = GenerationOverrides( | |
| 108 | - temperature: number( | |
| 109 | - mapping, "temperature", path: path, rule: "must be between 0 and 2" | |
| 110 | - ) { (0 ... 2).contains($0) }, | |
| 111 | - topP: number( | |
| 112 | - mapping, "top_p", path: path, rule: "must be above 0 and at most 1" | |
| 113 | - ) { $0 > 0 && $0 <= 1 }, | |
| 114 | - maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1), | |
| 115 | - thinking: reader.bool(mapping, "thinking", path: path), | |
| 116 | - thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0), | |
| 117 | - showReasoning: reader.bool(mapping, "show_reasoning", path: path)) | |
| 108 | + var block = sampling(mapping, path: path) | |
| 109 | + block.maxTokens = whole(mapping, "max_tokens", path: path, atLeast: 1) | |
| 110 | + block.thinking = reader.bool(mapping, "thinking", path: path) | |
| 111 | + block.thinkingBudget = whole(mapping, "thinking_budget", path: path, atLeast: 0) | |
| 112 | + block.showReasoning = reader.bool(mapping, "show_reasoning", path: path) | |
| 118 | 113 | if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens { |
| 119 | 114 | reader.report( |
| 120 | 115 | "\(path).thinking_budget", mapping["thinking_budget"], |
| @@ -123,6 +118,25 @@ private struct Context { | ||
| 123 | 118 | return block |
| 124 | 119 | } |
| 125 | 120 | |
| 121 | + /// The sampling keys of a `defaults` / `locked` block. | |
| 122 | + func sampling(_ mapping: Node.Mapping, path: String) -> GenerationOverrides { | |
| 123 | + GenerationOverrides( | |
| 124 | + temperature: number( | |
| 125 | + mapping, "temperature", path: path, rule: "must be between 0 and 2" | |
| 126 | + ) { (0 ... 2).contains($0) }, | |
| 127 | + topP: number( | |
| 128 | + mapping, "top_p", path: path, rule: "must be above 0 and at most 1" | |
| 129 | + ) { $0 > 0 && $0 <= 1 }, | |
| 130 | + topK: whole(mapping, "top_k", path: path, atLeast: 0), | |
| 131 | + minP: number(mapping, "min_p", path: path, rule: "must be between 0 and 1") { | |
| 132 | + (0 ... 1).contains($0) | |
| 133 | + }, | |
| 134 | + repetitionPenalty: number( | |
| 135 | + mapping, "repetition_penalty", path: path, rule: "must be above 0" | |
| 136 | + ) { $0 > 0 }, | |
| 137 | + repetitionContextSize: whole(mapping, "repetition_context_size", path: path, atLeast: 1)) | |
| 138 | + } | |
| 139 | + | |
| 126 | 140 | func limits(_ mapping: Node.Mapping, path: String) -> ServerLimits { |
| 127 | 141 | reader.rejectUnknownKeys(mapping, allowed: ServerConfigLoader.limitKeys, path: path) |
| 128 | 142 | var limits = ServerLimits() |
| @@ -56,6 +56,7 @@ public struct ServerConfigLoader: Sendable { | |||
| 56 | static let serverKeys = ["host", "port", "api_key_env", "cors_origin"] | 56 | static let serverKeys = ["host", "port", "api_key_env", "cors_origin"] |
| 57 | static let generationKeys = [ | 57 | static let generationKeys = [ |
| 58 | "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", "show_reasoning", | 58 | "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", "show_reasoning", |
| 59 | + "top_k", "min_p", "repetition_penalty", "repetition_context_size", | ||
| 59 | ] | 60 | ] |
| 60 | static let modelKeys = [ | 61 | static let modelKeys = [ |
| 61 | "id", "source", "revision", "path", "kind", "preload", "defaults", "locked", | 62 | "id", "source", "revision", "path", "kind", "preload", "defaults", "locked", |
| @@ -104,17 +105,11 @@ private struct Context { | |||
| 104 | 105 | ||
| 105 | func generation(_ mapping: Node.Mapping, path: String) -> GenerationOverrides { | 106 | func generation(_ mapping: Node.Mapping, path: String) -> GenerationOverrides { |
| 106 | reader.rejectUnknownKeys(mapping, allowed: ServerConfigLoader.generationKeys, path: path) | 107 | reader.rejectUnknownKeys(mapping, allowed: ServerConfigLoader.generationKeys, path: path) |
| 107 | - let block = GenerationOverrides( | 108 | + var block = sampling(mapping, path: path) |
| 108 | - temperature: number( | 109 | + block.maxTokens = whole(mapping, "max_tokens", path: path, atLeast: 1) |
| 109 | - mapping, "temperature", path: path, rule: "must be between 0 and 2" | 110 | + block.thinking = reader.bool(mapping, "thinking", path: path) |
| 110 | - ) { (0 ... 2).contains($0) }, | 111 | + block.thinkingBudget = whole(mapping, "thinking_budget", path: path, atLeast: 0) |
| 111 | - topP: number( | 112 | + block.showReasoning = reader.bool(mapping, "show_reasoning", path: path) |
| 112 | - mapping, "top_p", path: path, rule: "must be above 0 and at most 1" | ||
| 113 | - ) { $0 > 0 && $0 <= 1 }, | ||
| 114 | - maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1), | ||
| 115 | - thinking: reader.bool(mapping, "thinking", path: path), | ||
| 116 | - thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0), | ||
| 117 | - showReasoning: reader.bool(mapping, "show_reasoning", path: path)) | ||
| 118 | if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens { | 113 | if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens { |
| 119 | reader.report( | 114 | reader.report( |
| 120 | "\(path).thinking_budget", mapping["thinking_budget"], | 115 | "\(path).thinking_budget", mapping["thinking_budget"], |
| @@ -123,6 +118,25 @@ private struct Context { | |||
| 123 | return block | 118 | return block |
| 124 | } | 119 | } |
| 125 | 120 | ||
| 121 | + /// The sampling keys of a `defaults` / `locked` block. | ||
| 122 | + func sampling(_ mapping: Node.Mapping, path: String) -> GenerationOverrides { | ||
| 123 | + GenerationOverrides( | ||
| 124 | + temperature: number( | ||
| 125 | + mapping, "temperature", path: path, rule: "must be between 0 and 2" | ||
| 126 | + ) { (0 ... 2).contains($0) }, | ||
| 127 | + topP: number( | ||
| 128 | + mapping, "top_p", path: path, rule: "must be above 0 and at most 1" | ||
| 129 | + ) { $0 > 0 && $0 <= 1 }, | ||
| 130 | + topK: whole(mapping, "top_k", path: path, atLeast: 0), | ||
| 131 | + minP: number(mapping, "min_p", path: path, rule: "must be between 0 and 1") { | ||
| 132 | + (0 ... 1).contains($0) | ||
| 133 | + }, | ||
| 134 | + repetitionPenalty: number( | ||
| 135 | + mapping, "repetition_penalty", path: path, rule: "must be above 0" | ||
| 136 | + ) { $0 > 0 }, | ||
| 137 | + repetitionContextSize: whole(mapping, "repetition_context_size", path: path, atLeast: 1)) | ||
| 138 | + } | ||
| 139 | + | ||
| 126 | func limits(_ mapping: Node.Mapping, path: String) -> ServerLimits { | 140 | func limits(_ mapping: Node.Mapping, path: String) -> ServerLimits { |
| 127 | reader.rejectUnknownKeys(mapping, allowed: ServerConfigLoader.limitKeys, path: path) | 141 | reader.rejectUnknownKeys(mapping, allowed: ServerConfigLoader.limitKeys, path: path) |
| 128 | var limits = ServerLimits() | 142 | var limits = ServerLimits() |
modified
Sources/RazorbillCore/Engine/GenerationSettings.swift +16 -1 | @@ -23,12 +23,23 @@ public struct GenerationSettings: Sendable, Equatable { | ||
| 23 | 23 | public var presencePenalty: Double? |
| 24 | 24 | /// Penalty growing with how often a token already appeared (OpenAI's `frequency_penalty`). |
| 25 | 25 | public var frequencyPenalty: Double? |
| 26 | + /// Sample only among the `topK` most likely tokens; 0 disables. Default 0. | |
| 27 | + public var topK: Int | |
| 28 | + /// Drop tokens less likely than `minP` × the most likely one; 0 disables. Default 0. | |
| 29 | + public var minP: Double | |
| 30 | + /// Divides the score of tokens seen in the last ``repetitionContextSize`` tokens (prompt | |
| 31 | + /// included); above 1 discourages repeats. `nil` = no penalty. | |
| 32 | + public var repetitionPenalty: Double? | |
| 33 | + /// How many recent tokens ``repetitionPenalty`` looks at. Default 20. | |
| 34 | + public var repetitionContextSize: Int | |
| 26 | 35 | |
| 27 | 36 | public init( |
| 28 | 37 | temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024, |
| 29 | 38 | thinking: Bool = false, thinkingBudget: Int? = nil, showReasoning: Bool = true, |
| 30 | 39 | seed: UInt64? = nil, |
| 31 | - presencePenalty: Double? = nil, frequencyPenalty: Double? = nil | |
| 40 | + presencePenalty: Double? = nil, frequencyPenalty: Double? = nil, | |
| 41 | + topK: Int = 0, minP: Double = 0, repetitionPenalty: Double? = nil, | |
| 42 | + repetitionContextSize: Int = 20 | |
| 32 | 43 | ) { |
| 33 | 44 | self.temperature = temperature |
| 34 | 45 | self.topP = topP |
| @@ -39,5 +50,9 @@ public struct GenerationSettings: Sendable, Equatable { | ||
| 39 | 50 | self.seed = seed |
| 40 | 51 | self.presencePenalty = presencePenalty |
| 41 | 52 | self.frequencyPenalty = frequencyPenalty |
| 53 | + self.topK = topK | |
| 54 | + self.minP = minP | |
| 55 | + self.repetitionPenalty = repetitionPenalty | |
| 56 | + self.repetitionContextSize = repetitionContextSize | |
| 42 | 57 | } |
| 43 | 58 | } |
| @@ -23,12 +23,23 @@ public struct GenerationSettings: Sendable, Equatable { | |||
| 23 | public var presencePenalty: Double? | 23 | public var presencePenalty: Double? |
| 24 | /// Penalty growing with how often a token already appeared (OpenAI's `frequency_penalty`). | 24 | /// Penalty growing with how often a token already appeared (OpenAI's `frequency_penalty`). |
| 25 | public var frequencyPenalty: Double? | 25 | public var frequencyPenalty: Double? |
| 26 | + /// Sample only among the `topK` most likely tokens; 0 disables. Default 0. | ||
| 27 | + public var topK: Int | ||
| 28 | + /// Drop tokens less likely than `minP` × the most likely one; 0 disables. Default 0. | ||
| 29 | + public var minP: Double | ||
| 30 | + /// Divides the score of tokens seen in the last ``repetitionContextSize`` tokens (prompt | ||
| 31 | + /// included); above 1 discourages repeats. `nil` = no penalty. | ||
| 32 | + public var repetitionPenalty: Double? | ||
| 33 | + /// How many recent tokens ``repetitionPenalty`` looks at. Default 20. | ||
| 34 | + public var repetitionContextSize: Int | ||
| 26 | 35 | ||
| 27 | public init( | 36 | public init( |
| 28 | temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024, | 37 | temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024, |
| 29 | thinking: Bool = false, thinkingBudget: Int? = nil, showReasoning: Bool = true, | 38 | thinking: Bool = false, thinkingBudget: Int? = nil, showReasoning: Bool = true, |
| 30 | seed: UInt64? = nil, | 39 | seed: UInt64? = nil, |
| 31 | - presencePenalty: Double? = nil, frequencyPenalty: Double? = nil | 40 | + presencePenalty: Double? = nil, frequencyPenalty: Double? = nil, |
| 41 | + topK: Int = 0, minP: Double = 0, repetitionPenalty: Double? = nil, | ||
| 42 | + repetitionContextSize: Int = 20 | ||
| 32 | ) { | 43 | ) { |
| 33 | self.temperature = temperature | 44 | self.temperature = temperature |
| 34 | self.topP = topP | 45 | self.topP = topP |
| @@ -39,5 +50,9 @@ public struct GenerationSettings: Sendable, Equatable { | |||
| 39 | self.seed = seed | 50 | self.seed = seed |
| 40 | self.presencePenalty = presencePenalty | 51 | self.presencePenalty = presencePenalty |
| 41 | self.frequencyPenalty = frequencyPenalty | 52 | self.frequencyPenalty = frequencyPenalty |
| 53 | + self.topK = topK | ||
| 54 | + self.minP = minP | ||
| 55 | + self.repetitionPenalty = repetitionPenalty | ||
| 56 | + self.repetitionContextSize = repetitionContextSize | ||
| 42 | } | 57 | } |
| 43 | } | 58 | } |
modified
Sources/RazorbillCore/Engine/PromptPrefix.swift +4 -3 | @@ -19,10 +19,11 @@ public struct PromptPrefix: Equatable, Sendable { | ||
| 19 | 19 | /// - prompt: the new prompt's tokens. |
| 20 | 20 | /// - previous: the tokens of the prompt the cache was built from (empty: unknown). |
| 21 | 21 | /// - cachedLength: how many positions the cache holds (previous prompt + generated tokens). |
| 22 | - public init(prompt: [Int], previous: [Int], cachedLength: Int) { | |
| 22 | + /// - minimum: prompt tokens that must still be computed: at least 1, to get the first | |
| 23 | + /// answer token; more when a repetition penalty must see the end of the prompt. | |
| 24 | + public init(prompt: [Int], previous: [Int], cachedLength: Int, computing minimum: Int = 1) { | |
| 23 | 25 | let common = zip(prompt, previous).prefix { $0 == $1 }.count |
| 24 | - // At least one prompt token must be computed to get the first answer token. | |
| 25 | - let keep = max(0, min(common, prompt.count - 1, cachedLength)) | |
| 26 | + let keep = max(0, min(common, prompt.count - max(minimum, 1), cachedLength)) | |
| 26 | 27 | self.keep = keep |
| 27 | 28 | self.trim = keep == 0 ? 0 : cachedLength - keep |
| 28 | 29 | } |
| @@ -19,10 +19,11 @@ public struct PromptPrefix: Equatable, Sendable { | |||
| 19 | /// - prompt: the new prompt's tokens. | 19 | /// - prompt: the new prompt's tokens. |
| 20 | /// - previous: the tokens of the prompt the cache was built from (empty: unknown). | 20 | /// - previous: the tokens of the prompt the cache was built from (empty: unknown). |
| 21 | /// - cachedLength: how many positions the cache holds (previous prompt + generated tokens). | 21 | /// - cachedLength: how many positions the cache holds (previous prompt + generated tokens). |
| 22 | - public init(prompt: [Int], previous: [Int], cachedLength: Int) { | 22 | + /// - minimum: prompt tokens that must still be computed: at least 1, to get the first |
| 23 | + /// answer token; more when a repetition penalty must see the end of the prompt. | ||
| 24 | + public init(prompt: [Int], previous: [Int], cachedLength: Int, computing minimum: Int = 1) { | ||
| 23 | let common = zip(prompt, previous).prefix { $0 == $1 }.count | 25 | let common = zip(prompt, previous).prefix { $0 == $1 }.count |
| 24 | - // At least one prompt token must be computed to get the first answer token. | 26 | + let keep = max(0, min(common, prompt.count - max(minimum, 1), cachedLength)) |
| 25 | - let keep = max(0, min(common, prompt.count - 1, cachedLength)) | ||
| 26 | self.keep = keep | 27 | self.keep = keep |
| 27 | self.trim = keep == 0 ? 0 : cachedLength - keep | 28 | self.trim = keep == 0 ? 0 : cachedLength - keep |
| 28 | } | 29 | } |
modified
Sources/RazorbillMLX/MLXEngine.swift +4 -0 | @@ -135,6 +135,10 @@ public final class MLXEngine: InferenceEngine, @unchecked Sendable { | ||
| 135 | 135 | parameters.seed = generation.seed |
| 136 | 136 | parameters.presencePenalty = generation.presencePenalty.map(Float.init) |
| 137 | 137 | parameters.frequencyPenalty = generation.frequencyPenalty.map(Float.init) |
| 138 | + parameters.topK = generation.topK | |
| 139 | + parameters.minP = Float(generation.minP) | |
| 140 | + parameters.repetitionPenalty = generation.repetitionPenalty.map(Float.init) | |
| 141 | + parameters.repetitionContextSize = generation.repetitionContextSize | |
| 138 | 142 | return parameters |
| 139 | 143 | } |
| 140 | 144 | |
| @@ -135,6 +135,10 @@ public final class MLXEngine: InferenceEngine, @unchecked Sendable { | |||
| 135 | parameters.seed = generation.seed | 135 | parameters.seed = generation.seed |
| 136 | parameters.presencePenalty = generation.presencePenalty.map(Float.init) | 136 | parameters.presencePenalty = generation.presencePenalty.map(Float.init) |
| 137 | parameters.frequencyPenalty = generation.frequencyPenalty.map(Float.init) | 137 | parameters.frequencyPenalty = generation.frequencyPenalty.map(Float.init) |
| 138 | + parameters.topK = generation.topK | ||
| 139 | + parameters.minP = Float(generation.minP) | ||
| 140 | + parameters.repetitionPenalty = generation.repetitionPenalty.map(Float.init) | ||
| 141 | + parameters.repetitionContextSize = generation.repetitionContextSize | ||
| 138 | return parameters | 142 | return parameters |
| 139 | } | 143 | } |
| 140 | 144 | ||
modified
Sources/RazorbillMLX/PromptCache.swift +14 -1 | @@ -25,6 +25,7 @@ final class PromptCache: @unchecked Sendable { | ||
| 25 | 25 | func checkout( |
| 26 | 26 | _ prompt: [Int], model: any LanguageModel, parameters: GenerateParameters |
| 27 | 27 | ) async throws -> (cache: [KVCache], reused: Int) { |
| 28 | + let minimum = Self.penaltyWindow(parameters) | |
| 28 | 29 | if let running = lock.withLock({ generation }) { |
| 29 | 30 | await running.value |
| 30 | 31 | } |
| @@ -35,7 +36,8 @@ final class PromptCache: @unchecked Sendable { | ||
| 35 | 36 | return (self.cache, self.prompt) |
| 36 | 37 | } |
| 37 | 38 | let reuse = PromptPrefix( |
| 38 | - prompt: prompt, previous: previous, cachedLength: cache.map(\.offset).max() ?? 0) | |
| 39 | + prompt: prompt, previous: previous, cachedLength: cache.map(\.offset).max() ?? 0, | |
| 40 | + computing: minimum) | |
| 39 | 41 | if reuse.keep > 0, Self.trim(cache, by: reuse.trim) { |
| 40 | 42 | return (cache, reuse.keep) |
| 41 | 43 | } |
| @@ -62,6 +64,17 @@ final class PromptCache: @unchecked Sendable { | ||
| 62 | 64 | } |
| 63 | 65 | } |
| 64 | 66 | |
| 67 | + /// The penalties look at the last tokens of the prompt they are given: compute at least | |
| 68 | + /// that many again, so they see what a full prefill would show them. | |
| 69 | + static func penaltyWindow(_ parameters: GenerateParameters) -> Int { | |
| 70 | + let windows = [ | |
| 71 | + parameters.repetitionPenalty.map { _ in parameters.repetitionContextSize }, | |
| 72 | + parameters.presencePenalty.map { _ in parameters.presenceContextSize }, | |
| 73 | + parameters.frequencyPenalty.map { _ in parameters.frequencyContextSize }, | |
| 74 | + ] | |
| 75 | + return windows.compactMap { $0 }.max() ?? 1 | |
| 76 | + } | |
| 77 | + | |
| 65 | 78 | private static func trim(_ cache: [KVCache], by count: Int) -> Bool { |
| 66 | 79 | count == 0 || (canTrimPromptCache(cache) && trimPromptCache(cache, numTokens: count) == count) |
| 67 | 80 | } |
| @@ -25,6 +25,7 @@ final class PromptCache: @unchecked Sendable { | |||
| 25 | func checkout( | 25 | func checkout( |
| 26 | _ prompt: [Int], model: any LanguageModel, parameters: GenerateParameters | 26 | _ prompt: [Int], model: any LanguageModel, parameters: GenerateParameters |
| 27 | ) async throws -> (cache: [KVCache], reused: Int) { | 27 | ) async throws -> (cache: [KVCache], reused: Int) { |
| 28 | + let minimum = Self.penaltyWindow(parameters) | ||
| 28 | if let running = lock.withLock({ generation }) { | 29 | if let running = lock.withLock({ generation }) { |
| 29 | await running.value | 30 | await running.value |
| 30 | } | 31 | } |
| @@ -35,7 +36,8 @@ final class PromptCache: @unchecked Sendable { | |||
| 35 | return (self.cache, self.prompt) | 36 | return (self.cache, self.prompt) |
| 36 | } | 37 | } |
| 37 | let reuse = PromptPrefix( | 38 | let reuse = PromptPrefix( |
| 38 | - prompt: prompt, previous: previous, cachedLength: cache.map(\.offset).max() ?? 0) | 39 | + prompt: prompt, previous: previous, cachedLength: cache.map(\.offset).max() ?? 0, |
| 40 | + computing: minimum) | ||
| 39 | if reuse.keep > 0, Self.trim(cache, by: reuse.trim) { | 41 | if reuse.keep > 0, Self.trim(cache, by: reuse.trim) { |
| 40 | return (cache, reuse.keep) | 42 | return (cache, reuse.keep) |
| 41 | } | 43 | } |
| @@ -62,6 +64,17 @@ final class PromptCache: @unchecked Sendable { | |||
| 62 | } | 64 | } |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 67 | + /// The penalties look at the last tokens of the prompt they are given: compute at least | ||
| 68 | + /// that many again, so they see what a full prefill would show them. | ||
| 69 | + static func penaltyWindow(_ parameters: GenerateParameters) -> Int { | ||
| 70 | + let windows = [ | ||
| 71 | + parameters.repetitionPenalty.map { _ in parameters.repetitionContextSize }, | ||
| 72 | + parameters.presencePenalty.map { _ in parameters.presenceContextSize }, | ||
| 73 | + parameters.frequencyPenalty.map { _ in parameters.frequencyContextSize }, | ||
| 74 | + ] | ||
| 75 | + return windows.compactMap { $0 }.max() ?? 1 | ||
| 76 | + } | ||
| 77 | + | ||
| 65 | private static func trim(_ cache: [KVCache], by count: Int) -> Bool { | 78 | private static func trim(_ cache: [KVCache], by count: Int) -> Bool { |
| 66 | count == 0 || (canTrimPromptCache(cache) && trimPromptCache(cache, numTokens: count) == count) | 79 | count == 0 || (canTrimPromptCache(cache) && trimPromptCache(cache, numTokens: count) == count) |
| 67 | } | 80 | } |
modified
Sources/RazorbillServer/Chat/ChatCompletionRequest.swift +9 -3 | @@ -32,6 +32,8 @@ struct ChatCompletionRequest: Decodable, Sendable, FieldChecking { | ||
| 32 | 32 | var thinkingBudget: Int? |
| 33 | 33 | /// OpenRouter's convention: `false` hides the reasoning (the model still thinks). |
| 34 | 34 | var includeReasoning: Bool? |
| 35 | + /// `top_k`, `min_p`, `repetition_penalty`…, decoded separately by ``decode(_:)``. | |
| 36 | + var extensions = SamplingExtensions() | |
| 35 | 37 | |
| 36 | 38 | enum CodingKeys: String, CodingKey { |
| 37 | 39 | case model, messages, temperature, stop, seed, stream, logprobs, tools |
| @@ -56,6 +58,7 @@ struct ChatCompletionRequest: Decodable, Sendable, FieldChecking { | ||
| 56 | 58 | static func decode(_ data: Data) throws -> ChatCompletionRequest { |
| 57 | 59 | do { |
| 58 | 60 | var request = try JSONDecoder().decode(ChatCompletionRequest.self, from: data) |
| 61 | + request.extensions = try JSONDecoder().decode(SamplingExtensions.self, from: data) | |
| 59 | 62 | if let ordered = try? ConfigValue(orderedJSON: data) { |
| 60 | 63 | request.keepSchemaOrder(from: ordered) |
| 61 | 64 | } |
| @@ -191,15 +194,18 @@ extension ChatCompletionRequest { | ||
| 191 | 194 | limitName: maxCompletionTokens == nil ? "max_tokens" : "max_completion_tokens", |
| 192 | 195 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, |
| 193 | 196 | stops: stops)) |
| 197 | + let extensions = try self.extensions.validated() | |
| 194 | 198 | try checkReasoningSwitches() |
| 195 | 199 | let output = try outputPlan() |
| 196 | 200 | let mapped = try messages.enumerated().map { try Self.message($1, at: $0) } |
| 197 | 201 | return ChatPlan( |
| 198 | 202 | model: model, |
| 199 | 203 | messages: Self.adding(formatInstruction(), to: mapped), |
| 200 | - client: GenerationOverrides( | |
| 201 | - temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking, | |
| 202 | - thinkingBudget: thinkingBudget, showReasoning: includeReasoning), | |
| 204 | + client: extensions.adding( | |
| 205 | + to: GenerationOverrides( | |
| 206 | + temperature: temperature, topP: topP, maxTokens: limit, | |
| 207 | + thinking: requestedThinking, thinkingBudget: thinkingBudget, | |
| 208 | + showReasoning: includeReasoning)), | |
| 203 | 209 | seed: seed.map { UInt64(bitPattern: $0) }, |
| 204 | 210 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, |
| 205 | 211 | stops: stops, stream: stream ?? false, |
| @@ -32,6 +32,8 @@ struct ChatCompletionRequest: Decodable, Sendable, FieldChecking { | |||
| 32 | var thinkingBudget: Int? | 32 | var thinkingBudget: Int? |
| 33 | /// OpenRouter's convention: `false` hides the reasoning (the model still thinks). | 33 | /// OpenRouter's convention: `false` hides the reasoning (the model still thinks). |
| 34 | var includeReasoning: Bool? | 34 | var includeReasoning: Bool? |
| 35 | + /// `top_k`, `min_p`, `repetition_penalty`…, decoded separately by ``decode(_:)``. | ||
| 36 | + var extensions = SamplingExtensions() | ||
| 35 | 37 | ||
| 36 | enum CodingKeys: String, CodingKey { | 38 | enum CodingKeys: String, CodingKey { |
| 37 | case model, messages, temperature, stop, seed, stream, logprobs, tools | 39 | case model, messages, temperature, stop, seed, stream, logprobs, tools |
| @@ -56,6 +58,7 @@ struct ChatCompletionRequest: Decodable, Sendable, FieldChecking { | |||
| 56 | static func decode(_ data: Data) throws -> ChatCompletionRequest { | 58 | static func decode(_ data: Data) throws -> ChatCompletionRequest { |
| 57 | do { | 59 | do { |
| 58 | var request = try JSONDecoder().decode(ChatCompletionRequest.self, from: data) | 60 | var request = try JSONDecoder().decode(ChatCompletionRequest.self, from: data) |
| 61 | + request.extensions = try JSONDecoder().decode(SamplingExtensions.self, from: data) | ||
| 59 | if let ordered = try? ConfigValue(orderedJSON: data) { | 62 | if let ordered = try? ConfigValue(orderedJSON: data) { |
| 60 | request.keepSchemaOrder(from: ordered) | 63 | request.keepSchemaOrder(from: ordered) |
| 61 | } | 64 | } |
| @@ -191,15 +194,18 @@ extension ChatCompletionRequest { | |||
| 191 | limitName: maxCompletionTokens == nil ? "max_tokens" : "max_completion_tokens", | 194 | limitName: maxCompletionTokens == nil ? "max_tokens" : "max_completion_tokens", |
| 192 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, | 195 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, |
| 193 | stops: stops)) | 196 | stops: stops)) |
| 197 | + let extensions = try self.extensions.validated() | ||
| 194 | try checkReasoningSwitches() | 198 | try checkReasoningSwitches() |
| 195 | let output = try outputPlan() | 199 | let output = try outputPlan() |
| 196 | let mapped = try messages.enumerated().map { try Self.message($1, at: $0) } | 200 | let mapped = try messages.enumerated().map { try Self.message($1, at: $0) } |
| 197 | return ChatPlan( | 201 | return ChatPlan( |
| 198 | model: model, | 202 | model: model, |
| 199 | messages: Self.adding(formatInstruction(), to: mapped), | 203 | messages: Self.adding(formatInstruction(), to: mapped), |
| 200 | - client: GenerationOverrides( | 204 | + client: extensions.adding( |
| 201 | - temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking, | 205 | + to: GenerationOverrides( |
| 202 | - thinkingBudget: thinkingBudget, showReasoning: includeReasoning), | 206 | + temperature: temperature, topP: topP, maxTokens: limit, |
| 207 | + thinking: requestedThinking, thinkingBudget: thinkingBudget, | ||
| 208 | + showReasoning: includeReasoning)), | ||
| 203 | seed: seed.map { UInt64(bitPattern: $0) }, | 209 | seed: seed.map { UInt64(bitPattern: $0) }, |
| 204 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, | 210 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, |
| 205 | stops: stops, stream: stream ?? false, | 211 | stops: stops, stream: stream ?? false, |
modified
Sources/RazorbillServer/CompletionsRoute.swift +8 -3 | @@ -25,6 +25,8 @@ struct CompletionRequest: Decodable, Sendable, FieldChecking { | ||
| 25 | 25 | var logprobs: Int? |
| 26 | 26 | var choiceCount: Int? |
| 27 | 27 | var bestOf: Int? |
| 28 | + /// `top_k`, `min_p`, `repetition_penalty`…, decoded separately by ``decode(_:)``. | |
| 29 | + var extensions = SamplingExtensions() | |
| 28 | 30 | |
| 29 | 31 | enum CodingKeys: String, CodingKey { |
| 30 | 32 | case model, prompt, temperature, stop, seed, stream, echo, suffix, logprobs |
| @@ -39,7 +41,9 @@ struct CompletionRequest: Decodable, Sendable, FieldChecking { | ||
| 39 | 41 | |
| 40 | 42 | static func decode(_ data: Data) throws -> CompletionRequest { |
| 41 | 43 | do { |
| 42 | - return try JSONDecoder().decode(CompletionRequest.self, from: data) | |
| 44 | + var request = try JSONDecoder().decode(CompletionRequest.self, from: data) | |
| 45 | + request.extensions = try JSONDecoder().decode(SamplingExtensions.self, from: data) | |
| 46 | + return request | |
| 43 | 47 | } catch let error as DecodingError { |
| 44 | 48 | throw OpenAIError.invalidBody(error) |
| 45 | 49 | } catch { |
| @@ -59,8 +63,9 @@ struct CompletionRequest: Decodable, Sendable, FieldChecking { | ||
| 59 | 63 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, stops: stops)) |
| 60 | 64 | return CompletionPlan( |
| 61 | 65 | model: model, prompt: try prompt.single(), |
| 62 | - client: GenerationOverrides( | |
| 63 | - temperature: temperature, topP: topP, maxTokens: maxTokens, thinking: false), | |
| 66 | + client: try extensions.validated().adding( | |
| 67 | + to: GenerationOverrides( | |
| 68 | + temperature: temperature, topP: topP, maxTokens: maxTokens, thinking: false)), | |
| 64 | 69 | seed: seed.map { UInt64(bitPattern: $0) }, presencePenalty: presencePenalty, |
| 65 | 70 | frequencyPenalty: frequencyPenalty, stops: stops, stream: stream ?? false, |
| 66 | 71 | includeUsage: streamOptions?.includeUsage ?? false, echo: echo ?? false) |
| @@ -25,6 +25,8 @@ struct CompletionRequest: Decodable, Sendable, FieldChecking { | |||
| 25 | var logprobs: Int? | 25 | var logprobs: Int? |
| 26 | var choiceCount: Int? | 26 | var choiceCount: Int? |
| 27 | var bestOf: Int? | 27 | var bestOf: Int? |
| 28 | + /// `top_k`, `min_p`, `repetition_penalty`…, decoded separately by ``decode(_:)``. | ||
| 29 | + var extensions = SamplingExtensions() | ||
| 28 | 30 | ||
| 29 | enum CodingKeys: String, CodingKey { | 31 | enum CodingKeys: String, CodingKey { |
| 30 | case model, prompt, temperature, stop, seed, stream, echo, suffix, logprobs | 32 | case model, prompt, temperature, stop, seed, stream, echo, suffix, logprobs |
| @@ -39,7 +41,9 @@ struct CompletionRequest: Decodable, Sendable, FieldChecking { | |||
| 39 | 41 | ||
| 40 | static func decode(_ data: Data) throws -> CompletionRequest { | 42 | static func decode(_ data: Data) throws -> CompletionRequest { |
| 41 | do { | 43 | do { |
| 42 | - return try JSONDecoder().decode(CompletionRequest.self, from: data) | 44 | + var request = try JSONDecoder().decode(CompletionRequest.self, from: data) |
| 45 | + request.extensions = try JSONDecoder().decode(SamplingExtensions.self, from: data) | ||
| 46 | + return request | ||
| 43 | } catch let error as DecodingError { | 47 | } catch let error as DecodingError { |
| 44 | throw OpenAIError.invalidBody(error) | 48 | throw OpenAIError.invalidBody(error) |
| 45 | } catch { | 49 | } catch { |
| @@ -59,8 +63,9 @@ struct CompletionRequest: Decodable, Sendable, FieldChecking { | |||
| 59 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, stops: stops)) | 63 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, stops: stops)) |
| 60 | return CompletionPlan( | 64 | return CompletionPlan( |
| 61 | model: model, prompt: try prompt.single(), | 65 | model: model, prompt: try prompt.single(), |
| 62 | - client: GenerationOverrides( | 66 | + client: try extensions.validated().adding( |
| 63 | - temperature: temperature, topP: topP, maxTokens: maxTokens, thinking: false), | 67 | + to: GenerationOverrides( |
| 68 | + temperature: temperature, topP: topP, maxTokens: maxTokens, thinking: false)), | ||
| 64 | seed: seed.map { UInt64(bitPattern: $0) }, presencePenalty: presencePenalty, | 69 | seed: seed.map { UInt64(bitPattern: $0) }, presencePenalty: presencePenalty, |
| 65 | frequencyPenalty: frequencyPenalty, stops: stops, stream: stream ?? false, | 70 | frequencyPenalty: frequencyPenalty, stops: stops, stream: stream ?? false, |
| 66 | includeUsage: streamOptions?.includeUsage ?? false, echo: echo ?? false) | 71 | includeUsage: streamOptions?.includeUsage ?? false, echo: echo ?? false) |
modified
Sources/RazorbillServer/FieldChecking.swift +36 -0 | @@ -39,3 +39,39 @@ extension FieldChecking { | ||
| 39 | 39 | try check(fields.frequencyPenalty, "frequency_penalty", penalty) { abs($0) <= 2 } |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | + | |
| 43 | +/// Sampling fields outside OpenAI's API that mlx-swift-lm implements, under the names vLLM, | |
| 44 | +/// llama-server, Ollama and mlx-lm use. Read from the same body as the request. | |
| 45 | +struct SamplingExtensions: Decodable, Sendable, Equatable, FieldChecking { | |
| 46 | + var topK: Int? | |
| 47 | + var minP: Double? | |
| 48 | + var repetitionPenalty: Double? | |
| 49 | + var repetitionContextSize: Int? | |
| 50 | + | |
| 51 | + enum CodingKeys: String, CodingKey { | |
| 52 | + case topK = "top_k" | |
| 53 | + case minP = "min_p" | |
| 54 | + case repetitionPenalty = "repetition_penalty" | |
| 55 | + case repetitionContextSize = "repetition_context_size" | |
| 56 | + } | |
| 57 | + | |
| 58 | + func validated() throws -> Self { | |
| 59 | + try check(topK, "top_k", "must be 0 or more") { $0 >= 0 } | |
| 60 | + try check(minP, "min_p", "must be between 0 and 1") { (0 ... 1).contains($0) } | |
| 61 | + try check(repetitionPenalty, "repetition_penalty", "must be above 0") { $0 > 0 } | |
| 62 | + try check(repetitionContextSize, "repetition_context_size", "must be 1 or more") { | |
| 63 | + $0 >= 1 | |
| 64 | + } | |
| 65 | + return self | |
| 66 | + } | |
| 67 | + | |
| 68 | + /// `overrides` with these values added. | |
| 69 | + func adding(to overrides: GenerationOverrides) -> GenerationOverrides { | |
| 70 | + var result = overrides | |
| 71 | + result.topK = topK | |
| 72 | + result.minP = minP | |
| 73 | + result.repetitionPenalty = repetitionPenalty | |
| 74 | + result.repetitionContextSize = repetitionContextSize | |
| 75 | + return result | |
| 76 | + } | |
| 77 | +} | |
| @@ -39,3 +39,39 @@ extension FieldChecking { | |||
| 39 | try check(fields.frequencyPenalty, "frequency_penalty", penalty) { abs($0) <= 2 } | 39 | try check(fields.frequencyPenalty, "frequency_penalty", penalty) { abs($0) <= 2 } |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | + | ||
| 43 | +/// Sampling fields outside OpenAI's API that mlx-swift-lm implements, under the names vLLM, | ||
| 44 | +/// llama-server, Ollama and mlx-lm use. Read from the same body as the request. | ||
| 45 | +struct SamplingExtensions: Decodable, Sendable, Equatable, FieldChecking { | ||
| 46 | + var topK: Int? | ||
| 47 | + var minP: Double? | ||
| 48 | + var repetitionPenalty: Double? | ||
| 49 | + var repetitionContextSize: Int? | ||
| 50 | + | ||
| 51 | + enum CodingKeys: String, CodingKey { | ||
| 52 | + case topK = "top_k" | ||
| 53 | + case minP = "min_p" | ||
| 54 | + case repetitionPenalty = "repetition_penalty" | ||
| 55 | + case repetitionContextSize = "repetition_context_size" | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + func validated() throws -> Self { | ||
| 59 | + try check(topK, "top_k", "must be 0 or more") { $0 >= 0 } | ||
| 60 | + try check(minP, "min_p", "must be between 0 and 1") { (0 ... 1).contains($0) } | ||
| 61 | + try check(repetitionPenalty, "repetition_penalty", "must be above 0") { $0 > 0 } | ||
| 62 | + try check(repetitionContextSize, "repetition_context_size", "must be 1 or more") { | ||
| 63 | + $0 >= 1 | ||
| 64 | + } | ||
| 65 | + return self | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /// `overrides` with these values added. | ||
| 69 | + func adding(to overrides: GenerationOverrides) -> GenerationOverrides { | ||
| 70 | + var result = overrides | ||
| 71 | + result.topK = topK | ||
| 72 | + result.minP = minP | ||
| 73 | + result.repetitionPenalty = repetitionPenalty | ||
| 74 | + result.repetitionContextSize = repetitionContextSize | ||
| 75 | + return result | ||
| 76 | + } | ||
| 77 | +} | ||
modified
Tests/Compatibility/test_chat.py +25 -1 | @@ -84,7 +84,14 @@ def test_raw_stream_ends_with_done(http): | ||
| 84 | 84 | |
| 85 | 85 | @pytest.mark.parametrize( |
| 86 | 86 | ("field", "value"), |
| 87 | - [("n", 2), ("logprobs", True), ("temperature", -1), ("reasoning_effort", "huge")], | |
| 87 | + [ | |
| 88 | + ("n", 2), | |
| 89 | + ("logprobs", True), | |
| 90 | + ("temperature", -1), | |
| 91 | + ("reasoning_effort", "huge"), | |
| 92 | + ("top_k", -1), | |
| 93 | + ("min_p", 2), | |
| 94 | + ], | |
| 88 | 95 | ) |
| 89 | 96 | def test_unsupported_or_invalid_fields_are_400(client, field, value): |
| 90 | 97 | with pytest.raises(openai.BadRequestError) as error: |
| @@ -94,6 +101,23 @@ def test_unsupported_or_invalid_fields_are_400(client, field, value): | ||
| 94 | 101 | assert error.value.body["param"] == field |
| 95 | 102 | |
| 96 | 103 | |
| 104 | +def test_mlx_sampling_extensions_are_accepted(client): | |
| 105 | + """top_k, min_p and repetition_penalty, sent the way vLLM / llama-server clients send them.""" | |
| 106 | + answer = client.chat.completions.create( | |
| 107 | + model="chat", | |
| 108 | + messages=[{"role": "user", "content": "Say hello."}], | |
| 109 | + max_tokens=20, | |
| 110 | + extra_body={ | |
| 111 | + **NO_THINKING, | |
| 112 | + "top_k": 20, | |
| 113 | + "min_p": 0.05, | |
| 114 | + "repetition_penalty": 1.1, | |
| 115 | + "repetition_context_size": 32, | |
| 116 | + }, | |
| 117 | + ) | |
| 118 | + assert answer.choices[0].message.content | |
| 119 | + | |
| 120 | + | |
| 97 | 121 | def test_embedding_model_cannot_chat(client): |
| 98 | 122 | with pytest.raises(openai.BadRequestError) as error: |
| 99 | 123 | client.chat.completions.create(model="embed", messages=[{"role": "user", "content": "hi"}]) |
| @@ -84,7 +84,14 @@ def test_raw_stream_ends_with_done(http): | |||
| 84 | 84 | ||
| 85 | @pytest.mark.parametrize( | 85 | @pytest.mark.parametrize( |
| 86 | ("field", "value"), | 86 | ("field", "value"), |
| 87 | - [("n", 2), ("logprobs", True), ("temperature", -1), ("reasoning_effort", "huge")], | 87 | + [ |
| 88 | + ("n", 2), | ||
| 89 | + ("logprobs", True), | ||
| 90 | + ("temperature", -1), | ||
| 91 | + ("reasoning_effort", "huge"), | ||
| 92 | + ("top_k", -1), | ||
| 93 | + ("min_p", 2), | ||
| 94 | + ], | ||
| 88 | ) | 95 | ) |
| 89 | def test_unsupported_or_invalid_fields_are_400(client, field, value): | 96 | def test_unsupported_or_invalid_fields_are_400(client, field, value): |
| 90 | with pytest.raises(openai.BadRequestError) as error: | 97 | with pytest.raises(openai.BadRequestError) as error: |
| @@ -94,6 +101,23 @@ def test_unsupported_or_invalid_fields_are_400(client, field, value): | |||
| 94 | assert error.value.body["param"] == field | 101 | assert error.value.body["param"] == field |
| 95 | 102 | ||
| 96 | 103 | ||
| 104 | +def test_mlx_sampling_extensions_are_accepted(client): | ||
| 105 | + """top_k, min_p and repetition_penalty, sent the way vLLM / llama-server clients send them.""" | ||
| 106 | + answer = client.chat.completions.create( | ||
| 107 | + model="chat", | ||
| 108 | + messages=[{"role": "user", "content": "Say hello."}], | ||
| 109 | + max_tokens=20, | ||
| 110 | + extra_body={ | ||
| 111 | + **NO_THINKING, | ||
| 112 | + "top_k": 20, | ||
| 113 | + "min_p": 0.05, | ||
| 114 | + "repetition_penalty": 1.1, | ||
| 115 | + "repetition_context_size": 32, | ||
| 116 | + }, | ||
| 117 | + ) | ||
| 118 | + assert answer.choices[0].message.content | ||
| 119 | + | ||
| 120 | + | ||
| 97 | def test_embedding_model_cannot_chat(client): | 121 | def test_embedding_model_cannot_chat(client): |
| 98 | with pytest.raises(openai.BadRequestError) as error: | 122 | with pytest.raises(openai.BadRequestError) as error: |
| 99 | client.chat.completions.create(model="embed", messages=[{"role": "user", "content": "hi"}]) | 123 | client.chat.completions.create(model="embed", messages=[{"role": "user", "content": "hi"}]) |
modified
Tests/RazorbillCoreTests/PromptPrefixTests.swift +9 -0 | @@ -24,6 +24,15 @@ struct PromptPrefixTests { | ||
| 24 | 24 | #expect(PromptPrefix(prompt: [4], previous: [4], cachedLength: 2).keep == 0) |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | + @Test func leavesEnoughTokensForARepetitionWindow() { | |
| 28 | + let prompt = Array(0 ..< 100) | |
| 29 | + let reuse = PromptPrefix( | |
| 30 | + prompt: prompt, previous: Array(0 ..< 90), cachedLength: 95, computing: 20) | |
| 31 | + #expect(reuse == PromptPrefix(keep: 80, trim: 15)) | |
| 32 | + let short = PromptPrefix(prompt: [1, 2], previous: [1], cachedLength: 3, computing: 20) | |
| 33 | + #expect(short.keep == 0) | |
| 34 | + } | |
| 35 | + | |
| 27 | 36 | @Test func neverKeepsMoreThanTheCacheHolds() { |
| 28 | 37 | let reuse = PromptPrefix(prompt: [1, 2, 3, 4], previous: [1, 2, 3], cachedLength: 2) |
| 29 | 38 | #expect(reuse == PromptPrefix(keep: 2, trim: 0)) |
| @@ -24,6 +24,15 @@ struct PromptPrefixTests { | |||
| 24 | #expect(PromptPrefix(prompt: [4], previous: [4], cachedLength: 2).keep == 0) | 24 | #expect(PromptPrefix(prompt: [4], previous: [4], cachedLength: 2).keep == 0) |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | + @Test func leavesEnoughTokensForARepetitionWindow() { | ||
| 28 | + let prompt = Array(0 ..< 100) | ||
| 29 | + let reuse = PromptPrefix( | ||
| 30 | + prompt: prompt, previous: Array(0 ..< 90), cachedLength: 95, computing: 20) | ||
| 31 | + #expect(reuse == PromptPrefix(keep: 80, trim: 15)) | ||
| 32 | + let short = PromptPrefix(prompt: [1, 2], previous: [1], cachedLength: 3, computing: 20) | ||
| 33 | + #expect(short.keep == 0) | ||
| 34 | + } | ||
| 35 | + | ||
| 27 | @Test func neverKeepsMoreThanTheCacheHolds() { | 36 | @Test func neverKeepsMoreThanTheCacheHolds() { |
| 28 | let reuse = PromptPrefix(prompt: [1, 2, 3, 4], previous: [1, 2, 3], cachedLength: 2) | 37 | let reuse = PromptPrefix(prompt: [1, 2, 3, 4], previous: [1, 2, 3], cachedLength: 2) |
| 29 | #expect(reuse == PromptPrefix(keep: 2, trim: 0)) | 38 | #expect(reuse == PromptPrefix(keep: 2, trim: 0)) |
modified
Tests/RazorbillCoreTests/ServerConfigLoaderTests.swift +29 -0 | @@ -121,6 +121,24 @@ import Testing | ||
| 121 | 121 | ]) |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | + @Test func mlxSamplingKeysAreReadAndChecked() throws { | |
| 125 | + let config = try loader.parse( | |
| 126 | + """ | |
| 127 | + defaults: { top_k: 20, min_p: 0.05 } | |
| 128 | + locked: { repetition_penalty: 1.1, repetition_context_size: 64 } | |
| 129 | + """) | |
| 130 | + #expect(config.defaults == GenerationOverrides(topK: 20, minP: 0.05)) | |
| 131 | + #expect( | |
| 132 | + config.locked | |
| 133 | + == GenerationOverrides(repetitionPenalty: 1.1, repetitionContextSize: 64)) | |
| 134 | + #expect( | |
| 135 | + issues("defaults: { top_k: -1, min_p: 2, repetition_penalty: 0 }\n") == [ | |
| 136 | + "line 1: defaults.top_k: must be 0 or more", | |
| 137 | + "line 1: defaults.min_p: must be between 0 and 1", | |
| 138 | + "line 1: defaults.repetition_penalty: must be above 0", | |
| 139 | + ]) | |
| 140 | + } | |
| 141 | + | |
| 124 | 142 | @Test func wrongShapesAreReported() { |
| 125 | 143 | #expect( |
| 126 | 144 | issues("models: qwen3\n") == ["line 1: models: must be a list (lines starting with -)"]) |
| @@ -178,6 +196,17 @@ import Testing | ||
| 178 | 196 | #expect(unlimited.thinkingBudget == 64) |
| 179 | 197 | } |
| 180 | 198 | |
| 199 | + @Test func samplingExtensionsFollowTheSameOrder() { | |
| 200 | + let settings = GenerationOverrides.resolve( | |
| 201 | + defaults: [GenerationOverrides(topK: 20, minP: 0.05)], | |
| 202 | + client: GenerationOverrides(topK: 50, repetitionPenalty: 1.3), | |
| 203 | + locked: [GenerationOverrides(repetitionPenalty: 1.05)]) | |
| 204 | + #expect(settings.topK == 50 && settings.minP == 0.05) | |
| 205 | + #expect(settings.repetitionPenalty == 1.05) | |
| 206 | + #expect(settings.repetitionContextSize == 20) | |
| 207 | + #expect(GenerationOverrides.resolve(defaults: [], client: .init(), locked: []).topK == 0) | |
| 208 | + } | |
| 209 | + | |
| 181 | 210 | @Test func laterLockedBlocksTightenFurther() { |
| 182 | 211 | let settings = GenerationOverrides.resolve( |
| 183 | 212 | defaults: [], client: .init(), |
| @@ -121,6 +121,24 @@ import Testing | |||
| 121 | ]) | 121 | ]) |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | + @Test func mlxSamplingKeysAreReadAndChecked() throws { | ||
| 125 | + let config = try loader.parse( | ||
| 126 | + """ | ||
| 127 | + defaults: { top_k: 20, min_p: 0.05 } | ||
| 128 | + locked: { repetition_penalty: 1.1, repetition_context_size: 64 } | ||
| 129 | + """) | ||
| 130 | + #expect(config.defaults == GenerationOverrides(topK: 20, minP: 0.05)) | ||
| 131 | + #expect( | ||
| 132 | + config.locked | ||
| 133 | + == GenerationOverrides(repetitionPenalty: 1.1, repetitionContextSize: 64)) | ||
| 134 | + #expect( | ||
| 135 | + issues("defaults: { top_k: -1, min_p: 2, repetition_penalty: 0 }\n") == [ | ||
| 136 | + "line 1: defaults.top_k: must be 0 or more", | ||
| 137 | + "line 1: defaults.min_p: must be between 0 and 1", | ||
| 138 | + "line 1: defaults.repetition_penalty: must be above 0", | ||
| 139 | + ]) | ||
| 140 | + } | ||
| 141 | + | ||
| 124 | @Test func wrongShapesAreReported() { | 142 | @Test func wrongShapesAreReported() { |
| 125 | #expect( | 143 | #expect( |
| 126 | issues("models: qwen3\n") == ["line 1: models: must be a list (lines starting with -)"]) | 144 | issues("models: qwen3\n") == ["line 1: models: must be a list (lines starting with -)"]) |
| @@ -178,6 +196,17 @@ import Testing | |||
| 178 | #expect(unlimited.thinkingBudget == 64) | 196 | #expect(unlimited.thinkingBudget == 64) |
| 179 | } | 197 | } |
| 180 | 198 | ||
| 199 | + @Test func samplingExtensionsFollowTheSameOrder() { | ||
| 200 | + let settings = GenerationOverrides.resolve( | ||
| 201 | + defaults: [GenerationOverrides(topK: 20, minP: 0.05)], | ||
| 202 | + client: GenerationOverrides(topK: 50, repetitionPenalty: 1.3), | ||
| 203 | + locked: [GenerationOverrides(repetitionPenalty: 1.05)]) | ||
| 204 | + #expect(settings.topK == 50 && settings.minP == 0.05) | ||
| 205 | + #expect(settings.repetitionPenalty == 1.05) | ||
| 206 | + #expect(settings.repetitionContextSize == 20) | ||
| 207 | + #expect(GenerationOverrides.resolve(defaults: [], client: .init(), locked: []).topK == 0) | ||
| 208 | + } | ||
| 209 | + | ||
| 181 | @Test func laterLockedBlocksTightenFurther() { | 210 | @Test func laterLockedBlocksTightenFurther() { |
| 182 | let settings = GenerationOverrides.resolve( | 211 | let settings = GenerationOverrides.resolve( |
| 183 | defaults: [], client: .init(), | 212 | defaults: [], client: .init(), |
modified
Tests/RazorbillMLXTests/ChatSmokeTests.swift +7 -3 | @@ -100,9 +100,13 @@ struct ChatSmokeTests { | ||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /// A client resends the conversation: the second request takes the shared start from the |
| 103 | - /// cache of the first, and answers exactly as a fresh engine does. | |
| 104 | - @Test func secondTurnReusesTheCacheWithTheSameAnswer() async throws { | |
| 105 | - let first = plan("What is the capital of France?") | |
| 103 | + /// cache of the first, and answers exactly as a fresh engine does — also with a repetition | |
| 104 | + /// penalty, which must still see the end of the prompt. | |
| 105 | + @Test(arguments: [nil, 1.3]) | |
| 106 | + func secondTurnReusesTheCacheWithTheSameAnswer(penalty: Double?) async throws { | |
| 107 | + var first = plan("What is the capital of France?") | |
| 108 | + first.client.repetitionPenalty = penalty | |
| 109 | + first.client.repetitionContextSize = 16 | |
| 106 | 110 | let answer = try await route().complete(first) |
| 107 | 111 | var second = first |
| 108 | 112 | second.messages += [ |
| @@ -100,9 +100,13 @@ struct ChatSmokeTests { | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | /// A client resends the conversation: the second request takes the shared start from the | 102 | /// A client resends the conversation: the second request takes the shared start from the |
| 103 | - /// cache of the first, and answers exactly as a fresh engine does. | 103 | + /// cache of the first, and answers exactly as a fresh engine does — also with a repetition |
| 104 | - @Test func secondTurnReusesTheCacheWithTheSameAnswer() async throws { | 104 | + /// penalty, which must still see the end of the prompt. |
| 105 | - let first = plan("What is the capital of France?") | 105 | + @Test(arguments: [nil, 1.3]) |
| 106 | + func secondTurnReusesTheCacheWithTheSameAnswer(penalty: Double?) async throws { | ||
| 107 | + var first = plan("What is the capital of France?") | ||
| 108 | + first.client.repetitionPenalty = penalty | ||
| 109 | + first.client.repetitionContextSize = 16 | ||
| 106 | let answer = try await route().complete(first) | 110 | let answer = try await route().complete(first) |
| 107 | var second = first | 111 | var second = first |
| 108 | second.messages += [ | 112 | second.messages += [ |
modified
Tests/RazorbillServerTests/ChatCompletionTests.swift +22 -0 | @@ -129,6 +129,24 @@ func simpleRequest(_ model: String = "org/m", content: String = "x", extra: Stri | ||
| 129 | 129 | #expect(generation.presencePenalty == 0.5 && generation.frequencyPenalty == -0.5) |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | + @Test func mlxSamplingExtensionsReachTheEngine() async throws { | |
| 133 | + let engines = TestEngines() | |
| 134 | + var settings = testSettings | |
| 135 | + settings.config = ServerConfig( | |
| 136 | + defaults: GenerationOverrides(topK: 20, minP: 0.05), | |
| 137 | + locked: GenerationOverrides(repetitionContextSize: 64)) | |
| 138 | + let extra = | |
| 139 | + #","top_k":40,"repetition_penalty":1.1,"repetition_context_size":8"# | |
| 140 | + try await withLiveServer(settings, engines: engines) { client in | |
| 141 | + let response = try await post(client, simpleRequest(extra: extra)) | |
| 142 | + #expect(response.status == .ok) | |
| 143 | + } | |
| 144 | + let generation = try #require(engines.fake.sessionSetups.first?.generation) | |
| 145 | + #expect(generation.topK == 40 && generation.minP == 0.05) | |
| 146 | + #expect(generation.repetitionPenalty == 1.1) | |
| 147 | + #expect(generation.repetitionContextSize == 64) // locked | |
| 148 | + } | |
| 149 | + | |
| 132 | 150 | @Test func stopSequencesCutTheAnswerWithoutLeaking() async throws { |
| 133 | 151 | let engines = TestEngines(script: [ |
| 134 | 152 | [.text("Hello wo"), .text("rld EN"), .text("D and more")] |
| @@ -177,6 +195,10 @@ func simpleRequest(_ model: String = "org/m", content: String = "x", extra: Stri | ||
| 177 | 195 | (simpleRequest(extra: #","top_p":"high""#), "top_p"), |
| 178 | 196 | (simpleRequest(extra: #","max_tokens":0"#), "max_tokens"), |
| 179 | 197 | (simpleRequest(extra: #","n":2"#), "n"), |
| 198 | + (simpleRequest(extra: #","top_k":-1"#), "top_k"), | |
| 199 | + (simpleRequest(extra: #","min_p":1.5"#), "min_p"), | |
| 200 | + (simpleRequest(extra: #","repetition_penalty":0"#), "repetition_penalty"), | |
| 201 | + (simpleRequest(extra: #","repetition_context_size":0"#), "repetition_context_size"), | |
| 180 | 202 | ( |
| 181 | 203 | simpleRequest(extra: #","tools":[{"type":"web","function":{"name":"f"}}]"#), |
| 182 | 204 | "tools[0].type" |
| @@ -129,6 +129,24 @@ func simpleRequest(_ model: String = "org/m", content: String = "x", extra: Stri | |||
| 129 | #expect(generation.presencePenalty == 0.5 && generation.frequencyPenalty == -0.5) | 129 | #expect(generation.presencePenalty == 0.5 && generation.frequencyPenalty == -0.5) |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | + @Test func mlxSamplingExtensionsReachTheEngine() async throws { | ||
| 133 | + let engines = TestEngines() | ||
| 134 | + var settings = testSettings | ||
| 135 | + settings.config = ServerConfig( | ||
| 136 | + defaults: GenerationOverrides(topK: 20, minP: 0.05), | ||
| 137 | + locked: GenerationOverrides(repetitionContextSize: 64)) | ||
| 138 | + let extra = | ||
| 139 | + #","top_k":40,"repetition_penalty":1.1,"repetition_context_size":8"# | ||
| 140 | + try await withLiveServer(settings, engines: engines) { client in | ||
| 141 | + let response = try await post(client, simpleRequest(extra: extra)) | ||
| 142 | + #expect(response.status == .ok) | ||
| 143 | + } | ||
| 144 | + let generation = try #require(engines.fake.sessionSetups.first?.generation) | ||
| 145 | + #expect(generation.topK == 40 && generation.minP == 0.05) | ||
| 146 | + #expect(generation.repetitionPenalty == 1.1) | ||
| 147 | + #expect(generation.repetitionContextSize == 64) // locked | ||
| 148 | + } | ||
| 149 | + | ||
| 132 | @Test func stopSequencesCutTheAnswerWithoutLeaking() async throws { | 150 | @Test func stopSequencesCutTheAnswerWithoutLeaking() async throws { |
| 133 | let engines = TestEngines(script: [ | 151 | let engines = TestEngines(script: [ |
| 134 | [.text("Hello wo"), .text("rld EN"), .text("D and more")] | 152 | [.text("Hello wo"), .text("rld EN"), .text("D and more")] |
| @@ -177,6 +195,10 @@ func simpleRequest(_ model: String = "org/m", content: String = "x", extra: Stri | |||
| 177 | (simpleRequest(extra: #","top_p":"high""#), "top_p"), | 195 | (simpleRequest(extra: #","top_p":"high""#), "top_p"), |
| 178 | (simpleRequest(extra: #","max_tokens":0"#), "max_tokens"), | 196 | (simpleRequest(extra: #","max_tokens":0"#), "max_tokens"), |
| 179 | (simpleRequest(extra: #","n":2"#), "n"), | 197 | (simpleRequest(extra: #","n":2"#), "n"), |
| 198 | + (simpleRequest(extra: #","top_k":-1"#), "top_k"), | ||
| 199 | + (simpleRequest(extra: #","min_p":1.5"#), "min_p"), | ||
| 200 | + (simpleRequest(extra: #","repetition_penalty":0"#), "repetition_penalty"), | ||
| 201 | + (simpleRequest(extra: #","repetition_context_size":0"#), "repetition_context_size"), | ||
| 180 | ( | 202 | ( |
| 181 | simpleRequest(extra: #","tools":[{"type":"web","function":{"name":"f"}}]"#), | 203 | simpleRequest(extra: #","tools":[{"type":"web","function":{"name":"f"}}]"#), |
| 182 | "tools[0].type" | 204 | "tools[0].type" |
modified
docs/en/explanation/openai-compatibility.md +6 -0 | @@ -24,6 +24,11 @@ Local models do things OpenAI's API has no field for, mostly around reasoning. W | ||
| 24 | 24 | | Turn thinking on or off | `chat_template_kwargs.enable_thinking` | vLLM | |
| 25 | 25 | | Hide the reasoning | `include_reasoning: false` | OpenRouter | |
| 26 | 26 | | Count reasoning tokens | `usage.completion_tokens_details.reasoning_tokens` | OpenAI | |
| 27 | +| Sample among the k most likely tokens | `top_k` | vLLM, llama-server, Ollama, mlx-lm | | |
| 28 | +| Drop unlikely tokens relative to the best one | `min_p` | vLLM, llama-server, Ollama, mlx-lm | | |
| 29 | +| Discourage repeats | `repetition_penalty`, `repetition_context_size` | vLLM, llama-server, Ollama; mlx-lm for the window | | |
| 30 | + | |
| 31 | +The sampling extensions stop at what mlx-swift-lm implements. Other servers' samplers (`typical_p`, XTC, DRY, Mirostat…) and OpenAI's `logit_bias` have no implementation in it, so they are ignored like any unknown field rather than imitated. | |
| 27 | 32 | |
| 28 | 33 | Only `thinking_budget` is razorbill's own, because no common convention exists for a hard limit on reasoning tokens. `/v1/models` also adds `loaded` and `kind` to each model, which clients ignore. |
| 29 | 34 | |
| @@ -31,6 +36,7 @@ Only `thinking_budget` is razorbill's own, because no common convention exists f | ||
| 31 | 36 | |
| 32 | 37 | - **Defaults come from the server.** OpenAI's legacy completions default to 16 tokens; razorbill uses the server's configured `max_tokens`, because a local operator sets limits once for every client. |
| 33 | 38 | - **The prompt may change.** With `response_format`, the server adds an instruction carrying the schema to the system message (see [constrained decoding](constrained-decoding.md)). OpenAI's models are trained for structured output; local models need to be told. |
| 39 | +- **Penalties look at a window.** `presence_penalty` and `frequency_penalty` count the last 20 tokens, prompt included, as mlx-swift-lm does; OpenAI counts the whole answer. `repetition_penalty` works the same way, with a window set by `repetition_context_size`. | |
| 34 | 40 | - **Locked settings win.** An operator can impose `temperature` or cap `max_tokens` for every client, which OpenAI's API has no equivalent for. |
| 35 | 41 | |
| 36 | 42 | ## How compatibility is checked |
| @@ -24,6 +24,11 @@ Local models do things OpenAI's API has no field for, mostly around reasoning. W | |||
| 24 | | Turn thinking on or off | `chat_template_kwargs.enable_thinking` | vLLM | | 24 | | Turn thinking on or off | `chat_template_kwargs.enable_thinking` | vLLM | |
| 25 | | Hide the reasoning | `include_reasoning: false` | OpenRouter | | 25 | | Hide the reasoning | `include_reasoning: false` | OpenRouter | |
| 26 | | Count reasoning tokens | `usage.completion_tokens_details.reasoning_tokens` | OpenAI | | 26 | | Count reasoning tokens | `usage.completion_tokens_details.reasoning_tokens` | OpenAI | |
| 27 | +| Sample among the k most likely tokens | `top_k` | vLLM, llama-server, Ollama, mlx-lm | | ||
| 28 | +| Drop unlikely tokens relative to the best one | `min_p` | vLLM, llama-server, Ollama, mlx-lm | | ||
| 29 | +| Discourage repeats | `repetition_penalty`, `repetition_context_size` | vLLM, llama-server, Ollama; mlx-lm for the window | | ||
| 30 | + | ||
| 31 | +The sampling extensions stop at what mlx-swift-lm implements. Other servers' samplers (`typical_p`, XTC, DRY, Mirostat…) and OpenAI's `logit_bias` have no implementation in it, so they are ignored like any unknown field rather than imitated. | ||
| 27 | 32 | ||
| 28 | Only `thinking_budget` is razorbill's own, because no common convention exists for a hard limit on reasoning tokens. `/v1/models` also adds `loaded` and `kind` to each model, which clients ignore. | 33 | Only `thinking_budget` is razorbill's own, because no common convention exists for a hard limit on reasoning tokens. `/v1/models` also adds `loaded` and `kind` to each model, which clients ignore. |
| 29 | 34 | ||
| @@ -31,6 +36,7 @@ Only `thinking_budget` is razorbill's own, because no common convention exists f | |||
| 31 | 36 | ||
| 32 | - **Defaults come from the server.** OpenAI's legacy completions default to 16 tokens; razorbill uses the server's configured `max_tokens`, because a local operator sets limits once for every client. | 37 | - **Defaults come from the server.** OpenAI's legacy completions default to 16 tokens; razorbill uses the server's configured `max_tokens`, because a local operator sets limits once for every client. |
| 33 | - **The prompt may change.** With `response_format`, the server adds an instruction carrying the schema to the system message (see [constrained decoding](constrained-decoding.md)). OpenAI's models are trained for structured output; local models need to be told. | 38 | - **The prompt may change.** With `response_format`, the server adds an instruction carrying the schema to the system message (see [constrained decoding](constrained-decoding.md)). OpenAI's models are trained for structured output; local models need to be told. |
| 39 | +- **Penalties look at a window.** `presence_penalty` and `frequency_penalty` count the last 20 tokens, prompt included, as mlx-swift-lm does; OpenAI counts the whole answer. `repetition_penalty` works the same way, with a window set by `repetition_context_size`. | ||
| 34 | - **Locked settings win.** An operator can impose `temperature` or cap `max_tokens` for every client, which OpenAI's API has no equivalent for. | 40 | - **Locked settings win.** An operator can impose `temperature` or cap `max_tokens` for every client, which OpenAI's API has no equivalent for. |
| 35 | 41 | ||
| 36 | ## How compatibility is checked | 42 | ## How compatibility is checked |
modified
docs/en/reference/configuration.md +5 -0 | @@ -59,6 +59,10 @@ The same keys, in the top-level `defaults` / `locked` and in each model's `defau | ||
| 59 | 59 | | --- | --- | --- | --- | |
| 60 | 60 | | `temperature` | number, 0–2 | `0.6` | imposed | |
| 61 | 61 | | `top_p` | number, >0–1 | `1.0` | imposed | |
| 62 | +| `top_k` | integer ≥ 0 | `0` (off) | imposed | | |
| 63 | +| `min_p` | number, 0–1 | `0` (off) | imposed | | |
| 64 | +| `repetition_penalty` | number > 0 | none | imposed | | |
| 65 | +| `repetition_context_size` | integer ≥ 1 | `20` | imposed | | |
| 62 | 66 | | `max_tokens` | integer ≥ 1 | `1024` | ceiling (a smaller request is kept) | |
| 63 | 67 | | `thinking` | boolean | `false` | imposed | |
| 64 | 68 | | `thinking_budget` | integer ≥ 0, smaller than `max_tokens` of the same block | none (no limit) | ceiling | |
| @@ -66,6 +70,7 @@ The same keys, in the top-level `defaults` / `locked` and in each model's `defau | ||
| 66 | 70 | |
| 67 | 71 | - `thinking`: whether a reasoning model (Qwen3…) thinks before answering. Models that do not reason ignore it. |
| 68 | 72 | - `thinking_budget`: most tokens of reasoning; the model is then made to answer. Refused at request time (400) for models with no known reasoning protocol. |
| 73 | +- `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size`: the sampling settings mlx-swift-lm implements beyond OpenAI's, with the meaning given in the [HTTP API reference](http-api.md#request-fields). Some model cards recommend values (Qwen3: `top_k: 20`); they are not read from the model. | |
| 69 | 74 | - `show_reasoning`: send the reasoning to clients (`reasoning_content`). With `false`, the model still thinks and `reasoning_tokens` still counts it. |
| 70 | 75 | |
| 71 | 76 | The settings of a request are computed in this order, each step replacing the previous values it sets: built-in defaults → top-level `defaults` → the model's `defaults` → the request's fields → top-level `locked` → the model's `locked`. Models used by their Hugging Face id (not declared) get only the top-level blocks. |
| @@ -59,6 +59,10 @@ The same keys, in the top-level `defaults` / `locked` and in each model's `defau | |||
| 59 | | --- | --- | --- | --- | | 59 | | --- | --- | --- | --- | |
| 60 | | `temperature` | number, 0–2 | `0.6` | imposed | | 60 | | `temperature` | number, 0–2 | `0.6` | imposed | |
| 61 | | `top_p` | number, >0–1 | `1.0` | imposed | | 61 | | `top_p` | number, >0–1 | `1.0` | imposed | |
| 62 | +| `top_k` | integer ≥ 0 | `0` (off) | imposed | | ||
| 63 | +| `min_p` | number, 0–1 | `0` (off) | imposed | | ||
| 64 | +| `repetition_penalty` | number > 0 | none | imposed | | ||
| 65 | +| `repetition_context_size` | integer ≥ 1 | `20` | imposed | | ||
| 62 | | `max_tokens` | integer ≥ 1 | `1024` | ceiling (a smaller request is kept) | | 66 | | `max_tokens` | integer ≥ 1 | `1024` | ceiling (a smaller request is kept) | |
| 63 | | `thinking` | boolean | `false` | imposed | | 67 | | `thinking` | boolean | `false` | imposed | |
| 64 | | `thinking_budget` | integer ≥ 0, smaller than `max_tokens` of the same block | none (no limit) | ceiling | | 68 | | `thinking_budget` | integer ≥ 0, smaller than `max_tokens` of the same block | none (no limit) | ceiling | |
| @@ -66,6 +70,7 @@ The same keys, in the top-level `defaults` / `locked` and in each model's `defau | |||
| 66 | 70 | ||
| 67 | - `thinking`: whether a reasoning model (Qwen3…) thinks before answering. Models that do not reason ignore it. | 71 | - `thinking`: whether a reasoning model (Qwen3…) thinks before answering. Models that do not reason ignore it. |
| 68 | - `thinking_budget`: most tokens of reasoning; the model is then made to answer. Refused at request time (400) for models with no known reasoning protocol. | 72 | - `thinking_budget`: most tokens of reasoning; the model is then made to answer. Refused at request time (400) for models with no known reasoning protocol. |
| 73 | +- `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size`: the sampling settings mlx-swift-lm implements beyond OpenAI's, with the meaning given in the [HTTP API reference](http-api.md#request-fields). Some model cards recommend values (Qwen3: `top_k: 20`); they are not read from the model. | ||
| 69 | - `show_reasoning`: send the reasoning to clients (`reasoning_content`). With `false`, the model still thinks and `reasoning_tokens` still counts it. | 74 | - `show_reasoning`: send the reasoning to clients (`reasoning_content`). With `false`, the model still thinks and `reasoning_tokens` still counts it. |
| 70 | 75 | ||
| 71 | The settings of a request are computed in this order, each step replacing the previous values it sets: built-in defaults → top-level `defaults` → the model's `defaults` → the request's fields → top-level `locked` → the model's `locked`. Models used by their Hugging Face id (not declared) get only the top-level blocks. | 76 | The settings of a request are computed in this order, each step replacing the previous values it sets: built-in defaults → top-level `defaults` → the model's `defaults` → the request's fields → top-level `locked` → the model's `locked`. Models used by their Hugging Face id (not declared) get only the top-level blocks. |
modified
docs/en/reference/http-api.md +8 -4 | @@ -94,8 +94,12 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | ||
| 94 | 94 | | `max_completion_tokens` | integer ≥ 1 | — | Same as `max_tokens`; wins when both are sent | |
| 95 | 95 | | `stop` | string or array of ≤ 4 strings | none | The answer ends before the first occurrence; `finish_reason` is then `stop` | |
| 96 | 96 | | `seed` | integer | random | Sampler seed: same seed and settings, same answer | |
| 97 | -| `presence_penalty` | number, −2–2 | none | Penalises tokens already present | | |
| 98 | -| `frequency_penalty` | number, −2–2 | none | Penalises tokens by their frequency | | |
| 97 | +| `presence_penalty` | number, −2–2 | none | Penalises tokens present among the last 20 tokens (prompt included) | | |
| 98 | +| `frequency_penalty` | number, −2–2 | none | Penalises tokens by their frequency among the last 20 tokens (prompt included) | | |
| 99 | +| `top_k` | integer ≥ 0 | configuration, else `0` (off) | Extension (vLLM, llama-server, Ollama, mlx-lm): sample among the `top_k` most likely tokens only | | |
| 100 | +| `min_p` | number, 0–1 | configuration, else `0` (off) | Extension: drop tokens less likely than `min_p` × the most likely one | | |
| 101 | +| `repetition_penalty` | number > 0 | configuration, else none | Extension: divides the score of tokens seen in the last `repetition_context_size` tokens (prompt included); above 1 discourages repeats | | |
| 102 | +| `repetition_context_size` | integer ≥ 1 | configuration, else `20` | Extension (mlx-lm's name): how many recent tokens `repetition_penalty` looks at | | |
| 99 | 103 | | `stream` | boolean | `false` | Stream the answer as Server-Sent Events ([streaming](#streaming)) | |
| 100 | 104 | | `stream_options.include_usage` | boolean | `false` | Add a last chunk with `usage` | |
| 101 | 105 | | `response_format` | object | `{"type": "text"}` | `text`, `json_object` or `json_schema`; see [structured output](#structured-output) | |
| @@ -107,7 +111,7 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | ||
| 107 | 111 | | `thinking_budget` | integer ≥ 0 | configuration | razorbill extension: most tokens of reasoning before the model must answer | |
| 108 | 112 | | `include_reasoning` | boolean | configuration, else `true` | OpenRouter's switch: `false` leaves out `reasoning_content` (the model still thinks) | |
| 109 | 113 | |
| 110 | -The configuration's `locked` values win over the request: `temperature`, `top_p`, `thinking` and `show_reasoning` are imposed, `max_tokens` and `thinking_budget` are ceilings ([configuration reference](configuration.md#defaults-and-locked)). | |
| 114 | +The configuration's `locked` values win over the request: `temperature`, `top_p`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size`, `thinking` and `show_reasoning` are imposed, `max_tokens` and `thinking_budget` are ceilings ([configuration reference](configuration.md#defaults-and-locked)). | |
| 111 | 115 | |
| 112 | 116 | ### Refused fields |
| 113 | 117 | |
| @@ -242,7 +246,7 @@ curl -s http://127.0.0.1:8080/v1/completions \ | ||
| 242 | 246 | | `model` | string | required | A chat model ([model names](#model-names)) | |
| 243 | 247 | | `prompt` | string, or array of one string | required | The text to continue | |
| 244 | 248 | | `max_tokens` | integer ≥ 1 | configuration, else `1024` (OpenAI's default is 16) | Most tokens generated | |
| 245 | -| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty` | | | As for chat completions | | |
| 249 | +| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size` | | | As for chat completions | | |
| 246 | 250 | | `echo` | boolean | `false` | Put the prompt before the completion in `text` | |
| 247 | 251 | | `stream`, `stream_options.include_usage` | | `false` | As for chat completions | |
| 248 | 252 | |
| @@ -94,8 +94,12 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | |||
| 94 | | `max_completion_tokens` | integer ≥ 1 | — | Same as `max_tokens`; wins when both are sent | | 94 | | `max_completion_tokens` | integer ≥ 1 | — | Same as `max_tokens`; wins when both are sent | |
| 95 | | `stop` | string or array of ≤ 4 strings | none | The answer ends before the first occurrence; `finish_reason` is then `stop` | | 95 | | `stop` | string or array of ≤ 4 strings | none | The answer ends before the first occurrence; `finish_reason` is then `stop` | |
| 96 | | `seed` | integer | random | Sampler seed: same seed and settings, same answer | | 96 | | `seed` | integer | random | Sampler seed: same seed and settings, same answer | |
| 97 | -| `presence_penalty` | number, −2–2 | none | Penalises tokens already present | | 97 | +| `presence_penalty` | number, −2–2 | none | Penalises tokens present among the last 20 tokens (prompt included) | |
| 98 | -| `frequency_penalty` | number, −2–2 | none | Penalises tokens by their frequency | | 98 | +| `frequency_penalty` | number, −2–2 | none | Penalises tokens by their frequency among the last 20 tokens (prompt included) | |
| 99 | +| `top_k` | integer ≥ 0 | configuration, else `0` (off) | Extension (vLLM, llama-server, Ollama, mlx-lm): sample among the `top_k` most likely tokens only | | ||
| 100 | +| `min_p` | number, 0–1 | configuration, else `0` (off) | Extension: drop tokens less likely than `min_p` × the most likely one | | ||
| 101 | +| `repetition_penalty` | number > 0 | configuration, else none | Extension: divides the score of tokens seen in the last `repetition_context_size` tokens (prompt included); above 1 discourages repeats | | ||
| 102 | +| `repetition_context_size` | integer ≥ 1 | configuration, else `20` | Extension (mlx-lm's name): how many recent tokens `repetition_penalty` looks at | | ||
| 99 | | `stream` | boolean | `false` | Stream the answer as Server-Sent Events ([streaming](#streaming)) | | 103 | | `stream` | boolean | `false` | Stream the answer as Server-Sent Events ([streaming](#streaming)) | |
| 100 | | `stream_options.include_usage` | boolean | `false` | Add a last chunk with `usage` | | 104 | | `stream_options.include_usage` | boolean | `false` | Add a last chunk with `usage` | |
| 101 | | `response_format` | object | `{"type": "text"}` | `text`, `json_object` or `json_schema`; see [structured output](#structured-output) | | 105 | | `response_format` | object | `{"type": "text"}` | `text`, `json_object` or `json_schema`; see [structured output](#structured-output) | |
| @@ -107,7 +111,7 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | |||
| 107 | | `thinking_budget` | integer ≥ 0 | configuration | razorbill extension: most tokens of reasoning before the model must answer | | 111 | | `thinking_budget` | integer ≥ 0 | configuration | razorbill extension: most tokens of reasoning before the model must answer | |
| 108 | | `include_reasoning` | boolean | configuration, else `true` | OpenRouter's switch: `false` leaves out `reasoning_content` (the model still thinks) | | 112 | | `include_reasoning` | boolean | configuration, else `true` | OpenRouter's switch: `false` leaves out `reasoning_content` (the model still thinks) | |
| 109 | 113 | ||
| 110 | -The configuration's `locked` values win over the request: `temperature`, `top_p`, `thinking` and `show_reasoning` are imposed, `max_tokens` and `thinking_budget` are ceilings ([configuration reference](configuration.md#defaults-and-locked)). | 114 | +The configuration's `locked` values win over the request: `temperature`, `top_p`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size`, `thinking` and `show_reasoning` are imposed, `max_tokens` and `thinking_budget` are ceilings ([configuration reference](configuration.md#defaults-and-locked)). |
| 111 | 115 | ||
| 112 | ### Refused fields | 116 | ### Refused fields |
| 113 | 117 | ||
| @@ -242,7 +246,7 @@ curl -s http://127.0.0.1:8080/v1/completions \ | |||
| 242 | | `model` | string | required | A chat model ([model names](#model-names)) | | 246 | | `model` | string | required | A chat model ([model names](#model-names)) | |
| 243 | | `prompt` | string, or array of one string | required | The text to continue | | 247 | | `prompt` | string, or array of one string | required | The text to continue | |
| 244 | | `max_tokens` | integer ≥ 1 | configuration, else `1024` (OpenAI's default is 16) | Most tokens generated | | 248 | | `max_tokens` | integer ≥ 1 | configuration, else `1024` (OpenAI's default is 16) | Most tokens generated | |
| 245 | -| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty` | | | As for chat completions | | 249 | +| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size` | | | As for chat completions | |
| 246 | | `echo` | boolean | `false` | Put the prompt before the completion in `text` | | 250 | | `echo` | boolean | `false` | Put the prompt before the completion in `text` | |
| 247 | | `stream`, `stream_options.include_usage` | | `false` | As for chat completions | | 251 | | `stream`, `stream_options.include_usage` | | `false` | As for chat completions | |
| 248 | 252 | ||
modified
docs/fr/explanation/compatibilite-openai.md +6 -0 | @@ -24,6 +24,11 @@ Les modèles locaux font des choses pour lesquelles l'API d'OpenAI n'a pas de ch | ||
| 24 | 24 | | Activer ou couper la réflexion | `chat_template_kwargs.enable_thinking` | vLLM | |
| 25 | 25 | | Masquer le raisonnement | `include_reasoning: false` | OpenRouter | |
| 26 | 26 | | Compter les tokens de raisonnement | `usage.completion_tokens_details.reasoning_tokens` | OpenAI | |
| 27 | +| Tirer parmi les k tokens les plus probables | `top_k` | vLLM, llama-server, Ollama, mlx-lm | | |
| 28 | +| Écarter les tokens peu probables par rapport au meilleur | `min_p` | vLLM, llama-server, Ollama, mlx-lm | | |
| 29 | +| Décourager les répétitions | `repetition_penalty`, `repetition_context_size` | vLLM, llama-server, Ollama ; mlx-lm pour la fenêtre | | |
| 30 | + | |
| 31 | +Les extensions d'échantillonnage s'arrêtent à ce que mlx-swift-lm sait faire. Les autres méthodes des autres serveurs (`typical_p`, XTC, DRY, Mirostat…) et le `logit_bias` d'OpenAI n'y ont pas d'implémentation : ils sont ignorés comme tout champ inconnu plutôt qu'imités. | |
| 27 | 32 | |
| 28 | 33 | Seul `thinking_budget` est propre à razorbill, faute de convention commune pour une limite stricte des tokens de raisonnement. `/v1/models` ajoute aussi `loaded` et `kind` à chaque modèle, que les clients ignorent. |
| 29 | 34 | |
| @@ -31,6 +36,7 @@ Seul `thinking_budget` est propre à razorbill, faute de convention commune pour | ||
| 31 | 36 | |
| 32 | 37 | - **Les valeurs par défaut viennent du serveur.** Les complétions historiques d'OpenAI ont 16 tokens par défaut ; razorbill utilise le `max_tokens` configuré sur le serveur, parce qu'un opérateur local règle ses limites une fois pour tous les clients. |
| 33 | 38 | - **Le prompt peut changer.** Avec `response_format`, le serveur ajoute au message système une consigne contenant le schéma (voir [décodage contraint](decodage-contraint.md)). Les modèles d'OpenAI sont entraînés pour la sortie structurée ; les modèles locaux ont besoin qu'on le leur dise. |
| 39 | +- **Les pénalités regardent une fenêtre.** `presence_penalty` et `frequency_penalty` comptent les 20 derniers tokens, prompt compris, comme le fait mlx-swift-lm ; OpenAI compte toute la réponse. `repetition_penalty` fonctionne de la même façon, avec une fenêtre réglée par `repetition_context_size`. | |
| 34 | 40 | - **Les réglages verrouillés l'emportent.** Un opérateur peut imposer `temperature` ou plafonner `max_tokens` pour tous les clients, ce qui n'a pas d'équivalent dans l'API d'OpenAI. |
| 35 | 41 | |
| 36 | 42 | ## Comment la compatibilité est vérifiée |
| @@ -24,6 +24,11 @@ Les modèles locaux font des choses pour lesquelles l'API d'OpenAI n'a pas de ch | |||
| 24 | | Activer ou couper la réflexion | `chat_template_kwargs.enable_thinking` | vLLM | | 24 | | Activer ou couper la réflexion | `chat_template_kwargs.enable_thinking` | vLLM | |
| 25 | | Masquer le raisonnement | `include_reasoning: false` | OpenRouter | | 25 | | Masquer le raisonnement | `include_reasoning: false` | OpenRouter | |
| 26 | | Compter les tokens de raisonnement | `usage.completion_tokens_details.reasoning_tokens` | OpenAI | | 26 | | Compter les tokens de raisonnement | `usage.completion_tokens_details.reasoning_tokens` | OpenAI | |
| 27 | +| Tirer parmi les k tokens les plus probables | `top_k` | vLLM, llama-server, Ollama, mlx-lm | | ||
| 28 | +| Écarter les tokens peu probables par rapport au meilleur | `min_p` | vLLM, llama-server, Ollama, mlx-lm | | ||
| 29 | +| Décourager les répétitions | `repetition_penalty`, `repetition_context_size` | vLLM, llama-server, Ollama ; mlx-lm pour la fenêtre | | ||
| 30 | + | ||
| 31 | +Les extensions d'échantillonnage s'arrêtent à ce que mlx-swift-lm sait faire. Les autres méthodes des autres serveurs (`typical_p`, XTC, DRY, Mirostat…) et le `logit_bias` d'OpenAI n'y ont pas d'implémentation : ils sont ignorés comme tout champ inconnu plutôt qu'imités. | ||
| 27 | 32 | ||
| 28 | Seul `thinking_budget` est propre à razorbill, faute de convention commune pour une limite stricte des tokens de raisonnement. `/v1/models` ajoute aussi `loaded` et `kind` à chaque modèle, que les clients ignorent. | 33 | Seul `thinking_budget` est propre à razorbill, faute de convention commune pour une limite stricte des tokens de raisonnement. `/v1/models` ajoute aussi `loaded` et `kind` à chaque modèle, que les clients ignorent. |
| 29 | 34 | ||
| @@ -31,6 +36,7 @@ Seul `thinking_budget` est propre à razorbill, faute de convention commune pour | |||
| 31 | 36 | ||
| 32 | - **Les valeurs par défaut viennent du serveur.** Les complétions historiques d'OpenAI ont 16 tokens par défaut ; razorbill utilise le `max_tokens` configuré sur le serveur, parce qu'un opérateur local règle ses limites une fois pour tous les clients. | 37 | - **Les valeurs par défaut viennent du serveur.** Les complétions historiques d'OpenAI ont 16 tokens par défaut ; razorbill utilise le `max_tokens` configuré sur le serveur, parce qu'un opérateur local règle ses limites une fois pour tous les clients. |
| 33 | - **Le prompt peut changer.** Avec `response_format`, le serveur ajoute au message système une consigne contenant le schéma (voir [décodage contraint](decodage-contraint.md)). Les modèles d'OpenAI sont entraînés pour la sortie structurée ; les modèles locaux ont besoin qu'on le leur dise. | 38 | - **Le prompt peut changer.** Avec `response_format`, le serveur ajoute au message système une consigne contenant le schéma (voir [décodage contraint](decodage-contraint.md)). Les modèles d'OpenAI sont entraînés pour la sortie structurée ; les modèles locaux ont besoin qu'on le leur dise. |
| 39 | +- **Les pénalités regardent une fenêtre.** `presence_penalty` et `frequency_penalty` comptent les 20 derniers tokens, prompt compris, comme le fait mlx-swift-lm ; OpenAI compte toute la réponse. `repetition_penalty` fonctionne de la même façon, avec une fenêtre réglée par `repetition_context_size`. | ||
| 34 | - **Les réglages verrouillés l'emportent.** Un opérateur peut imposer `temperature` ou plafonner `max_tokens` pour tous les clients, ce qui n'a pas d'équivalent dans l'API d'OpenAI. | 40 | - **Les réglages verrouillés l'emportent.** Un opérateur peut imposer `temperature` ou plafonner `max_tokens` pour tous les clients, ce qui n'a pas d'équivalent dans l'API d'OpenAI. |
| 35 | 41 | ||
| 36 | ## Comment la compatibilité est vérifiée | 42 | ## Comment la compatibilité est vérifiée |
modified
docs/fr/reference/api-http.md +8 -4 | @@ -94,8 +94,12 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | ||
| 94 | 94 | | `max_completion_tokens` | entier ≥ 1 | — | Comme `max_tokens` ; l'emporte quand les deux sont envoyés | |
| 95 | 95 | | `stop` | chaîne ou tableau de ≤ 4 chaînes | aucun | La réponse s'arrête avant la première occurrence ; `finish_reason` vaut alors `stop` | |
| 96 | 96 | | `seed` | entier | aléatoire | Graine de l'échantillonneur : même graine et mêmes réglages, même réponse | |
| 97 | -| `presence_penalty` | nombre, −2–2 | aucune | Pénalise les tokens déjà présents | | |
| 98 | -| `frequency_penalty` | nombre, −2–2 | aucune | Pénalise les tokens selon leur fréquence | | |
| 97 | +| `presence_penalty` | nombre, −2–2 | aucune | Pénalise les tokens présents parmi les 20 derniers (prompt compris) | | |
| 98 | +| `frequency_penalty` | nombre, −2–2 | aucune | Pénalise les tokens selon leur fréquence parmi les 20 derniers (prompt compris) | | |
| 99 | +| `top_k` | entier ≥ 0 | configuration, sinon `0` (désactivé) | Extension (vLLM, llama-server, Ollama, mlx-lm) : tirer seulement parmi les `top_k` tokens les plus probables | | |
| 100 | +| `min_p` | nombre, 0–1 | configuration, sinon `0` (désactivé) | Extension : écarter les tokens moins probables que `min_p` × le plus probable | | |
| 101 | +| `repetition_penalty` | nombre > 0 | configuration, sinon aucune | Extension : divise le score des tokens vus parmi les `repetition_context_size` derniers (prompt compris) ; au-dessus de 1, décourage les répétitions | | |
| 102 | +| `repetition_context_size` | entier ≥ 1 | configuration, sinon `20` | Extension (nom de mlx-lm) : nombre de tokens récents examinés par `repetition_penalty` | | |
| 99 | 103 | | `stream` | booléen | `false` | Envoyer la réponse en Server-Sent Events ([streaming](#streaming)) | |
| 100 | 104 | | `stream_options.include_usage` | booléen | `false` | Ajouter un dernier morceau avec `usage` | |
| 101 | 105 | | `response_format` | objet | `{"type": "text"}` | `text`, `json_object` ou `json_schema` ; voir [sortie structurée](#sortie-structurée) | |
| @@ -107,7 +111,7 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | ||
| 107 | 111 | | `thinking_budget` | entier ≥ 0 | configuration | Extension razorbill : nombre maximal de tokens de raisonnement avant que le modèle doive répondre | |
| 108 | 112 | | `include_reasoning` | booléen | configuration, sinon `true` | L'interrupteur d'OpenRouter : `false` retire `reasoning_content` (le modèle réfléchit quand même) | |
| 109 | 113 | |
| 110 | -Les valeurs `locked` de la configuration l'emportent sur la requête : `temperature`, `top_p`, `thinking` et `show_reasoning` sont imposés, `max_tokens` et `thinking_budget` sont des plafonds ([référence de la configuration](configuration.md#defaults-et-locked)). | |
| 114 | +Les valeurs `locked` de la configuration l'emportent sur la requête : `temperature`, `top_p`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size`, `thinking` et `show_reasoning` sont imposés, `max_tokens` et `thinking_budget` sont des plafonds ([référence de la configuration](configuration.md#defaults-et-locked)). | |
| 111 | 115 | |
| 112 | 116 | ### Champs refusés |
| 113 | 117 | |
| @@ -242,7 +246,7 @@ curl -s http://127.0.0.1:8080/v1/completions \ | ||
| 242 | 246 | | `model` | chaîne | obligatoire | Un modèle de chat ([noms de modèles](#noms-de-modèles)) | |
| 243 | 247 | | `prompt` | chaîne, ou tableau d'une chaîne | obligatoire | Le texte à continuer | |
| 244 | 248 | | `max_tokens` | entier ≥ 1 | configuration, sinon `1024` (celui d'OpenAI est 16) | Nombre maximal de tokens générés | |
| 245 | -| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty` | | | Comme pour les complétions de chat | | |
| 249 | +| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size` | | | Comme pour les complétions de chat | | |
| 246 | 250 | | `echo` | booléen | `false` | Placer le prompt avant la complétion dans `text` | |
| 247 | 251 | | `stream`, `stream_options.include_usage` | | `false` | Comme pour les complétions de chat | |
| 248 | 252 | |
| @@ -94,8 +94,12 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | |||
| 94 | | `max_completion_tokens` | entier ≥ 1 | — | Comme `max_tokens` ; l'emporte quand les deux sont envoyés | | 94 | | `max_completion_tokens` | entier ≥ 1 | — | Comme `max_tokens` ; l'emporte quand les deux sont envoyés | |
| 95 | | `stop` | chaîne ou tableau de ≤ 4 chaînes | aucun | La réponse s'arrête avant la première occurrence ; `finish_reason` vaut alors `stop` | | 95 | | `stop` | chaîne ou tableau de ≤ 4 chaînes | aucun | La réponse s'arrête avant la première occurrence ; `finish_reason` vaut alors `stop` | |
| 96 | | `seed` | entier | aléatoire | Graine de l'échantillonneur : même graine et mêmes réglages, même réponse | | 96 | | `seed` | entier | aléatoire | Graine de l'échantillonneur : même graine et mêmes réglages, même réponse | |
| 97 | -| `presence_penalty` | nombre, −2–2 | aucune | Pénalise les tokens déjà présents | | 97 | +| `presence_penalty` | nombre, −2–2 | aucune | Pénalise les tokens présents parmi les 20 derniers (prompt compris) | |
| 98 | -| `frequency_penalty` | nombre, −2–2 | aucune | Pénalise les tokens selon leur fréquence | | 98 | +| `frequency_penalty` | nombre, −2–2 | aucune | Pénalise les tokens selon leur fréquence parmi les 20 derniers (prompt compris) | |
| 99 | +| `top_k` | entier ≥ 0 | configuration, sinon `0` (désactivé) | Extension (vLLM, llama-server, Ollama, mlx-lm) : tirer seulement parmi les `top_k` tokens les plus probables | | ||
| 100 | +| `min_p` | nombre, 0–1 | configuration, sinon `0` (désactivé) | Extension : écarter les tokens moins probables que `min_p` × le plus probable | | ||
| 101 | +| `repetition_penalty` | nombre > 0 | configuration, sinon aucune | Extension : divise le score des tokens vus parmi les `repetition_context_size` derniers (prompt compris) ; au-dessus de 1, décourage les répétitions | | ||
| 102 | +| `repetition_context_size` | entier ≥ 1 | configuration, sinon `20` | Extension (nom de mlx-lm) : nombre de tokens récents examinés par `repetition_penalty` | | ||
| 99 | | `stream` | booléen | `false` | Envoyer la réponse en Server-Sent Events ([streaming](#streaming)) | | 103 | | `stream` | booléen | `false` | Envoyer la réponse en Server-Sent Events ([streaming](#streaming)) | |
| 100 | | `stream_options.include_usage` | booléen | `false` | Ajouter un dernier morceau avec `usage` | | 104 | | `stream_options.include_usage` | booléen | `false` | Ajouter un dernier morceau avec `usage` | |
| 101 | | `response_format` | objet | `{"type": "text"}` | `text`, `json_object` ou `json_schema` ; voir [sortie structurée](#sortie-structurée) | | 105 | | `response_format` | objet | `{"type": "text"}` | `text`, `json_object` ou `json_schema` ; voir [sortie structurée](#sortie-structurée) | |
| @@ -107,7 +111,7 @@ curl -s http://127.0.0.1:8080/v1/chat/completions \ | |||
| 107 | | `thinking_budget` | entier ≥ 0 | configuration | Extension razorbill : nombre maximal de tokens de raisonnement avant que le modèle doive répondre | | 111 | | `thinking_budget` | entier ≥ 0 | configuration | Extension razorbill : nombre maximal de tokens de raisonnement avant que le modèle doive répondre | |
| 108 | | `include_reasoning` | booléen | configuration, sinon `true` | L'interrupteur d'OpenRouter : `false` retire `reasoning_content` (le modèle réfléchit quand même) | | 112 | | `include_reasoning` | booléen | configuration, sinon `true` | L'interrupteur d'OpenRouter : `false` retire `reasoning_content` (le modèle réfléchit quand même) | |
| 109 | 113 | ||
| 110 | -Les valeurs `locked` de la configuration l'emportent sur la requête : `temperature`, `top_p`, `thinking` et `show_reasoning` sont imposés, `max_tokens` et `thinking_budget` sont des plafonds ([référence de la configuration](configuration.md#defaults-et-locked)). | 114 | +Les valeurs `locked` de la configuration l'emportent sur la requête : `temperature`, `top_p`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size`, `thinking` et `show_reasoning` sont imposés, `max_tokens` et `thinking_budget` sont des plafonds ([référence de la configuration](configuration.md#defaults-et-locked)). |
| 111 | 115 | ||
| 112 | ### Champs refusés | 116 | ### Champs refusés |
| 113 | 117 | ||
| @@ -242,7 +246,7 @@ curl -s http://127.0.0.1:8080/v1/completions \ | |||
| 242 | | `model` | chaîne | obligatoire | Un modèle de chat ([noms de modèles](#noms-de-modèles)) | | 246 | | `model` | chaîne | obligatoire | Un modèle de chat ([noms de modèles](#noms-de-modèles)) | |
| 243 | | `prompt` | chaîne, ou tableau d'une chaîne | obligatoire | Le texte à continuer | | 247 | | `prompt` | chaîne, ou tableau d'une chaîne | obligatoire | Le texte à continuer | |
| 244 | | `max_tokens` | entier ≥ 1 | configuration, sinon `1024` (celui d'OpenAI est 16) | Nombre maximal de tokens générés | | 248 | | `max_tokens` | entier ≥ 1 | configuration, sinon `1024` (celui d'OpenAI est 16) | Nombre maximal de tokens générés | |
| 245 | -| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty` | | | Comme pour les complétions de chat | | 249 | +| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size` | | | Comme pour les complétions de chat | |
| 246 | | `echo` | booléen | `false` | Placer le prompt avant la complétion dans `text` | | 250 | | `echo` | booléen | `false` | Placer le prompt avant la complétion dans `text` | |
| 247 | | `stream`, `stream_options.include_usage` | | `false` | Comme pour les complétions de chat | | 251 | | `stream`, `stream_options.include_usage` | | `false` | Comme pour les complétions de chat | |
| 248 | 252 | ||
modified
docs/fr/reference/configuration.md +5 -0 | @@ -59,6 +59,10 @@ Les mêmes clés, dans les blocs `defaults` / `locked` de premier niveau et dans | ||
| 59 | 59 | | --- | --- | --- | --- | |
| 60 | 60 | | `temperature` | nombre, 0–2 | `0.6` | imposé | |
| 61 | 61 | | `top_p` | nombre, >0–1 | `1.0` | imposé | |
| 62 | +| `top_k` | entier ≥ 0 | `0` (désactivé) | imposé | | |
| 63 | +| `min_p` | nombre, 0–1 | `0` (désactivé) | imposé | | |
| 64 | +| `repetition_penalty` | nombre > 0 | aucune | imposé | | |
| 65 | +| `repetition_context_size` | entier ≥ 1 | `20` | imposé | | |
| 62 | 66 | | `max_tokens` | entier ≥ 1 | `1024` | plafond (une demande plus petite est gardée) | |
| 63 | 67 | | `thinking` | booléen | `false` | imposé | |
| 64 | 68 | | `thinking_budget` | entier ≥ 0, inférieur au `max_tokens` du même bloc | aucun (pas de limite) | plafond | |
| @@ -66,6 +70,7 @@ Les mêmes clés, dans les blocs `defaults` / `locked` de premier niveau et dans | ||
| 66 | 70 | |
| 67 | 71 | - `thinking` : si un modèle qui raisonne (Qwen3…) réfléchit avant de répondre. Les modèles qui ne raisonnent pas l'ignorent. |
| 68 | 72 | - `thinking_budget` : nombre maximal de tokens de raisonnement ; le modèle est ensuite obligé de répondre. Refusé à la requête (400) pour les modèles sans protocole de raisonnement connu. |
| 73 | +- `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size` : les réglages d'échantillonnage que mlx-swift-lm sait faire en plus de ceux d'OpenAI, avec le sens donné dans la [référence de l'API HTTP](api-http.md#champs-de-la-requête). Certaines fiches de modèles recommandent des valeurs (Qwen3 : `top_k: 20`) ; elles ne sont pas lues dans le modèle. | |
| 69 | 74 | - `show_reasoning` : envoyer le raisonnement aux clients (`reasoning_content`). Avec `false`, le modèle réfléchit quand même et `reasoning_tokens` le compte toujours. |
| 70 | 75 | |
| 71 | 76 | Les réglages d'une requête sont calculés dans cet ordre, chaque étape remplaçant les valeurs qu'elle définit : défauts intégrés → `defaults` de premier niveau → `defaults` du modèle → champs de la requête → `locked` de premier niveau → `locked` du modèle. Les modèles utilisés par leur identifiant Hugging Face (non déclarés) ne reçoivent que les blocs de premier niveau. |
| @@ -59,6 +59,10 @@ Les mêmes clés, dans les blocs `defaults` / `locked` de premier niveau et dans | |||
| 59 | | --- | --- | --- | --- | | 59 | | --- | --- | --- | --- | |
| 60 | | `temperature` | nombre, 0–2 | `0.6` | imposé | | 60 | | `temperature` | nombre, 0–2 | `0.6` | imposé | |
| 61 | | `top_p` | nombre, >0–1 | `1.0` | imposé | | 61 | | `top_p` | nombre, >0–1 | `1.0` | imposé | |
| 62 | +| `top_k` | entier ≥ 0 | `0` (désactivé) | imposé | | ||
| 63 | +| `min_p` | nombre, 0–1 | `0` (désactivé) | imposé | | ||
| 64 | +| `repetition_penalty` | nombre > 0 | aucune | imposé | | ||
| 65 | +| `repetition_context_size` | entier ≥ 1 | `20` | imposé | | ||
| 62 | | `max_tokens` | entier ≥ 1 | `1024` | plafond (une demande plus petite est gardée) | | 66 | | `max_tokens` | entier ≥ 1 | `1024` | plafond (une demande plus petite est gardée) | |
| 63 | | `thinking` | booléen | `false` | imposé | | 67 | | `thinking` | booléen | `false` | imposé | |
| 64 | | `thinking_budget` | entier ≥ 0, inférieur au `max_tokens` du même bloc | aucun (pas de limite) | plafond | | 68 | | `thinking_budget` | entier ≥ 0, inférieur au `max_tokens` du même bloc | aucun (pas de limite) | plafond | |
| @@ -66,6 +70,7 @@ Les mêmes clés, dans les blocs `defaults` / `locked` de premier niveau et dans | |||
| 66 | 70 | ||
| 67 | - `thinking` : si un modèle qui raisonne (Qwen3…) réfléchit avant de répondre. Les modèles qui ne raisonnent pas l'ignorent. | 71 | - `thinking` : si un modèle qui raisonne (Qwen3…) réfléchit avant de répondre. Les modèles qui ne raisonnent pas l'ignorent. |
| 68 | - `thinking_budget` : nombre maximal de tokens de raisonnement ; le modèle est ensuite obligé de répondre. Refusé à la requête (400) pour les modèles sans protocole de raisonnement connu. | 72 | - `thinking_budget` : nombre maximal de tokens de raisonnement ; le modèle est ensuite obligé de répondre. Refusé à la requête (400) pour les modèles sans protocole de raisonnement connu. |
| 73 | +- `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size` : les réglages d'échantillonnage que mlx-swift-lm sait faire en plus de ceux d'OpenAI, avec le sens donné dans la [référence de l'API HTTP](api-http.md#champs-de-la-requête). Certaines fiches de modèles recommandent des valeurs (Qwen3 : `top_k: 20`) ; elles ne sont pas lues dans le modèle. | ||
| 69 | - `show_reasoning` : envoyer le raisonnement aux clients (`reasoning_content`). Avec `false`, le modèle réfléchit quand même et `reasoning_tokens` le compte toujours. | 74 | - `show_reasoning` : envoyer le raisonnement aux clients (`reasoning_content`). Avec `false`, le modèle réfléchit quand même et `reasoning_tokens` le compte toujours. |
| 70 | 75 | ||
| 71 | Les réglages d'une requête sont calculés dans cet ordre, chaque étape remplaçant les valeurs qu'elle définit : défauts intégrés → `defaults` de premier niveau → `defaults` du modèle → champs de la requête → `locked` de premier niveau → `locked` du modèle. Les modèles utilisés par leur identifiant Hugging Face (non déclarés) ne reçoivent que les blocs de premier niveau. | 76 | Les réglages d'une requête sont calculés dans cet ordre, chaque étape remplaçant les valeurs qu'elle définit : défauts intégrés → `defaults` de premier niveau → `defaults` du modèle → champs de la requête → `locked` de premier niveau → `locked` du modèle. Les modèles utilisés par leur identifiant Hugging Face (non déclarés) ne reçoivent que les blocs de premier niveau. |
modified
examples/server.yaml +4 -3 | @@ -14,8 +14,9 @@ defaults: | ||
| 14 | 14 | max_tokens: 2048 |
| 15 | 15 | |
| 16 | 16 | # Settings clients cannot change. Nothing is locked unless listed here (or under a model). |
| 17 | -# temperature, top_p, thinking and show_reasoning are imposed; max_tokens and thinking_budget are | |
| 18 | -# ceilings. Keys: temperature, top_p, max_tokens, thinking, thinking_budget, show_reasoning. | |
| 17 | +# max_tokens and thinking_budget are ceilings; every other key is imposed. Keys: temperature, | |
| 18 | +# top_p, top_k, min_p, repetition_penalty, repetition_context_size, max_tokens, thinking, | |
| 19 | +# thinking_budget, show_reasoning. | |
| 19 | 20 | locked: |
| 20 | 21 | max_tokens: 8192 |
| 21 | 22 | # show_reasoning: false # never send the models' reasoning (they still think) |
| @@ -27,7 +28,7 @@ models: | ||
| 27 | 28 | # revision: main |
| 28 | 29 | kind: chat # chat | embedding |
| 29 | 30 | preload: false |
| 30 | - defaults: { thinking: true, thinking_budget: 512 } | |
| 31 | + defaults: { thinking: true, thinking_budget: 512, top_k: 20 } # top_k: Qwen3's advice | |
| 31 | 32 | locked: { max_tokens: 4096 } |
| 32 | 33 | # - id: embed # for /v1/embeddings |
| 33 | 34 | # source: BAAI/bge-small-en-v1.5 |
| @@ -14,8 +14,9 @@ defaults: | |||
| 14 | max_tokens: 2048 | 14 | max_tokens: 2048 |
| 15 | 15 | ||
| 16 | # Settings clients cannot change. Nothing is locked unless listed here (or under a model). | 16 | # Settings clients cannot change. Nothing is locked unless listed here (or under a model). |
| 17 | -# temperature, top_p, thinking and show_reasoning are imposed; max_tokens and thinking_budget are | 17 | +# max_tokens and thinking_budget are ceilings; every other key is imposed. Keys: temperature, |
| 18 | -# ceilings. Keys: temperature, top_p, max_tokens, thinking, thinking_budget, show_reasoning. | 18 | +# top_p, top_k, min_p, repetition_penalty, repetition_context_size, max_tokens, thinking, |
| 19 | +# thinking_budget, show_reasoning. | ||
| 19 | locked: | 20 | locked: |
| 20 | max_tokens: 8192 | 21 | max_tokens: 8192 |
| 21 | # show_reasoning: false # never send the models' reasoning (they still think) | 22 | # show_reasoning: false # never send the models' reasoning (they still think) |
| @@ -27,7 +28,7 @@ models: | |||
| 27 | # revision: main | 28 | # revision: main |
| 28 | kind: chat # chat | embedding | 29 | kind: chat # chat | embedding |
| 29 | preload: false | 30 | preload: false |
| 30 | - defaults: { thinking: true, thinking_budget: 512 } | 31 | + defaults: { thinking: true, thinking_budget: 512, top_k: 20 } # top_k: Qwen3's advice |
| 31 | locked: { max_tokens: 4096 } | 32 | locked: { max_tokens: 4096 } |
| 32 | # - id: embed # for /v1/embeddings | 33 | # - id: embed # for /v1/embeddings |
| 33 | # source: BAAI/bge-small-en-v1.5 | 34 | # source: BAAI/bge-small-en-v1.5 |