inferplan 0.1.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inferplan-0.1.0a1/LICENSE +21 -0
- inferplan-0.1.0a1/PKG-INFO +243 -0
- inferplan-0.1.0a1/README.md +218 -0
- inferplan-0.1.0a1/inferplan/__init__.py +53 -0
- inferplan-0.1.0a1/inferplan/bench.py +497 -0
- inferplan-0.1.0a1/inferplan/cli.py +76 -0
- inferplan-0.1.0a1/inferplan/costmodel.py +1688 -0
- inferplan-0.1.0a1/inferplan/gpuwatch.py +356 -0
- inferplan-0.1.0a1/inferplan/mergeledger.py +114 -0
- inferplan-0.1.0a1/inferplan/planner.py +1161 -0
- inferplan-0.1.0a1/inferplan/quality.py +659 -0
- inferplan-0.1.0a1/inferplan/repairledger.py +195 -0
- inferplan-0.1.0a1/inferplan/runner.py +1065 -0
- inferplan-0.1.0a1/inferplan/serve.py +206 -0
- inferplan-0.1.0a1/inferplan.egg-info/PKG-INFO +243 -0
- inferplan-0.1.0a1/inferplan.egg-info/SOURCES.txt +21 -0
- inferplan-0.1.0a1/inferplan.egg-info/dependency_links.txt +1 -0
- inferplan-0.1.0a1/inferplan.egg-info/entry_points.txt +2 -0
- inferplan-0.1.0a1/inferplan.egg-info/requires.txt +4 -0
- inferplan-0.1.0a1/inferplan.egg-info/top_level.txt +1 -0
- inferplan-0.1.0a1/pyproject.toml +63 -0
- inferplan-0.1.0a1/setup.cfg +4 -0
- inferplan-0.1.0a1/tests/test_smoke.py +191 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Muslim Aqeel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: inferplan
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Picks the cheapest vLLM serving configuration that still meets your latency and accuracy limits, by measuring a few on your own GPU and pricing the rest.
|
|
5
|
+
Author: Muslim Aqeel
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/muslimaqeel/inferplan
|
|
8
|
+
Project-URL: Issues, https://github.com/muslimaqeel/inferplan/issues
|
|
9
|
+
Keywords: llm,inference,vllm,serving,benchmark,cost
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: Topic :: System :: Benchmark
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: aiohttp>=3.9
|
|
22
|
+
Provides-Extra: serve
|
|
23
|
+
Requires-Dist: vllm>=0.6; extra == "serve"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# InferPlan
|
|
27
|
+
|
|
28
|
+
Finds the cheapest way to serve your LLM without breaking your latency limit —
|
|
29
|
+
by measuring a few settings on your own GPU and working out the rest.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install inferplan
|
|
33
|
+
|
|
34
|
+
inferplan sweep --sweep knee --reference-every 4 # measure (about 15 min)
|
|
35
|
+
inferplan fit # learn, and show its error
|
|
36
|
+
inferplan plan --rate 20 --p99-ms 2000 # decide
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The last command prints a `vllm serve` line you can paste, how many GPUs that
|
|
40
|
+
traffic needs, the cost per 1000 requests, and the command to check it.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Why serving settings matter
|
|
45
|
+
|
|
46
|
+
vLLM has about a dozen settings that interact: how many requests share the GPU
|
|
47
|
+
(`--max-num-seqs`), the number format (`--quantization`, `--dtype`), how much
|
|
48
|
+
memory to reserve (`--gpu-memory-utilization`), whether to cache repeated
|
|
49
|
+
prompts, and more.
|
|
50
|
+
|
|
51
|
+
Pick them badly and you pay two or three times more than you need to, or you
|
|
52
|
+
blow your latency budget. Testing them honestly means dozens of benchmark runs,
|
|
53
|
+
and the right answer changes with your model, your prompt shape, and your card.
|
|
54
|
+
So most teams try three or four combinations, pick one that works, and move on —
|
|
55
|
+
which is a reasonable thing to do and usually leaves money on the table.
|
|
56
|
+
|
|
57
|
+
InferPlan measures a handful of settings, learns how your GPU behaves from
|
|
58
|
+
those, and then prices the combinations it did **not** run.
|
|
59
|
+
|
|
60
|
+
## What it actually does
|
|
61
|
+
|
|
62
|
+
**1. Measures.** It starts a vLLM server, sends it real streaming requests, and
|
|
63
|
+
records time-to-first-token, time-per-output-token, end-to-end latency, how many
|
|
64
|
+
requests it can handle per second, and the cost. Then it stops the server and
|
|
65
|
+
does the next setting.
|
|
66
|
+
|
|
67
|
+
**2. Checks that your machine stayed still.** Before, during and after every
|
|
68
|
+
sweep it re-measures one fixed setting. If that reference drifts, the sweep is
|
|
69
|
+
thrown away. This matters more than it sounds — see below.
|
|
70
|
+
|
|
71
|
+
**3. Learns three things** from the measurements, each fitted where its own
|
|
72
|
+
effect dominates:
|
|
73
|
+
|
|
74
|
+
- **How long one decode step takes**, as the number of requests sharing it grows:
|
|
75
|
+
`step = c0 + c1 × batch^alpha`. `c0` turns out to be the time to read the
|
|
76
|
+
model weights once, which is what physics says it should be.
|
|
77
|
+
- **How long the first token takes**, split between prompt tokens the cache had
|
|
78
|
+
to compute and prompt tokens it served from memory.
|
|
79
|
+
- **How long requests wait** when more arrive than the server has room for.
|
|
80
|
+
Queueing theory predicts a coefficient of 1.0; measured, it came out 0.99.
|
|
81
|
+
|
|
82
|
+
**4. Decides.** You give it your constraints — traffic rate, latency limit,
|
|
83
|
+
accuracy you can afford to lose, budget — and it searches the whole space,
|
|
84
|
+
ranks by cost, and prints the command. It counts GPUs in whole units, because
|
|
85
|
+
a GPU is rented by the hour, not by the request.
|
|
86
|
+
|
|
87
|
+
## Installing and running it
|
|
88
|
+
|
|
89
|
+
**Install:**
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install inferplan # the tools
|
|
93
|
+
pip install inferplan[serve] # and vLLM, if it should start servers too
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
You need a machine with an NVIDIA GPU, `nvidia-smi`, and Python 3.10 or newer.
|
|
97
|
+
On Windows this means WSL2, because vLLM needs Linux.
|
|
98
|
+
|
|
99
|
+
**Step 1 — measure (about 15 minutes).** Nine settings, each benchmarked three
|
|
100
|
+
times, with a reference check every fourth one:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
inferplan sweep --sweep knee --reference-every 4
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Leave the machine otherwise idle while this runs. At the end it tells you
|
|
107
|
+
whether the reference held steady; if it did not, run it again after a rest
|
|
108
|
+
rather than using the numbers.
|
|
109
|
+
|
|
110
|
+
**Step 2 — learn.** No GPU needed; this reads the measurements from step 1:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
inferplan fit
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
This prints what it learned and how wrong it is, holding out each run in turn.
|
|
117
|
+
Read the error table before trusting anything below it.
|
|
118
|
+
|
|
119
|
+
**Step 3 — decide.** Describe your traffic and your limits:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
inferplan plan --rate 20 --input-tokens 512 --output-tokens 128 --p99-ms 2000
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- `--rate` requests per second you expect
|
|
126
|
+
- `--input-tokens` / `--output-tokens` your typical prompt and reply length
|
|
127
|
+
- `--p99-ms` the latency ceiling you must not cross
|
|
128
|
+
- `--prefix-overlap 0.8` if most of your prompt repeats (a system prompt, say)
|
|
129
|
+
- `--budget-per-1k`, `--max-gpus`, `--max-accuracy-drop-pct` if those bind
|
|
130
|
+
|
|
131
|
+
It prints the `vllm serve` command, the GPU count, the cost, and a verify
|
|
132
|
+
command.
|
|
133
|
+
|
|
134
|
+
**Step 4 — verify before you deploy.** The plan ends with the exact command;
|
|
135
|
+
run it. A prediction is an estimate until measured:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
inferplan sweep --slots 32 --reference-every 1 --repeat 3
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Measuring more** makes the predictions better. Each of these adds a dimension:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
inferplan sweep --sweep slots --reference-every 1 # bigger batches
|
|
145
|
+
inferplan sweep --sweep prefix --reference-every 4 # prompt caching
|
|
146
|
+
inferplan sweep --sweep prefix_curve --reference-every 4
|
|
147
|
+
inferplan sweep --sweep quant --reference-every 4 # number formats
|
|
148
|
+
inferplan sweep --sweep kvcache --reference-every 4
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Quality,** if you are considering a quantized model. Start a server, then:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
inferplan quality --label fp16_baseline --set-baseline
|
|
155
|
+
# restart with the quantized build, then:
|
|
156
|
+
inferplan quality --label int4
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**If something goes wrong:**
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
inferplan serve --stop # a server was left running
|
|
163
|
+
inferplan watch --seconds 60 # the GPU is behaving oddly
|
|
164
|
+
inferplan repair # the measurements look mismatched
|
|
165
|
+
inferplan <command> --help # every command explains itself
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Why the "reference control" is the interesting part
|
|
169
|
+
|
|
170
|
+
While building this, one single setting measured **4730, 3083 and 801 tokens/s
|
|
171
|
+
within 25 hours** on the same laptop — and each of those readings repeated to
|
|
172
|
+
within 0.2% across three passes. Nothing in the configuration changed. The
|
|
173
|
+
machine itself drifted, and recovered fully after fifteen minutes idle.
|
|
174
|
+
|
|
175
|
+
Someone testing one setting per sitting over an afternoon would have credited a
|
|
176
|
+
6x platform effect to whichever knob they happened to be turning, with excellent
|
|
177
|
+
internal consistency to back it up. That is not carelessness; it is unavoidable
|
|
178
|
+
without a control that returns to a previous setting and checks.
|
|
179
|
+
|
|
180
|
+
So every sweep brackets its measurements with a reference reading. If the
|
|
181
|
+
machine moved, you are told while the sweep is still running, not a day later.
|
|
182
|
+
Automating the sweep is convenience. **Automating the control is the point.**
|
|
183
|
+
|
|
184
|
+
## How to check that it isn't lying to you
|
|
185
|
+
|
|
186
|
+
Fair question to ask of anything that predicts a number. Four ways, all built in:
|
|
187
|
+
|
|
188
|
+
**It scores itself.** `inferplan fit` holds out each measured run, refits
|
|
189
|
+
without it, predicts it, and reports the error — so the score is on runs the
|
|
190
|
+
model never saw. From a development machine (RTX 3050, Qwen2.5-0.5B):
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
TPOT 1.9 %
|
|
194
|
+
median miss 0.15 ms on a typical 8.3 ms
|
|
195
|
+
TTFT 17.3 % OVER TARGET
|
|
196
|
+
median miss 4.60 ms on a typical 40.0 ms
|
|
197
|
+
E2E latency 2.3 %
|
|
198
|
+
median miss 22.90 ms on a typical 1058.1 ms
|
|
199
|
+
cost per 1K 8.1 %
|
|
200
|
+
median miss $0.00065 on a typical $0.0112
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Your numbers will differ, because they describe your GPU and your model — which
|
|
204
|
+
is the whole idea. Run `inferplan fit` and read your own.
|
|
205
|
+
|
|
206
|
+
The absolute miss is printed next to every percentage on purpose. TTFT's 17%
|
|
207
|
+
looks alarming until you see it is 4.6 ms on a 40 ms quantity — about one decode
|
|
208
|
+
step, and below any plausible scheduling jitter. A percentage without a
|
|
209
|
+
magnitude is a verdict without evidence.
|
|
210
|
+
|
|
211
|
+
**It tells you its own noise floor.** If repeated runs of the same setting
|
|
212
|
+
disagree by 5%, a 3% difference between two settings is not a result, and it
|
|
213
|
+
says so rather than ranking them.
|
|
214
|
+
|
|
215
|
+
**It refuses when it should.** It will not quietly recommend something it has
|
|
216
|
+
never measured: configurations outside the measured range are labelled as
|
|
217
|
+
extrapolations and carry a penalty, configurations whose coefficients were
|
|
218
|
+
borrowed from a neighbour rank *below* measured ones even when they price
|
|
219
|
+
cheaper, and if the ledger contains runs that do not look like measurements, the
|
|
220
|
+
planner exits instead of producing a confident wrong answer.
|
|
221
|
+
|
|
222
|
+
**It hands you the check.** Every recommendation ends with the exact command to
|
|
223
|
+
verify it by measurement, run under the reference control.
|
|
224
|
+
|
|
225
|
+
## Commands
|
|
226
|
+
|
|
227
|
+
| command | what it does |
|
|
228
|
+
|---|---|
|
|
229
|
+
| `inferplan serve MODEL` | start exactly one server and wait until it answers |
|
|
230
|
+
| `inferplan bench` | measure the running server |
|
|
231
|
+
| `inferplan sweep` | measure many settings, with the reference control |
|
|
232
|
+
| `inferplan fit` | learn from the measurements and report the error |
|
|
233
|
+
| `inferplan plan` | search and recommend, with provenance |
|
|
234
|
+
| `inferplan quality` | measure what a number format costs in output quality |
|
|
235
|
+
| `inferplan watch` | sample the GPU during a run and say what it saw |
|
|
236
|
+
| `inferplan merge` | combine measurements from several machines |
|
|
237
|
+
| `inferplan repair` | re-pair measurements with their own records |
|
|
238
|
+
|
|
239
|
+
Each takes `--help`.
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
MIT.
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# InferPlan
|
|
2
|
+
|
|
3
|
+
Finds the cheapest way to serve your LLM without breaking your latency limit —
|
|
4
|
+
by measuring a few settings on your own GPU and working out the rest.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install inferplan
|
|
8
|
+
|
|
9
|
+
inferplan sweep --sweep knee --reference-every 4 # measure (about 15 min)
|
|
10
|
+
inferplan fit # learn, and show its error
|
|
11
|
+
inferplan plan --rate 20 --p99-ms 2000 # decide
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The last command prints a `vllm serve` line you can paste, how many GPUs that
|
|
15
|
+
traffic needs, the cost per 1000 requests, and the command to check it.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Why serving settings matter
|
|
20
|
+
|
|
21
|
+
vLLM has about a dozen settings that interact: how many requests share the GPU
|
|
22
|
+
(`--max-num-seqs`), the number format (`--quantization`, `--dtype`), how much
|
|
23
|
+
memory to reserve (`--gpu-memory-utilization`), whether to cache repeated
|
|
24
|
+
prompts, and more.
|
|
25
|
+
|
|
26
|
+
Pick them badly and you pay two or three times more than you need to, or you
|
|
27
|
+
blow your latency budget. Testing them honestly means dozens of benchmark runs,
|
|
28
|
+
and the right answer changes with your model, your prompt shape, and your card.
|
|
29
|
+
So most teams try three or four combinations, pick one that works, and move on —
|
|
30
|
+
which is a reasonable thing to do and usually leaves money on the table.
|
|
31
|
+
|
|
32
|
+
InferPlan measures a handful of settings, learns how your GPU behaves from
|
|
33
|
+
those, and then prices the combinations it did **not** run.
|
|
34
|
+
|
|
35
|
+
## What it actually does
|
|
36
|
+
|
|
37
|
+
**1. Measures.** It starts a vLLM server, sends it real streaming requests, and
|
|
38
|
+
records time-to-first-token, time-per-output-token, end-to-end latency, how many
|
|
39
|
+
requests it can handle per second, and the cost. Then it stops the server and
|
|
40
|
+
does the next setting.
|
|
41
|
+
|
|
42
|
+
**2. Checks that your machine stayed still.** Before, during and after every
|
|
43
|
+
sweep it re-measures one fixed setting. If that reference drifts, the sweep is
|
|
44
|
+
thrown away. This matters more than it sounds — see below.
|
|
45
|
+
|
|
46
|
+
**3. Learns three things** from the measurements, each fitted where its own
|
|
47
|
+
effect dominates:
|
|
48
|
+
|
|
49
|
+
- **How long one decode step takes**, as the number of requests sharing it grows:
|
|
50
|
+
`step = c0 + c1 × batch^alpha`. `c0` turns out to be the time to read the
|
|
51
|
+
model weights once, which is what physics says it should be.
|
|
52
|
+
- **How long the first token takes**, split between prompt tokens the cache had
|
|
53
|
+
to compute and prompt tokens it served from memory.
|
|
54
|
+
- **How long requests wait** when more arrive than the server has room for.
|
|
55
|
+
Queueing theory predicts a coefficient of 1.0; measured, it came out 0.99.
|
|
56
|
+
|
|
57
|
+
**4. Decides.** You give it your constraints — traffic rate, latency limit,
|
|
58
|
+
accuracy you can afford to lose, budget — and it searches the whole space,
|
|
59
|
+
ranks by cost, and prints the command. It counts GPUs in whole units, because
|
|
60
|
+
a GPU is rented by the hour, not by the request.
|
|
61
|
+
|
|
62
|
+
## Installing and running it
|
|
63
|
+
|
|
64
|
+
**Install:**
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install inferplan # the tools
|
|
68
|
+
pip install inferplan[serve] # and vLLM, if it should start servers too
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
You need a machine with an NVIDIA GPU, `nvidia-smi`, and Python 3.10 or newer.
|
|
72
|
+
On Windows this means WSL2, because vLLM needs Linux.
|
|
73
|
+
|
|
74
|
+
**Step 1 — measure (about 15 minutes).** Nine settings, each benchmarked three
|
|
75
|
+
times, with a reference check every fourth one:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
inferplan sweep --sweep knee --reference-every 4
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Leave the machine otherwise idle while this runs. At the end it tells you
|
|
82
|
+
whether the reference held steady; if it did not, run it again after a rest
|
|
83
|
+
rather than using the numbers.
|
|
84
|
+
|
|
85
|
+
**Step 2 — learn.** No GPU needed; this reads the measurements from step 1:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
inferplan fit
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This prints what it learned and how wrong it is, holding out each run in turn.
|
|
92
|
+
Read the error table before trusting anything below it.
|
|
93
|
+
|
|
94
|
+
**Step 3 — decide.** Describe your traffic and your limits:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
inferplan plan --rate 20 --input-tokens 512 --output-tokens 128 --p99-ms 2000
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- `--rate` requests per second you expect
|
|
101
|
+
- `--input-tokens` / `--output-tokens` your typical prompt and reply length
|
|
102
|
+
- `--p99-ms` the latency ceiling you must not cross
|
|
103
|
+
- `--prefix-overlap 0.8` if most of your prompt repeats (a system prompt, say)
|
|
104
|
+
- `--budget-per-1k`, `--max-gpus`, `--max-accuracy-drop-pct` if those bind
|
|
105
|
+
|
|
106
|
+
It prints the `vllm serve` command, the GPU count, the cost, and a verify
|
|
107
|
+
command.
|
|
108
|
+
|
|
109
|
+
**Step 4 — verify before you deploy.** The plan ends with the exact command;
|
|
110
|
+
run it. A prediction is an estimate until measured:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
inferplan sweep --slots 32 --reference-every 1 --repeat 3
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Measuring more** makes the predictions better. Each of these adds a dimension:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
inferplan sweep --sweep slots --reference-every 1 # bigger batches
|
|
120
|
+
inferplan sweep --sweep prefix --reference-every 4 # prompt caching
|
|
121
|
+
inferplan sweep --sweep prefix_curve --reference-every 4
|
|
122
|
+
inferplan sweep --sweep quant --reference-every 4 # number formats
|
|
123
|
+
inferplan sweep --sweep kvcache --reference-every 4
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Quality,** if you are considering a quantized model. Start a server, then:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
inferplan quality --label fp16_baseline --set-baseline
|
|
130
|
+
# restart with the quantized build, then:
|
|
131
|
+
inferplan quality --label int4
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**If something goes wrong:**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
inferplan serve --stop # a server was left running
|
|
138
|
+
inferplan watch --seconds 60 # the GPU is behaving oddly
|
|
139
|
+
inferplan repair # the measurements look mismatched
|
|
140
|
+
inferplan <command> --help # every command explains itself
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Why the "reference control" is the interesting part
|
|
144
|
+
|
|
145
|
+
While building this, one single setting measured **4730, 3083 and 801 tokens/s
|
|
146
|
+
within 25 hours** on the same laptop — and each of those readings repeated to
|
|
147
|
+
within 0.2% across three passes. Nothing in the configuration changed. The
|
|
148
|
+
machine itself drifted, and recovered fully after fifteen minutes idle.
|
|
149
|
+
|
|
150
|
+
Someone testing one setting per sitting over an afternoon would have credited a
|
|
151
|
+
6x platform effect to whichever knob they happened to be turning, with excellent
|
|
152
|
+
internal consistency to back it up. That is not carelessness; it is unavoidable
|
|
153
|
+
without a control that returns to a previous setting and checks.
|
|
154
|
+
|
|
155
|
+
So every sweep brackets its measurements with a reference reading. If the
|
|
156
|
+
machine moved, you are told while the sweep is still running, not a day later.
|
|
157
|
+
Automating the sweep is convenience. **Automating the control is the point.**
|
|
158
|
+
|
|
159
|
+
## How to check that it isn't lying to you
|
|
160
|
+
|
|
161
|
+
Fair question to ask of anything that predicts a number. Four ways, all built in:
|
|
162
|
+
|
|
163
|
+
**It scores itself.** `inferplan fit` holds out each measured run, refits
|
|
164
|
+
without it, predicts it, and reports the error — so the score is on runs the
|
|
165
|
+
model never saw. From a development machine (RTX 3050, Qwen2.5-0.5B):
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
TPOT 1.9 %
|
|
169
|
+
median miss 0.15 ms on a typical 8.3 ms
|
|
170
|
+
TTFT 17.3 % OVER TARGET
|
|
171
|
+
median miss 4.60 ms on a typical 40.0 ms
|
|
172
|
+
E2E latency 2.3 %
|
|
173
|
+
median miss 22.90 ms on a typical 1058.1 ms
|
|
174
|
+
cost per 1K 8.1 %
|
|
175
|
+
median miss $0.00065 on a typical $0.0112
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Your numbers will differ, because they describe your GPU and your model — which
|
|
179
|
+
is the whole idea. Run `inferplan fit` and read your own.
|
|
180
|
+
|
|
181
|
+
The absolute miss is printed next to every percentage on purpose. TTFT's 17%
|
|
182
|
+
looks alarming until you see it is 4.6 ms on a 40 ms quantity — about one decode
|
|
183
|
+
step, and below any plausible scheduling jitter. A percentage without a
|
|
184
|
+
magnitude is a verdict without evidence.
|
|
185
|
+
|
|
186
|
+
**It tells you its own noise floor.** If repeated runs of the same setting
|
|
187
|
+
disagree by 5%, a 3% difference between two settings is not a result, and it
|
|
188
|
+
says so rather than ranking them.
|
|
189
|
+
|
|
190
|
+
**It refuses when it should.** It will not quietly recommend something it has
|
|
191
|
+
never measured: configurations outside the measured range are labelled as
|
|
192
|
+
extrapolations and carry a penalty, configurations whose coefficients were
|
|
193
|
+
borrowed from a neighbour rank *below* measured ones even when they price
|
|
194
|
+
cheaper, and if the ledger contains runs that do not look like measurements, the
|
|
195
|
+
planner exits instead of producing a confident wrong answer.
|
|
196
|
+
|
|
197
|
+
**It hands you the check.** Every recommendation ends with the exact command to
|
|
198
|
+
verify it by measurement, run under the reference control.
|
|
199
|
+
|
|
200
|
+
## Commands
|
|
201
|
+
|
|
202
|
+
| command | what it does |
|
|
203
|
+
|---|---|
|
|
204
|
+
| `inferplan serve MODEL` | start exactly one server and wait until it answers |
|
|
205
|
+
| `inferplan bench` | measure the running server |
|
|
206
|
+
| `inferplan sweep` | measure many settings, with the reference control |
|
|
207
|
+
| `inferplan fit` | learn from the measurements and report the error |
|
|
208
|
+
| `inferplan plan` | search and recommend, with provenance |
|
|
209
|
+
| `inferplan quality` | measure what a number format costs in output quality |
|
|
210
|
+
| `inferplan watch` | sample the GPU during a run and say what it saw |
|
|
211
|
+
| `inferplan merge` | combine measurements from several machines |
|
|
212
|
+
| `inferplan repair` | re-pair measurements with their own records |
|
|
213
|
+
|
|
214
|
+
Each takes `--help`.
|
|
215
|
+
|
|
216
|
+
## License
|
|
217
|
+
|
|
218
|
+
MIT.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
InferPlan: cost-aware inference planning for LLM serving.
|
|
3
|
+
|
|
4
|
+
Measures a few serving configurations on the GPU you actually have, learns a
|
|
5
|
+
cost model from those measurements, and then prices the rest of the search
|
|
6
|
+
space without running it - so you get a `vllm serve` command that meets your
|
|
7
|
+
latency and accuracy limits at the lowest cost per request.
|
|
8
|
+
|
|
9
|
+
What makes it different from a benchmark script is what it refuses to do:
|
|
10
|
+
|
|
11
|
+
- It does not recommend a configuration it has never seen measured without
|
|
12
|
+
labelling the figure as an extrapolation.
|
|
13
|
+
- It does not plan at all when the measurements in its ledger do not look
|
|
14
|
+
like measurements.
|
|
15
|
+
- It re-measures a fixed reference configuration during every sweep, and
|
|
16
|
+
throws the sweep away if the machine drifted while it ran. On the laptop
|
|
17
|
+
this was developed on, one configuration read 4730, 3083 and 801 tokens/s
|
|
18
|
+
within 25 hours, each reading repeatable to 0.2%. Without that control,
|
|
19
|
+
a 6x platform effect gets attributed to whichever knob was being turned.
|
|
20
|
+
|
|
21
|
+
The modules, in the order a session uses them:
|
|
22
|
+
|
|
23
|
+
serve start exactly one vLLM server and wait until it answers
|
|
24
|
+
bench measure one running server (TTFT, TPOT, ITL, cost, noise)
|
|
25
|
+
runner sweep configurations, with the reference control
|
|
26
|
+
costmodel learn from the ledger; leave-one-out validation
|
|
27
|
+
planner search the space, rank by cost, print the serve command
|
|
28
|
+
quality measure what quantization costs in output quality
|
|
29
|
+
gpuwatch sample the GPU during a run and say what it saw
|
|
30
|
+
mergeledger combine ledgers from several machines or sessions
|
|
31
|
+
repairledger re-pair ledger rows with their own benchmark records
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# Read from the installed package metadata, which pyproject.toml is the only
|
|
35
|
+
# source of. Hard-coding it here made `inferplan --version` print 0.1.0 while
|
|
36
|
+
# the wheel on TestPyPI was 0.1.0a1 - the same version claimed in two places,
|
|
37
|
+
# with nothing comparing them. That is the shape of the dependency-list bug
|
|
38
|
+
# (finding #38) and the requires-python bug: a fact stated twice is a fact
|
|
39
|
+
# that will eventually disagree with itself.
|
|
40
|
+
try:
|
|
41
|
+
from importlib.metadata import PackageNotFoundError, version as _version
|
|
42
|
+
try:
|
|
43
|
+
__version__ = _version("inferplan")
|
|
44
|
+
except PackageNotFoundError:
|
|
45
|
+
# Running from a source checkout that was never installed.
|
|
46
|
+
__version__ = "0.0.0+local"
|
|
47
|
+
except ImportError: # pragma: no cover
|
|
48
|
+
__version__ = "0.0.0+unknown"
|
|
49
|
+
|
|
50
|
+
__all__ = [
|
|
51
|
+
"bench", "runner", "costmodel", "planner", "quality",
|
|
52
|
+
"serve", "gpuwatch", "mergeledger", "repairledger",
|
|
53
|
+
]
|