bots-garden/razorbillpublic Fork
⑂ f95af71
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/razorbill.git
git clone ssh://git@rickub.com/bots-garden/razorbill.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

demos/test-qwen: stream from rzb serve and measure the generation speed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
k33g committed 2026-11-26T15:05:19+01:00 Browse files
f95af71 parent: 83271da
modified .memory/history.md +8 -0
@@ -366,3 +366,11 @@ User agreed to both changes: default port 7920 (code, tests, example config, doc
366366 suite defaults, ticket #54; compat.sh's own 18080 unchanged) and a hint in the 404 message on `/`,
367367 `/v1`, `/v1/` (status and code unchanged). Included in 0.2.0: local tag moved again. Tests Linux
368368 173, compat Linux 51/20, gate PASS, links OK. Mac tests not re-run (server code is not MLX).
369+
370+## 2026-11-26 — demos/test-qwen
371+
372+User runs `rzb serve --host 0.0.0.0` and wants to test mlx-community/Qwen3.5-9B-MLX-4bit: added
373+`demos/test-qwen/test_qwen.py` (uv inline script, openai lib, streaming with include_usage,
374+reasoning dimmed, TTFT / time to answer / decode tokens/s / overall throughput / cached tokens,
375+--no-think, --runs) and its README; listed in the root README. Tested on Linux against a
376+fake-engine `rzb serve` (2 runs + unreachable server message); not run against the real model.
@@ -366,3 +366,11 @@ User agreed to both changes: default port 7920 (code, tests, example config, doc
366 suite defaults, ticket #54; compat.sh's own 18080 unchanged) and a hint in the 404 message on `/`,366 suite defaults, ticket #54; compat.sh's own 18080 unchanged) and a hint in the 404 message on `/`,
367 `/v1`, `/v1/` (status and code unchanged). Included in 0.2.0: local tag moved again. Tests Linux367 `/v1`, `/v1/` (status and code unchanged). Included in 0.2.0: local tag moved again. Tests Linux
368 173, compat Linux 51/20, gate PASS, links OK. Mac tests not re-run (server code is not MLX).368 173, compat Linux 51/20, gate PASS, links OK. Mac tests not re-run (server code is not MLX).
369+
370+## 2026-11-26 — demos/test-qwen
371+
372+User runs `rzb serve --host 0.0.0.0` and wants to test mlx-community/Qwen3.5-9B-MLX-4bit: added
373+`demos/test-qwen/test_qwen.py` (uv inline script, openai lib, streaming with include_usage,
374+reasoning dimmed, TTFT / time to answer / decode tokens/s / overall throughput / cached tokens,
375+--no-think, --runs) and its README; listed in the root README. Tested on Linux against a
376+fake-engine `rzb serve` (2 runs + unreachable server message); not run against the real model.
modified .quality/history.jsonl +1 -0
@@ -30,3 +30,4 @@
3030 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "a218748", "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": 30, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T05:21:18Z"}
3131 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "fe0695f", "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": 31, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T07:11:39Z"}
3232 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6e6d79e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 547, "cyclo": 605, "fields": 1210, "funcs": 583, "lcom": 115, "lines": 10687, "loc": 8507}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 32, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T07:29:39Z"}
33+{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "83271da", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 547, "cyclo": 605, "fields": 1210, "funcs": 583, "lcom": 115, "lines": 10687, "loc": 8507}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 33, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T14:05:13Z"}
@@ -30,3 +30,4 @@
30 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "a218748", "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": 30, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T05:21:18Z"}30 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "a218748", "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": 30, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T05:21:18Z"}
31 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "fe0695f", "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": 31, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T07:11:39Z"}31 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "fe0695f", "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": 31, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T07:11:39Z"}
32 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6e6d79e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 547, "cyclo": 605, "fields": 1210, "funcs": 583, "lcom": 115, "lines": 10687, "loc": 8507}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 32, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T07:29:39Z"}32 {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6e6d79e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 547, "cyclo": 605, "fields": 1210, "funcs": 583, "lcom": 115, "lines": 10687, "loc": 8507}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 32, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T07:29:39Z"}
33+{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "83271da", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 234, "complex": 547, "cyclo": 605, "fields": 1210, "funcs": 583, "lcom": 115, "lines": 10687, "loc": 8507}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 33, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-26T14:05:13Z"}
added .quality/report-20261126T140513Z.md +73 -0
new file mode 100644
@@ -0,0 +1,73 @@
1+# Quality report — 2026-11-26T14:05:13Z
2+
3+- **Gate**: ✅ **PASS**
4+- **Commit**: `83271da` 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**: #33 (previous: 2026-11-26T07:29:39Z)
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 | 583 | ±0 |
32+| classes | 234 | ±0 |
33+| fields | 1210 | ±0 |
34+| cyclo | 605 | ±0 |
35+| complex | 547 | ±0 |
36+| lcom | 115 | ±0 |
37+| lines | 10687 | ±0 |
38+| loc | 8507 | ±0 |
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+| experiments/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+| 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL |
65+| 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL |
66+| 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS |
67+| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS |
68+| 28 | 2026-11-25T22:03:59Z | 0 | 0 | 0 | 546 | PASS |
69+| 29 | 2026-11-26T04:34:58Z | 0 | 0 | 0 | 546 | PASS |
70+| 30 | 2026-11-26T05:21:18Z | 0 | 0 | 0 | 546 | PASS |
71+| 31 | 2026-11-26T07:11:39Z | 0 | 0 | 0 | 546 | PASS |
72+| 32 | 2026-11-26T07:29:39Z | 0 | 0 | 0 | 547 | PASS |
73+| 33 | 2026-11-26T14:05:13Z | 0 | 0 | 0 | 547 | PASS |
new file mode 100644
@@ -0,0 +1,73 @@
1+# Quality report — 2026-11-26T14:05:13Z
2+
3+- **Gate**: ✅ **PASS**
4+- **Commit**: `83271da` 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**: #33 (previous: 2026-11-26T07:29:39Z)
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 | 583 | ±0 |
32+| classes | 234 | ±0 |
33+| fields | 1210 | ±0 |
34+| cyclo | 605 | ±0 |
35+| complex | 547 | ±0 |
36+| lcom | 115 | ±0 |
37+| lines | 10687 | ±0 |
38+| loc | 8507 | ±0 |
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+| experiments/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+| 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL |
65+| 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL |
66+| 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS |
67+| 27 | 2026-11-25T22:01:44Z | 0 | 0 | 0 | 546 | PASS |
68+| 28 | 2026-11-25T22:03:59Z | 0 | 0 | 0 | 546 | PASS |
69+| 29 | 2026-11-26T04:34:58Z | 0 | 0 | 0 | 546 | PASS |
70+| 30 | 2026-11-26T05:21:18Z | 0 | 0 | 0 | 546 | PASS |
71+| 31 | 2026-11-26T07:11:39Z | 0 | 0 | 0 | 546 | PASS |
72+| 32 | 2026-11-26T07:29:39Z | 0 | 0 | 0 | 547 | PASS |
73+| 33 | 2026-11-26T14:05:13Z | 0 | 0 | 0 | 547 | PASS |
modified .quality/report-latest.md +10 -10
@@ -1,10 +1,10 @@
1-# Quality report — 2026-11-26T07:29:39Z
1+# Quality report — 2026-11-26T14:05:13Z
22
33 - **Gate**: ✅ **PASS**
4-- **Commit**: `6e6d79e` on `feature/v0.2-openai-server`
4+- **Commit**: `83271da` on `feature/v0.2-openai-server`
55 - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)
66 - **swiftlint**: 0.65.1 (run directly, merged into lint issues)
7-- **Run**: #32 (previous: 2026-11-26T07:11:39Z)
7+- **Run**: #33 (previous: 2026-11-26T07:29:39Z)
88
99 ## Lint issues (`qlty check`)
1010
@@ -28,14 +28,14 @@ _none_
2828
2929 | metric | total | vs previous |
3030 |---|---|---|
31-| funcs | 583 | +1 |
31+| funcs | 583 | ±0 |
3232 | classes | 234 | ±0 |
33-| fields | 1210 | +1 |
34-| cyclo | 605 | +1 |
35-| complex | 547 | +1 |
33+| fields | 1210 | ±0 |
34+| cyclo | 605 | ±0 |
35+| complex | 547 | ±0 |
3636 | lcom | 115 | ±0 |
37-| lines | 10687 | +18 |
38-| loc | 8507 | +15 |
37+| lines | 10687 | ±0 |
38+| loc | 8507 | ±0 |
3939
4040 ### Most complex files
4141
@@ -61,7 +61,6 @@ _none_
6161
6262 | run | timestamp | error | warning | smells | complex | gate |
6363 |---|---|---|---|---|---|---|
64-| 23 | 2026-11-25T21:28:10Z | 0 | 0 | 0 | 538 | PASS |
6564 | 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL |
6665 | 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL |
6766 | 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS |
@@ -71,3 +70,4 @@ _none_
7170 | 30 | 2026-11-26T05:21:18Z | 0 | 0 | 0 | 546 | PASS |
7271 | 31 | 2026-11-26T07:11:39Z | 0 | 0 | 0 | 546 | PASS |
7372 | 32 | 2026-11-26T07:29:39Z | 0 | 0 | 0 | 547 | PASS |
73+| 33 | 2026-11-26T14:05:13Z | 0 | 0 | 0 | 547 | PASS |
@@ -1,10 +1,10 @@
1-# Quality report — 2026-11-26T07:29:39Z1+# Quality report — 2026-11-26T14:05:13Z
2 2
3 - **Gate**: ✅ **PASS**3 - **Gate**: ✅ **PASS**
4-- **Commit**: `6e6d79e` on `feature/v0.2-openai-server`4+- **Commit**: `83271da` 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**: #32 (previous: 2026-11-26T07:11:39Z)7+- **Run**: #33 (previous: 2026-11-26T07:29:39Z)
8 8
9 ## Lint issues (`qlty check`)9 ## Lint issues (`qlty check`)
10 10
@@ -28,14 +28,14 @@ _none_
28 28
29 | metric | total | vs previous |29 | metric | total | vs previous |
30 |---|---|---|30 |---|---|---|
31-| funcs | 583 | +1 |31+| funcs | 583 | ±0 |
32 | classes | 234 | ±0 |32 | classes | 234 | ±0 |
33-| fields | 1210 | +1 |33+| fields | 1210 | ±0 |
34-| cyclo | 605 | +1 |34+| cyclo | 605 | ±0 |
35-| complex | 547 | +1 |35+| complex | 547 | ±0 |
36 | lcom | 115 | ±0 |36 | lcom | 115 | ±0 |
37-| lines | 10687 | +18 |37+| lines | 10687 | ±0 |
38-| loc | 8507 | +15 |38+| loc | 8507 | ±0 |
39 39
40 ### Most complex files40 ### Most complex files
41 41
@@ -61,7 +61,6 @@ _none_
61 61
62 | run | timestamp | error | warning | smells | complex | gate |62 | run | timestamp | error | warning | smells | complex | gate |
63 |---|---|---|---|---|---|---|63 |---|---|---|---|---|---|---|
64-| 23 | 2026-11-25T21:28:10Z | 0 | 0 | 0 | 538 | PASS |
65 | 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL |64 | 24 | 2026-11-25T21:37:24Z | 0 | 1 | 1 | 559 | FAIL |
66 | 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL |65 | 25 | 2026-11-25T21:37:51Z | 0 | 1 | 0 | 544 | FAIL |
67 | 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS |66 | 26 | 2026-11-25T21:38:24Z | 0 | 0 | 0 | 544 | PASS |
@@ -71,3 +70,4 @@ _none_
71 | 30 | 2026-11-26T05:21:18Z | 0 | 0 | 0 | 546 | PASS |70 | 30 | 2026-11-26T05:21:18Z | 0 | 0 | 0 | 546 | PASS |
72 | 31 | 2026-11-26T07:11:39Z | 0 | 0 | 0 | 546 | PASS |71 | 31 | 2026-11-26T07:11:39Z | 0 | 0 | 0 | 546 | PASS |
73 | 32 | 2026-11-26T07:29:39Z | 0 | 0 | 0 | 547 | PASS |72 | 32 | 2026-11-26T07:29:39Z | 0 | 0 | 0 | 547 | PASS |
73+| 33 | 2026-11-26T14:05:13Z | 0 | 0 | 0 | 547 | PASS |
modified README.md +1 -0
@@ -128,6 +128,7 @@ Step by step: [Develop from a Linux sandbox](docs/en/how-to/develop-from-a-sandb
128128 | `Sources/rzb` | The executable: registers the engines and starts the command line. |
129129 | `Tests/` | Unit tests (Swift Testing); `Tests/Compatibility`: the OpenAI compatibility suite (pytest). |
130130 | `examples/server.yaml` | Commented server configuration. |
131+| `demos/test-qwen` | Python script: streams one answer from `rzb serve` and measures the generation speed. |
131132 | `experiments/01-query-model` | Development experiment, standalone package: sends one prompt to one MLX model with mlx-swift-lm, no server; first check of MLX on the Mac (#1). |
132133 | `experiments/02-kv-cache-reuse` | Development experiment, standalone package: measures KV-cache reuse between stateless requests (#47), which led to the server's prompt cache (#48). |
133134 | `tools/host-runner` | Build, test and run on the Mac from the sandbox. |
@@ -128,6 +128,7 @@ Step by step: [Develop from a Linux sandbox](docs/en/how-to/develop-from-a-sandb
128 | `Sources/rzb` | The executable: registers the engines and starts the command line. |128 | `Sources/rzb` | The executable: registers the engines and starts the command line. |
129 | `Tests/` | Unit tests (Swift Testing); `Tests/Compatibility`: the OpenAI compatibility suite (pytest). |129 | `Tests/` | Unit tests (Swift Testing); `Tests/Compatibility`: the OpenAI compatibility suite (pytest). |
130 | `examples/server.yaml` | Commented server configuration. |130 | `examples/server.yaml` | Commented server configuration. |
131+| `demos/test-qwen` | Python script: streams one answer from `rzb serve` and measures the generation speed. |
131 | `experiments/01-query-model` | Development experiment, standalone package: sends one prompt to one MLX model with mlx-swift-lm, no server; first check of MLX on the Mac (#1). |132 | `experiments/01-query-model` | Development experiment, standalone package: sends one prompt to one MLX model with mlx-swift-lm, no server; first check of MLX on the Mac (#1). |
132 | `experiments/02-kv-cache-reuse` | Development experiment, standalone package: measures KV-cache reuse between stateless requests (#47), which led to the server's prompt cache (#48). |133 | `experiments/02-kv-cache-reuse` | Development experiment, standalone package: measures KV-cache reuse between stateless requests (#47), which led to the server's prompt cache (#48). |
133 | `tools/host-runner` | Build, test and run on the Mac from the sandbox. |134 | `tools/host-runner` | Build, test and run on the Mac from the sandbox. |
added demos/test-qwen/README.md +59 -0
new file mode 100644
@@ -0,0 +1,59 @@
1+# Demo — test Qwen3.5-9B through rzb serve
2+
3+`test_qwen.py` sends one chat request to a running `rzb serve`, streams the answer (reasoning dimmed, then the answer) and measures the speed from the server's token counts.
4+
5+## Run
6+
7+1. Download the model once (about 5 GB), so that the first request does not wait for it:
8+
9+ ```bash
10+ rzb models pull mlx-community/Qwen3.5-9B-MLX-4bit
11+ ```
12+
13+2. Start the server in a terminal (`--host 0.0.0.0` is only needed to reach it from another machine):
14+
15+ ```bash
16+ rzb serve
17+ ```
18+
19+3. In another terminal, from the repository root:
20+
21+ ```bash
22+ uv run demos/test-qwen/test_qwen.py
23+ ```
24+
25+ [`uv`](https://docs.astral.sh/uv/) installs the `openai` library declared at the top of the script. Without `uv`: `pip install openai`, then `python3 demos/test-qwen/test_qwen.py`.
26+
27+## Options
28+
29+| Option | Default | Meaning |
30+| --- | --- | --- |
31+| `--url` | `$RZB_URL`, else `http://127.0.0.1:7920/v1` | Base URL of the server; from another machine, the Mac's address (`http://192.168.1.20:7920/v1`), never `0.0.0.0` |
32+| `--model` | `mlx-community/Qwen3.5-9B-MLX-4bit` | Any model the server can load |
33+| `--prompt`, `--system` | a short poem | The messages sent |
34+| `--max-tokens` | 1024 | Upper bound, reasoning included |
35+| `--temperature` | 0.7 | |
36+| `--no-think` | off | Turns the reasoning off (`chat_template_kwargs.enable_thinking: false`) |
37+| `--hide-reasoning` | off | Does not print the reasoning; it is still generated and counted |
38+| `--runs` | 1 | Sends the request several times: the first run includes the model loading |
39+
40+The API key, when the server has one, is read from `$RZB_API_KEY`.
41+
42+## Reading the numbers
43+
44+```
45+prompt tokens 27 (reused from the cache: 0)
46+completion tokens 412 (reasoning: 301, answer: 111)
47+time to first token 1.84 s (prompt processing, + model loading on the first call)
48+time to answer 10.95 s (first token after the reasoning)
49+total time 14.40 s
50+generation speed 32.0 tokens/s
51+overall throughput 28.6 tokens/s (first token wait included)
52+```
53+
54+(Illustrative values.)
55+
56+- **Generation speed** is the decoding speed: tokens after the first one, divided by the time since the first one. This is the figure to compare between models.
57+- **Time to first token** covers the prompt processing; on the first run it also covers loading the model into memory (several seconds for a 9B model).
58+- Reasoning tokens are tokens too: a thinking model takes longer to start its answer, not to generate each token. Compare with `--no-think`.
59+- With `--runs 2` or more, **reused from the cache** shows the prompt tokens the server did not have to recompute ([prompt cache](../../docs/en/explanation/model-lifecycle.md#reusing-the-previous-prompt)).
new file mode 100644
@@ -0,0 +1,59 @@
1+# Demo — test Qwen3.5-9B through rzb serve
2+
3+`test_qwen.py` sends one chat request to a running `rzb serve`, streams the answer (reasoning dimmed, then the answer) and measures the speed from the server's token counts.
4+
5+## Run
6+
7+1. Download the model once (about 5 GB), so that the first request does not wait for it:
8+
9+ ```bash
10+ rzb models pull mlx-community/Qwen3.5-9B-MLX-4bit
11+ ```
12+
13+2. Start the server in a terminal (`--host 0.0.0.0` is only needed to reach it from another machine):
14+
15+ ```bash
16+ rzb serve
17+ ```
18+
19+3. In another terminal, from the repository root:
20+
21+ ```bash
22+ uv run demos/test-qwen/test_qwen.py
23+ ```
24+
25+ [`uv`](https://docs.astral.sh/uv/) installs the `openai` library declared at the top of the script. Without `uv`: `pip install openai`, then `python3 demos/test-qwen/test_qwen.py`.
26+
27+## Options
28+
29+| Option | Default | Meaning |
30+| --- | --- | --- |
31+| `--url` | `$RZB_URL`, else `http://127.0.0.1:7920/v1` | Base URL of the server; from another machine, the Mac's address (`http://192.168.1.20:7920/v1`), never `0.0.0.0` |
32+| `--model` | `mlx-community/Qwen3.5-9B-MLX-4bit` | Any model the server can load |
33+| `--prompt`, `--system` | a short poem | The messages sent |
34+| `--max-tokens` | 1024 | Upper bound, reasoning included |
35+| `--temperature` | 0.7 | |
36+| `--no-think` | off | Turns the reasoning off (`chat_template_kwargs.enable_thinking: false`) |
37+| `--hide-reasoning` | off | Does not print the reasoning; it is still generated and counted |
38+| `--runs` | 1 | Sends the request several times: the first run includes the model loading |
39+
40+The API key, when the server has one, is read from `$RZB_API_KEY`.
41+
42+## Reading the numbers
43+
44+```
45+prompt tokens 27 (reused from the cache: 0)
46+completion tokens 412 (reasoning: 301, answer: 111)
47+time to first token 1.84 s (prompt processing, + model loading on the first call)
48+time to answer 10.95 s (first token after the reasoning)
49+total time 14.40 s
50+generation speed 32.0 tokens/s
51+overall throughput 28.6 tokens/s (first token wait included)
52+```
53+
54+(Illustrative values.)
55+
56+- **Generation speed** is the decoding speed: tokens after the first one, divided by the time since the first one. This is the figure to compare between models.
57+- **Time to first token** covers the prompt processing; on the first run it also covers loading the model into memory (several seconds for a 9B model).
58+- Reasoning tokens are tokens too: a thinking model takes longer to start its answer, not to generate each token. Compare with `--no-think`.
59+- With `--runs 2` or more, **reused from the cache** shows the prompt tokens the server did not have to recompute ([prompt cache](../../docs/en/explanation/model-lifecycle.md#reusing-the-previous-prompt)).
added demos/test-qwen/test_qwen.py +136 -0
new file mode 100644
@@ -0,0 +1,136 @@
1+# /// script
2+# requires-python = ">=3.10"
3+# dependencies = ["openai>=1.40"]
4+# ///
5+"""Stream one answer from a model served by `rzb serve` and measure the generation speed.
6+
7+ uv run demos/test-qwen/test_qwen.py
8+ uv run demos/test-qwen/test_qwen.py --prompt "Explain KV caches in 3 sentences." --no-think
9+ uv run demos/test-qwen/test_qwen.py --url http://192.168.1.20:7920/v1 --runs 3
10+
11+The reasoning (Qwen3.5 thinks before answering) is printed dimmed, the answer in normal text.
12+"""
13+
14+import argparse
15+import os
16+import sys
17+import time
18+
19+from openai import APIConnectionError, APIStatusError, OpenAI
20+
21+DIM, RESET = "\033[2m", "\033[0m"
22+
23+
24+def parse_args() -> argparse.Namespace:
25+ parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
26+ parser.add_argument("--url", default=os.environ.get("RZB_URL", "http://127.0.0.1:7920/v1"),
27+ help="base URL of the server (default: $RZB_URL or %(default)s)")
28+ parser.add_argument("--model", default="mlx-community/Qwen3.5-9B-MLX-4bit")
29+ parser.add_argument("--prompt", default="Write a short poem about a razorbill diving into the sea.")
30+ parser.add_argument("--system", default="You are a helpful assistant.")
31+ parser.add_argument("--max-tokens", type=int, default=1024)
32+ parser.add_argument("--temperature", type=float, default=0.7)
33+ parser.add_argument("--no-think", action="store_true", help="turn the model's reasoning off")
34+ parser.add_argument("--hide-reasoning", action="store_true",
35+ help="do not print the reasoning (it is still generated and counted)")
36+ parser.add_argument("--runs", type=int, default=1,
37+ help="send the same request several times (the first one may load the model)")
38+ return parser.parse_args()
39+
40+
41+def stream_once(client: OpenAI, args: argparse.Namespace) -> dict:
42+ """Streams one answer; returns the timings and the token counts of the server's usage."""
43+ extra = {"chat_template_kwargs": {"enable_thinking": not args.no_think}}
44+ start = time.perf_counter()
45+ first_token = first_answer = None
46+ usage = None
47+ in_reasoning = False
48+
49+ stream = client.chat.completions.create(
50+ model=args.model,
51+ messages=[{"role": "system", "content": args.system}, {"role": "user", "content": args.prompt}],
52+ max_tokens=args.max_tokens,
53+ temperature=args.temperature,
54+ stream=True,
55+ stream_options={"include_usage": True}, # the last chunk carries the token counts
56+ extra_body=extra,
57+ )
58+ for chunk in stream:
59+ if chunk.usage:
60+ usage = chunk.usage
61+ if not chunk.choices:
62+ continue
63+ delta = chunk.choices[0].delta
64+ reasoning = getattr(delta, "reasoning_content", None) # razorbill's extension field
65+ if reasoning:
66+ first_token = first_token or time.perf_counter()
67+ if not args.hide_reasoning:
68+ if not in_reasoning:
69+ print(f"{DIM}[reasoning] ", end="")
70+ in_reasoning = True
71+ print(reasoning, end="", flush=True)
72+ if delta.content:
73+ now = time.perf_counter()
74+ first_token = first_token or now
75+ first_answer = first_answer or now
76+ if in_reasoning:
77+ print(f"{RESET}\n\n", end="")
78+ in_reasoning = False
79+ print(delta.content, end="", flush=True)
80+ end = time.perf_counter()
81+ print(RESET if in_reasoning else "", end="")
82+ print("\n")
83+ return {"start": start, "first_token": first_token, "first_answer": first_answer, "end": end,
84+ "usage": usage}
85+
86+
87+def report(result: dict) -> None:
88+ usage = result["usage"]
89+ start, end = result["start"], result["end"]
90+ total = end - start
91+ print(f"{'-' * 60}")
92+ if result["first_token"] is None or usage is None:
93+ print(f"no tokens received in {total:.2f} s")
94+ return
95+ ttft = result["first_token"] - start
96+ decode = end - result["first_token"]
97+ completion = usage.completion_tokens
98+ details = usage.completion_tokens_details
99+ reasoning = (details.reasoning_tokens or 0) if details else 0
100+ cached = (usage.prompt_tokens_details.cached_tokens or 0) if usage.prompt_tokens_details else 0
101+
102+ print(f"prompt tokens {usage.prompt_tokens:>8} (reused from the cache: {cached})")
103+ print(f"completion tokens {completion:>8} (reasoning: {reasoning}, answer: {completion - reasoning})")
104+ print(f"time to first token {ttft:>8.2f} s (prompt processing, + model loading on the first call)")
105+ if result["first_answer"] is not None:
106+ print(f"time to answer {result['first_answer'] - start:>8.2f} s (first token after the reasoning)")
107+ print(f"total time {total:>8.2f} s")
108+ if decode > 0 and completion > 1:
109+ # The first token comes with the prompt processing: speed over the tokens after it.
110+ print(f"generation speed {(completion - 1) / decode:>8.1f} tokens/s")
111+ print(f"overall throughput {completion / total:>8.1f} tokens/s (first token wait included)")
112+
113+
114+def main() -> int:
115+ args = parse_args()
116+ client = OpenAI(base_url=args.url, api_key=os.environ.get("RZB_API_KEY", "unused"))
117+ try:
118+ client.models.list()
119+ except APIConnectionError:
120+ print(f"no server at {args.url}: start it with `rzb serve` (and check the port)", file=sys.stderr)
121+ return 1
122+ print(f"model {args.model} on {args.url}, thinking {'off' if args.no_think else 'on'}\n")
123+ for run in range(1, args.runs + 1):
124+ if args.runs > 1:
125+ print(f"=== run {run}/{args.runs}\n")
126+ try:
127+ report(stream_once(client, args))
128+ except APIStatusError as error:
129+ print(f"\nserver error {error.status_code}: {error.message}", file=sys.stderr)
130+ return 1
131+ print()
132+ return 0
133+
134+
135+if __name__ == "__main__":
136+ sys.exit(main())
new file mode 100644
@@ -0,0 +1,136 @@
1+# /// script
2+# requires-python = ">=3.10"
3+# dependencies = ["openai>=1.40"]
4+# ///
5+"""Stream one answer from a model served by `rzb serve` and measure the generation speed.
6+
7+ uv run demos/test-qwen/test_qwen.py
8+ uv run demos/test-qwen/test_qwen.py --prompt "Explain KV caches in 3 sentences." --no-think
9+ uv run demos/test-qwen/test_qwen.py --url http://192.168.1.20:7920/v1 --runs 3
10+
11+The reasoning (Qwen3.5 thinks before answering) is printed dimmed, the answer in normal text.
12+"""
13+
14+import argparse
15+import os
16+import sys
17+import time
18+
19+from openai import APIConnectionError, APIStatusError, OpenAI
20+
21+DIM, RESET = "\033[2m", "\033[0m"
22+
23+
24+def parse_args() -> argparse.Namespace:
25+ parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
26+ parser.add_argument("--url", default=os.environ.get("RZB_URL", "http://127.0.0.1:7920/v1"),
27+ help="base URL of the server (default: $RZB_URL or %(default)s)")
28+ parser.add_argument("--model", default="mlx-community/Qwen3.5-9B-MLX-4bit")
29+ parser.add_argument("--prompt", default="Write a short poem about a razorbill diving into the sea.")
30+ parser.add_argument("--system", default="You are a helpful assistant.")
31+ parser.add_argument("--max-tokens", type=int, default=1024)
32+ parser.add_argument("--temperature", type=float, default=0.7)
33+ parser.add_argument("--no-think", action="store_true", help="turn the model's reasoning off")
34+ parser.add_argument("--hide-reasoning", action="store_true",
35+ help="do not print the reasoning (it is still generated and counted)")
36+ parser.add_argument("--runs", type=int, default=1,
37+ help="send the same request several times (the first one may load the model)")
38+ return parser.parse_args()
39+
40+
41+def stream_once(client: OpenAI, args: argparse.Namespace) -> dict:
42+ """Streams one answer; returns the timings and the token counts of the server's usage."""
43+ extra = {"chat_template_kwargs": {"enable_thinking": not args.no_think}}
44+ start = time.perf_counter()
45+ first_token = first_answer = None
46+ usage = None
47+ in_reasoning = False
48+
49+ stream = client.chat.completions.create(
50+ model=args.model,
51+ messages=[{"role": "system", "content": args.system}, {"role": "user", "content": args.prompt}],
52+ max_tokens=args.max_tokens,
53+ temperature=args.temperature,
54+ stream=True,
55+ stream_options={"include_usage": True}, # the last chunk carries the token counts
56+ extra_body=extra,
57+ )
58+ for chunk in stream:
59+ if chunk.usage:
60+ usage = chunk.usage
61+ if not chunk.choices:
62+ continue
63+ delta = chunk.choices[0].delta
64+ reasoning = getattr(delta, "reasoning_content", None) # razorbill's extension field
65+ if reasoning:
66+ first_token = first_token or time.perf_counter()
67+ if not args.hide_reasoning:
68+ if not in_reasoning:
69+ print(f"{DIM}[reasoning] ", end="")
70+ in_reasoning = True
71+ print(reasoning, end="", flush=True)
72+ if delta.content:
73+ now = time.perf_counter()
74+ first_token = first_token or now
75+ first_answer = first_answer or now
76+ if in_reasoning:
77+ print(f"{RESET}\n\n", end="")
78+ in_reasoning = False
79+ print(delta.content, end="", flush=True)
80+ end = time.perf_counter()
81+ print(RESET if in_reasoning else "", end="")
82+ print("\n")
83+ return {"start": start, "first_token": first_token, "first_answer": first_answer, "end": end,
84+ "usage": usage}
85+
86+
87+def report(result: dict) -> None:
88+ usage = result["usage"]
89+ start, end = result["start"], result["end"]
90+ total = end - start
91+ print(f"{'-' * 60}")
92+ if result["first_token"] is None or usage is None:
93+ print(f"no tokens received in {total:.2f} s")
94+ return
95+ ttft = result["first_token"] - start
96+ decode = end - result["first_token"]
97+ completion = usage.completion_tokens
98+ details = usage.completion_tokens_details
99+ reasoning = (details.reasoning_tokens or 0) if details else 0
100+ cached = (usage.prompt_tokens_details.cached_tokens or 0) if usage.prompt_tokens_details else 0
101+
102+ print(f"prompt tokens {usage.prompt_tokens:>8} (reused from the cache: {cached})")
103+ print(f"completion tokens {completion:>8} (reasoning: {reasoning}, answer: {completion - reasoning})")
104+ print(f"time to first token {ttft:>8.2f} s (prompt processing, + model loading on the first call)")
105+ if result["first_answer"] is not None:
106+ print(f"time to answer {result['first_answer'] - start:>8.2f} s (first token after the reasoning)")
107+ print(f"total time {total:>8.2f} s")
108+ if decode > 0 and completion > 1:
109+ # The first token comes with the prompt processing: speed over the tokens after it.
110+ print(f"generation speed {(completion - 1) / decode:>8.1f} tokens/s")
111+ print(f"overall throughput {completion / total:>8.1f} tokens/s (first token wait included)")
112+
113+
114+def main() -> int:
115+ args = parse_args()
116+ client = OpenAI(base_url=args.url, api_key=os.environ.get("RZB_API_KEY", "unused"))
117+ try:
118+ client.models.list()
119+ except APIConnectionError:
120+ print(f"no server at {args.url}: start it with `rzb serve` (and check the port)", file=sys.stderr)
121+ return 1
122+ print(f"model {args.model} on {args.url}, thinking {'off' if args.no_think else 'on'}\n")
123+ for run in range(1, args.runs + 1):
124+ if args.runs > 1:
125+ print(f"=== run {run}/{args.runs}\n")
126+ try:
127+ report(stream_once(client, args))
128+ except APIStatusError as error:
129+ print(f"\nserver error {error.status_code}: {error.message}", file=sys.stderr)
130+ return 1
131+ print()
132+ return 0
133+
134+
135+if __name__ == "__main__":
136+ sys.exit(main())