hmft 0.2.0__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.
hmft-0.2.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 hmft contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
hmft-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,252 @@
1
+ Metadata-Version: 2.4
2
+ Name: hmft
3
+ Version: 0.2.0
4
+ Summary: Estimate how long an LLM call will take before you send it, plus a live ETA while it streams. Fully client-side.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://hmft.dev
7
+ Project-URL: Repository, https://github.com/hmft-dev/hmft
8
+ Project-URL: Changelog, https://github.com/hmft-dev/hmft/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/hmft-dev/hmft/issues
10
+ Keywords: llm,latency,estimate,eta,streaming,tokens,tokenizer,openai,anthropic,benchmark
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: tiktoken>=0.7
27
+ Requires-Dist: httpx>=0.25
28
+ Provides-Extra: openai
29
+ Requires-Dist: openai>=1.30; extra == "openai"
30
+ Provides-Extra: anthropic
31
+ Requires-Dist: anthropic>=0.30; extra == "anthropic"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=8; extra == "dev"
34
+ Requires-Dist: openai>=1.30; extra == "dev"
35
+ Requires-Dist: anthropic>=0.30; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # hmft
39
+
40
+ Estimate how long an LLM call will take **before you send it**, and get a live ETA while it
41
+ streams. Runs entirely on your machine: no prompt or response text ever leaves the process.
42
+
43
+ ```bash
44
+ pip install hmft # from PyPI
45
+ pip install "hmft[openai,anthropic]" # with the SDK wrappers
46
+ pip install -e ".[dev]" # from a clone, with the test extras
47
+ ```
48
+
49
+ ## Quickstart
50
+
51
+ No API key, no network call: the estimate is computed locally from the prompt.
52
+
53
+ ```python
54
+ import hmft
55
+
56
+ est = hmft.estimate(
57
+ [{"role": "user", "content": "Explain how bicycles stay upright in two paragraphs."}],
58
+ model="gpt-4.1-mini", provider="openai",
59
+ )
60
+ print(est) # ~2.3s (p90 4.6s): ttft 0.69s, ~220 tokens [measured]
61
+ print(est.total_s.p50, est.total_s.p90) # 2.27 4.58
62
+ print(est.output_tokens.p50, est.output_tokens.p90) # 220 352
63
+ ```
64
+
65
+ Every estimate is a **band, not a point**: `p50` is the typical case, `p90` is the slow-but-likely
66
+ case you should plan around.
67
+
68
+ ## Accuracy on held-out prompts
69
+
70
+ 186 rows from prompt sets A to D, four models, re-scored under the current code with
71
+ `scripts/compare_runs.py`. "Coverage" is the share of rows whose actual landed at or under
72
+ the estimated p90; the target is about 90%.
73
+
74
+ **What "held out" means here, precisely.** These 186 rows are held out from **v2** constant
75
+ fitting: `compare_runs.py` marks sets A to D held-out and fits only on the later sets (E, F).
76
+ They are *not* untouched by v1. Set A is the v1 calibration set, and four v1.1 constants were
77
+ fitted or corrected using rows that are in this table — `TOKENS_PER_LIST_ITEM` (set B
78
+ actuals), `TOKENS_PER_ONE_LINE_ITEM_P50/P90` (A, B and C), the spoken-duration cue
79
+ `490 + 59 × minutes` (C and D), and the `code_large` band (the `long_code` actuals in A, B
80
+ and C). Read the table below as a standing regression score, not as a clean out-of-sample
81
+ result. The cleanest out-of-sample evidence is set E, measured on different subjects, where
82
+ the duration cue covered 29 of 30 rows.
83
+
84
+ | model | held-out rows | token p90 coverage | time p90 coverage |
85
+ |---|---|---|---|
86
+ | gpt-4.1-mini | 46 | 100% | 98% |
87
+ | claude-haiku-4-5 | 47 | 96% | 100% |
88
+ | claude-sonnet-4-5 | 47 | 100% | 94% |
89
+ | gpt-5@low | 46 | 100% † | 100% † |
90
+ | **all non-reasoning** | **140** | **99%** | **97%** |
91
+
92
+ † **gpt-5@low passes neither figure, despite the numbers, because all three of its table
93
+ constants are wrong.** The row assumes 1,312 hidden reasoning tokens, where the split runs
94
+ measured medians of 320 (set E) and 96 (set F); a 9.5 s first token, where the runs measured
95
+ per-run medians of 4.1 to 7.2 s; and 123 tokens/s decode, where the runs measured 34.9 to
96
+ 108.6 tokens/s (per-run medians 58 to 81). So hmft over-estimates time for gpt-5@low (set F
97
+ median actual/estimate 0.55) and under-estimates visible output on long-form prompts (set E
98
+ 1.27 and 1.34). The 100% coverage above is those two errors cancelling, not a pass. The
99
+ rebuild ships in 0.3.0. See `RESULTS.md`.
100
+
101
+ All four time-coverage breaches across the 140 non-reasoning rows were caused by time to
102
+ first token, not by the length heuristics; the token estimate was inside p90 in every one.
103
+
104
+ ## Supported models
105
+
106
+ | model | provider | status | basis |
107
+ |---|---|---|---|
108
+ | `gpt-4.1-mini` | openai | measured | 10 benchmark samples; 46 held-out rows |
109
+ | `claude-haiku-4-5` | anthropic | measured | 10 benchmark samples; 47 held-out rows |
110
+ | `claude-sonnet-4-5` | anthropic | measured | 40 benchmark samples; 47 held-out rows |
111
+ | `gpt-5@low` | openai | experimental | 10 benchmark samples; hidden tokens, first token and decode rate all mis-set (above): over-estimates time, under-estimates tokens |
112
+ | `gpt-5@medium` | openai | experimental | 10 benchmark samples; no held-out rows |
113
+ | `gpt-5-mini` | openai | experimental | 10 benchmark samples; no held-out rows |
114
+ | `gpt-4.1` | openai | experimental | 10 benchmark samples; no held-out rows |
115
+ | `openai/gpt-4.1-mini`, `openai/gpt-4.1`, `openai/gpt-5-mini`, `anthropic/claude-sonnet-4.5`, `anthropic/claude-haiku-4.5` | openrouter | experimental | 6 to 10 benchmark samples each; no held-out rows |
116
+ | anything else | any | not measured | `basis="unmeasured"`: token band only, no timing |
117
+
118
+ **measured** means the throughput row comes from a real benchmark run *and* the model has
119
+ held-out coverage above. **experimental** means the throughput row is real but the estimate
120
+ has not been scored against held-out prompts, or was scored and did not pass. **not
121
+ measured** means hmft refuses to invent a number: you get an output-token band and
122
+ `basis="unmeasured"`, never a fabricated time.
123
+
124
+ A bare `gpt-5` call with no effort set maps to the `gpt-5@medium` row, the provider default,
125
+ and `basis_key` says so. OpenRouter has no provider-wide fallback row, because it routes
126
+ across model families; an unbenchmarked slug is `unmeasured`.
127
+
128
+ ## Privacy
129
+
130
+ **No prompt text and no response text is ever stored, logged, printed or transmitted.**
131
+ Nothing is uploaded anywhere, by any code path, in v1. There is no server.
132
+
133
+ After each wrapped call hmft appends one JSON line to `~/.hmft/telemetry.jsonl`, created
134
+ `0600`, so you can score your own accuracy offline. The row is an allow-list of integers,
135
+ floats and short enum words — exactly these 24 fields and nothing else:
136
+
137
+ `ts`, `hmft_version`, `model`, `provider`, `prompt_tokens`, `output_tokens`, `ttft_ms`,
138
+ `total_ms`, `est_output_p50`, `est_output_p90`, `est_ttft_p50_s`, `est_ttft_p90_s`,
139
+ `est_total_p50_s`, `est_total_p90_s`, `basis`, `reasoning_effort`, `effort_source`,
140
+ `reasoning_tokens`, `finish_reason`, `visible_chunks`, `first_second_visible_chunks`,
141
+ `last_visible_ms`, `first_event_ms`, `max_gap_ms`.
142
+
143
+ No prompt, no response, no request ids, no user ids. `reasoning_effort`, `effort_source`,
144
+ `basis` and `finish_reason` are validated against fixed sets, so free text is dropped rather
145
+ than written. The write is enforced by an assertion against the allow-list in
146
+ `hmft/telemetry.py`, and `tests/test_telemetry.py` checks it.
147
+
148
+ Opt out with one environment variable:
149
+
150
+ ```bash
151
+ HMFT_TELEMETRY=off # write nothing
152
+ HMFT_TELEMETRY=/path/to/file.jsonl # or move it somewhere else
153
+ ```
154
+
155
+ ## The name
156
+
157
+ HMFT is short for **"how much fucking time"** — the question you actually ask when a model has
158
+ been streaming for forty seconds and you have no idea whether it is nearly done or has barely
159
+ started. The package, the import and the docs are all just `hmft`; the long form lives here and
160
+ nowhere else.
161
+
162
+ ## How estimates work
163
+
164
+ ```
165
+ total_time ≈ TTFT(prompt_tokens, model) + output_tokens / tokens_per_second(model)
166
+ ```
167
+
168
+ 1. **Output length comes from cues in the prompt** (`hmft/length.py`), in priority order:
169
+ an explicit count ("in one sentence", "about 500 words", "8 questions", "one per line"),
170
+ a stated speaking duration ("a 10-minute keynote" → `490 + 59 × minutes` tokens, validated
171
+ 2 to 45 minutes), a forced format (JSON mode, forced tool call, `max_tokens`), and finally
172
+ a task type guessed from keywords (code, list, JSON, yes/no, translate, summarise, essay,
173
+ explain, chat), each with its own base band.
174
+ 2. **TTFT and tokens/second are measured constants**, per model and provider, in
175
+ `hmft/data/throughput.json`. They are only ever written by `scripts/benchmark.py` from real
176
+ runs — never estimated, never hand-edited. Unmeasured rows stay `null` and the estimator
177
+ reports `basis="unmeasured"` instead of guessing.
178
+ 3. **The band comes from both.** The p50 time uses the throughput `p50`; the p90 time uses the
179
+ throughput **`p10`**, because for a rate the slow side is the low percentile. The length
180
+ heuristic contributes its own p50/p90, and the two compose into `total_s`.
181
+
182
+ Measured throughput, as of the `updated_at` in the table:
183
+
184
+ | model | TTFT p50 / p90 | tokens/s p50 / p10 | samples |
185
+ |---|---|---|---|
186
+ | gpt-4.1-mini | 0.69 s / 1.622 s | 139.2 / 119.1 | 10 |
187
+ | gpt-4.1 | 0.76 s / 2.229 s | 111.3 / 90.5 | 10 |
188
+ | claude-haiku-4-5 | 0.67 s / 0.686 s | 83.4 / 79.5 | 10 |
189
+ | claude-sonnet-4-5 | 0.86 s / 1.355 s | 36.8 / 34.6 | 40 |
190
+ | gpt-5@low | 9.5 s / 17.52 s | 123.0 / 69.4 | 10 |
191
+
192
+ On reasoning models the TTFT column absorbs hidden thinking time, which is why it is large and
193
+ why those rows are experimental.
194
+
195
+ ## Streaming ETA
196
+
197
+ ```python
198
+ from openai import OpenAI
199
+ import hmft
200
+
201
+ client = hmft.wrap_openai(OpenAI())
202
+ stream = client.chat.completions.create(
203
+ model="gpt-4.1-mini", stream=True,
204
+ messages=[{"role": "user", "content": "Explain how bicycles stay upright in two paragraphs."}],
205
+ )
206
+ print(stream.estimate) # pre-call band
207
+ for chunk in stream:
208
+ print(stream.eta(), end="\r") # live: blends the observed rate in after a few tokens
209
+ print(stream.result) # actual vs estimated
210
+ ```
211
+
212
+ `hmft.wrap_anthropic(Anthropic())` is the same shape around `client.messages.stream(...)`.
213
+ Wrappers are sync-only in v1; async is a v1.x item.
214
+
215
+ ## Filling the throughput table
216
+
217
+ ```bash
218
+ export OPENAI_API_KEY=... # and/or ANTHROPIC_API_KEY, OPENROUTER_API_KEY
219
+ python scripts/benchmark.py --all --dry-run # print the plan, make no calls
220
+ python scripts/benchmark.py --provider anthropic --models claude-haiku-4-5 --runs 3
221
+ ```
222
+
223
+ Each run sends two synthetic prompts and records only token counts and timings.
224
+ `name@effort` (for example `gpt-5@low`) sets `reasoning_effort` and gets its own row.
225
+
226
+ ## Known limits
227
+
228
+ - Output-length heuristics are rules, not a model. Expect the p50 to be off by 2x on
229
+ open-ended prompts; the p90 band is what to plan around.
230
+ - Reasoning models spend most of their wall time on hidden tokens the heuristics cannot see.
231
+ - Non-OpenAI token counts use the o200k tokenizer as a proxy, typically within 10 to 20%.
232
+ - Image and tool-result content blocks are not counted.
233
+ - Talk-duration cues are validated 2 to 45 minutes; above 45 is extrapolation. The p90 held on
234
+ 29 of 30 measured talks, but the p50 is biased per model: gpt-4.1-mini writes far less than
235
+ the estimate on long talks, Claude models somewhat more.
236
+ - Provider latency drifts hour to hour; `measured_at` tells you how stale a row is.
237
+
238
+ ## Tests
239
+
240
+ ```bash
241
+ pip install -e ".[dev]"
242
+ python -m pytest
243
+ ```
244
+
245
+ All tests use synthetic prompts and fake clients, and the suite makes no network calls —
246
+ `tests/test_no_network.py` enforces that. See `CONTRIBUTING.md` for the held-out rule and the
247
+ version-bump rule. `BASELINE.md` is the frozen v1 reference and `RESULTS.md` records every
248
+ measurement since.
249
+
250
+ ## License
251
+
252
+ Apache-2.0. See `LICENSE`.
hmft-0.2.0/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # hmft
2
+
3
+ Estimate how long an LLM call will take **before you send it**, and get a live ETA while it
4
+ streams. Runs entirely on your machine: no prompt or response text ever leaves the process.
5
+
6
+ ```bash
7
+ pip install hmft # from PyPI
8
+ pip install "hmft[openai,anthropic]" # with the SDK wrappers
9
+ pip install -e ".[dev]" # from a clone, with the test extras
10
+ ```
11
+
12
+ ## Quickstart
13
+
14
+ No API key, no network call: the estimate is computed locally from the prompt.
15
+
16
+ ```python
17
+ import hmft
18
+
19
+ est = hmft.estimate(
20
+ [{"role": "user", "content": "Explain how bicycles stay upright in two paragraphs."}],
21
+ model="gpt-4.1-mini", provider="openai",
22
+ )
23
+ print(est) # ~2.3s (p90 4.6s): ttft 0.69s, ~220 tokens [measured]
24
+ print(est.total_s.p50, est.total_s.p90) # 2.27 4.58
25
+ print(est.output_tokens.p50, est.output_tokens.p90) # 220 352
26
+ ```
27
+
28
+ Every estimate is a **band, not a point**: `p50` is the typical case, `p90` is the slow-but-likely
29
+ case you should plan around.
30
+
31
+ ## Accuracy on held-out prompts
32
+
33
+ 186 rows from prompt sets A to D, four models, re-scored under the current code with
34
+ `scripts/compare_runs.py`. "Coverage" is the share of rows whose actual landed at or under
35
+ the estimated p90; the target is about 90%.
36
+
37
+ **What "held out" means here, precisely.** These 186 rows are held out from **v2** constant
38
+ fitting: `compare_runs.py` marks sets A to D held-out and fits only on the later sets (E, F).
39
+ They are *not* untouched by v1. Set A is the v1 calibration set, and four v1.1 constants were
40
+ fitted or corrected using rows that are in this table — `TOKENS_PER_LIST_ITEM` (set B
41
+ actuals), `TOKENS_PER_ONE_LINE_ITEM_P50/P90` (A, B and C), the spoken-duration cue
42
+ `490 + 59 × minutes` (C and D), and the `code_large` band (the `long_code` actuals in A, B
43
+ and C). Read the table below as a standing regression score, not as a clean out-of-sample
44
+ result. The cleanest out-of-sample evidence is set E, measured on different subjects, where
45
+ the duration cue covered 29 of 30 rows.
46
+
47
+ | model | held-out rows | token p90 coverage | time p90 coverage |
48
+ |---|---|---|---|
49
+ | gpt-4.1-mini | 46 | 100% | 98% |
50
+ | claude-haiku-4-5 | 47 | 96% | 100% |
51
+ | claude-sonnet-4-5 | 47 | 100% | 94% |
52
+ | gpt-5@low | 46 | 100% † | 100% † |
53
+ | **all non-reasoning** | **140** | **99%** | **97%** |
54
+
55
+ † **gpt-5@low passes neither figure, despite the numbers, because all three of its table
56
+ constants are wrong.** The row assumes 1,312 hidden reasoning tokens, where the split runs
57
+ measured medians of 320 (set E) and 96 (set F); a 9.5 s first token, where the runs measured
58
+ per-run medians of 4.1 to 7.2 s; and 123 tokens/s decode, where the runs measured 34.9 to
59
+ 108.6 tokens/s (per-run medians 58 to 81). So hmft over-estimates time for gpt-5@low (set F
60
+ median actual/estimate 0.55) and under-estimates visible output on long-form prompts (set E
61
+ 1.27 and 1.34). The 100% coverage above is those two errors cancelling, not a pass. The
62
+ rebuild ships in 0.3.0. See `RESULTS.md`.
63
+
64
+ All four time-coverage breaches across the 140 non-reasoning rows were caused by time to
65
+ first token, not by the length heuristics; the token estimate was inside p90 in every one.
66
+
67
+ ## Supported models
68
+
69
+ | model | provider | status | basis |
70
+ |---|---|---|---|
71
+ | `gpt-4.1-mini` | openai | measured | 10 benchmark samples; 46 held-out rows |
72
+ | `claude-haiku-4-5` | anthropic | measured | 10 benchmark samples; 47 held-out rows |
73
+ | `claude-sonnet-4-5` | anthropic | measured | 40 benchmark samples; 47 held-out rows |
74
+ | `gpt-5@low` | openai | experimental | 10 benchmark samples; hidden tokens, first token and decode rate all mis-set (above): over-estimates time, under-estimates tokens |
75
+ | `gpt-5@medium` | openai | experimental | 10 benchmark samples; no held-out rows |
76
+ | `gpt-5-mini` | openai | experimental | 10 benchmark samples; no held-out rows |
77
+ | `gpt-4.1` | openai | experimental | 10 benchmark samples; no held-out rows |
78
+ | `openai/gpt-4.1-mini`, `openai/gpt-4.1`, `openai/gpt-5-mini`, `anthropic/claude-sonnet-4.5`, `anthropic/claude-haiku-4.5` | openrouter | experimental | 6 to 10 benchmark samples each; no held-out rows |
79
+ | anything else | any | not measured | `basis="unmeasured"`: token band only, no timing |
80
+
81
+ **measured** means the throughput row comes from a real benchmark run *and* the model has
82
+ held-out coverage above. **experimental** means the throughput row is real but the estimate
83
+ has not been scored against held-out prompts, or was scored and did not pass. **not
84
+ measured** means hmft refuses to invent a number: you get an output-token band and
85
+ `basis="unmeasured"`, never a fabricated time.
86
+
87
+ A bare `gpt-5` call with no effort set maps to the `gpt-5@medium` row, the provider default,
88
+ and `basis_key` says so. OpenRouter has no provider-wide fallback row, because it routes
89
+ across model families; an unbenchmarked slug is `unmeasured`.
90
+
91
+ ## Privacy
92
+
93
+ **No prompt text and no response text is ever stored, logged, printed or transmitted.**
94
+ Nothing is uploaded anywhere, by any code path, in v1. There is no server.
95
+
96
+ After each wrapped call hmft appends one JSON line to `~/.hmft/telemetry.jsonl`, created
97
+ `0600`, so you can score your own accuracy offline. The row is an allow-list of integers,
98
+ floats and short enum words — exactly these 24 fields and nothing else:
99
+
100
+ `ts`, `hmft_version`, `model`, `provider`, `prompt_tokens`, `output_tokens`, `ttft_ms`,
101
+ `total_ms`, `est_output_p50`, `est_output_p90`, `est_ttft_p50_s`, `est_ttft_p90_s`,
102
+ `est_total_p50_s`, `est_total_p90_s`, `basis`, `reasoning_effort`, `effort_source`,
103
+ `reasoning_tokens`, `finish_reason`, `visible_chunks`, `first_second_visible_chunks`,
104
+ `last_visible_ms`, `first_event_ms`, `max_gap_ms`.
105
+
106
+ No prompt, no response, no request ids, no user ids. `reasoning_effort`, `effort_source`,
107
+ `basis` and `finish_reason` are validated against fixed sets, so free text is dropped rather
108
+ than written. The write is enforced by an assertion against the allow-list in
109
+ `hmft/telemetry.py`, and `tests/test_telemetry.py` checks it.
110
+
111
+ Opt out with one environment variable:
112
+
113
+ ```bash
114
+ HMFT_TELEMETRY=off # write nothing
115
+ HMFT_TELEMETRY=/path/to/file.jsonl # or move it somewhere else
116
+ ```
117
+
118
+ ## The name
119
+
120
+ HMFT is short for **"how much fucking time"** — the question you actually ask when a model has
121
+ been streaming for forty seconds and you have no idea whether it is nearly done or has barely
122
+ started. The package, the import and the docs are all just `hmft`; the long form lives here and
123
+ nowhere else.
124
+
125
+ ## How estimates work
126
+
127
+ ```
128
+ total_time ≈ TTFT(prompt_tokens, model) + output_tokens / tokens_per_second(model)
129
+ ```
130
+
131
+ 1. **Output length comes from cues in the prompt** (`hmft/length.py`), in priority order:
132
+ an explicit count ("in one sentence", "about 500 words", "8 questions", "one per line"),
133
+ a stated speaking duration ("a 10-minute keynote" → `490 + 59 × minutes` tokens, validated
134
+ 2 to 45 minutes), a forced format (JSON mode, forced tool call, `max_tokens`), and finally
135
+ a task type guessed from keywords (code, list, JSON, yes/no, translate, summarise, essay,
136
+ explain, chat), each with its own base band.
137
+ 2. **TTFT and tokens/second are measured constants**, per model and provider, in
138
+ `hmft/data/throughput.json`. They are only ever written by `scripts/benchmark.py` from real
139
+ runs — never estimated, never hand-edited. Unmeasured rows stay `null` and the estimator
140
+ reports `basis="unmeasured"` instead of guessing.
141
+ 3. **The band comes from both.** The p50 time uses the throughput `p50`; the p90 time uses the
142
+ throughput **`p10`**, because for a rate the slow side is the low percentile. The length
143
+ heuristic contributes its own p50/p90, and the two compose into `total_s`.
144
+
145
+ Measured throughput, as of the `updated_at` in the table:
146
+
147
+ | model | TTFT p50 / p90 | tokens/s p50 / p10 | samples |
148
+ |---|---|---|---|
149
+ | gpt-4.1-mini | 0.69 s / 1.622 s | 139.2 / 119.1 | 10 |
150
+ | gpt-4.1 | 0.76 s / 2.229 s | 111.3 / 90.5 | 10 |
151
+ | claude-haiku-4-5 | 0.67 s / 0.686 s | 83.4 / 79.5 | 10 |
152
+ | claude-sonnet-4-5 | 0.86 s / 1.355 s | 36.8 / 34.6 | 40 |
153
+ | gpt-5@low | 9.5 s / 17.52 s | 123.0 / 69.4 | 10 |
154
+
155
+ On reasoning models the TTFT column absorbs hidden thinking time, which is why it is large and
156
+ why those rows are experimental.
157
+
158
+ ## Streaming ETA
159
+
160
+ ```python
161
+ from openai import OpenAI
162
+ import hmft
163
+
164
+ client = hmft.wrap_openai(OpenAI())
165
+ stream = client.chat.completions.create(
166
+ model="gpt-4.1-mini", stream=True,
167
+ messages=[{"role": "user", "content": "Explain how bicycles stay upright in two paragraphs."}],
168
+ )
169
+ print(stream.estimate) # pre-call band
170
+ for chunk in stream:
171
+ print(stream.eta(), end="\r") # live: blends the observed rate in after a few tokens
172
+ print(stream.result) # actual vs estimated
173
+ ```
174
+
175
+ `hmft.wrap_anthropic(Anthropic())` is the same shape around `client.messages.stream(...)`.
176
+ Wrappers are sync-only in v1; async is a v1.x item.
177
+
178
+ ## Filling the throughput table
179
+
180
+ ```bash
181
+ export OPENAI_API_KEY=... # and/or ANTHROPIC_API_KEY, OPENROUTER_API_KEY
182
+ python scripts/benchmark.py --all --dry-run # print the plan, make no calls
183
+ python scripts/benchmark.py --provider anthropic --models claude-haiku-4-5 --runs 3
184
+ ```
185
+
186
+ Each run sends two synthetic prompts and records only token counts and timings.
187
+ `name@effort` (for example `gpt-5@low`) sets `reasoning_effort` and gets its own row.
188
+
189
+ ## Known limits
190
+
191
+ - Output-length heuristics are rules, not a model. Expect the p50 to be off by 2x on
192
+ open-ended prompts; the p90 band is what to plan around.
193
+ - Reasoning models spend most of their wall time on hidden tokens the heuristics cannot see.
194
+ - Non-OpenAI token counts use the o200k tokenizer as a proxy, typically within 10 to 20%.
195
+ - Image and tool-result content blocks are not counted.
196
+ - Talk-duration cues are validated 2 to 45 minutes; above 45 is extrapolation. The p90 held on
197
+ 29 of 30 measured talks, but the p50 is biased per model: gpt-4.1-mini writes far less than
198
+ the estimate on long talks, Claude models somewhat more.
199
+ - Provider latency drifts hour to hour; `measured_at` tells you how stale a row is.
200
+
201
+ ## Tests
202
+
203
+ ```bash
204
+ pip install -e ".[dev]"
205
+ python -m pytest
206
+ ```
207
+
208
+ All tests use synthetic prompts and fake clients, and the suite makes no network calls —
209
+ `tests/test_no_network.py` enforces that. See `CONTRIBUTING.md` for the held-out rule and the
210
+ version-bump rule. `BASELINE.md` is the frozen v1 reference and `RESULTS.md` records every
211
+ measurement since.
212
+
213
+ ## License
214
+
215
+ Apache-2.0. See `LICENSE`.