jev-ultralightspeed 0.1.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.
- jev_ultralightspeed-0.1.0/LICENSE +210 -0
- jev_ultralightspeed-0.1.0/PKG-INFO +240 -0
- jev_ultralightspeed-0.1.0/README.md +216 -0
- jev_ultralightspeed-0.1.0/pyproject.toml +32 -0
- jev_ultralightspeed-0.1.0/setup.cfg +4 -0
- jev_ultralightspeed-0.1.0/src/jev_ultralightspeed/__init__.py +478 -0
- jev_ultralightspeed-0.1.0/src/jev_ultralightspeed/_http2.py +141 -0
- jev_ultralightspeed-0.1.0/src/jev_ultralightspeed.egg-info/PKG-INFO +240 -0
- jev_ultralightspeed-0.1.0/src/jev_ultralightspeed.egg-info/SOURCES.txt +11 -0
- jev_ultralightspeed-0.1.0/src/jev_ultralightspeed.egg-info/dependency_links.txt +1 -0
- jev_ultralightspeed-0.1.0/src/jev_ultralightspeed.egg-info/requires.txt +7 -0
- jev_ultralightspeed-0.1.0/src/jev_ultralightspeed.egg-info/top_level.txt +1 -0
- jev_ultralightspeed-0.1.0/tests/test_client.py +231 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
jev-ultralightspeed
|
|
2
|
+
Copyright 2026 Alex Kwon <ask@collapseindex.org>
|
|
3
|
+
https://github.com/collapseindex/jev-ultralightspeed
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0. Full text follows.
|
|
6
|
+
|
|
7
|
+
------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Apache License
|
|
11
|
+
Version 2.0, January 2004
|
|
12
|
+
http://www.apache.org/licenses/
|
|
13
|
+
|
|
14
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
15
|
+
|
|
16
|
+
1. Definitions.
|
|
17
|
+
|
|
18
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
19
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
20
|
+
|
|
21
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
22
|
+
the copyright owner that is granting the License.
|
|
23
|
+
|
|
24
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
25
|
+
other entities that control, are controlled by, or are under common
|
|
26
|
+
control with that entity. For the purposes of this definition,
|
|
27
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
28
|
+
direction or management of such entity, whether by contract or
|
|
29
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
30
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
31
|
+
|
|
32
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
33
|
+
exercising permissions granted by this License.
|
|
34
|
+
|
|
35
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
36
|
+
including but not limited to software source code, documentation
|
|
37
|
+
source, and configuration files.
|
|
38
|
+
|
|
39
|
+
"Object" form shall mean any form resulting from mechanical
|
|
40
|
+
transformation or translation of a Source form, including but
|
|
41
|
+
not limited to compiled object code, generated documentation,
|
|
42
|
+
and conversions to other media types.
|
|
43
|
+
|
|
44
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
45
|
+
Object form, made available under the License, as indicated by a
|
|
46
|
+
copyright notice that is included in or attached to the work
|
|
47
|
+
(an example is provided in the Appendix below).
|
|
48
|
+
|
|
49
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
50
|
+
form, that is based on (or derived from) the Work and for which the
|
|
51
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
52
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
53
|
+
of this License, Derivative Works shall not include works that remain
|
|
54
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
55
|
+
the Work and Derivative Works thereof.
|
|
56
|
+
|
|
57
|
+
"Contribution" shall mean any work of authorship, including
|
|
58
|
+
the original version of the Work and any modifications or additions
|
|
59
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
60
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
61
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
62
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
63
|
+
means any form of electronic, verbal, or written communication sent
|
|
64
|
+
to the Licensor or its representatives, including but not limited to
|
|
65
|
+
communication on electronic mailing lists, source code control systems,
|
|
66
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
67
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
68
|
+
excluding communication that is conspicuously marked or otherwise
|
|
69
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
70
|
+
|
|
71
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
72
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
73
|
+
subsequently incorporated within the Work.
|
|
74
|
+
|
|
75
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
79
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
80
|
+
Work and such Derivative Works in Source or Object form.
|
|
81
|
+
|
|
82
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
(except as stated in this section) patent license to make, have made,
|
|
86
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
87
|
+
where such license applies only to those patent claims licensable
|
|
88
|
+
by such Contributor that are necessarily infringed by their
|
|
89
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
90
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
91
|
+
institute patent litigation against any entity (including a
|
|
92
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
93
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
94
|
+
or contributory patent infringement, then any patent licenses
|
|
95
|
+
granted to You under this License for that Work shall terminate
|
|
96
|
+
as of the date such litigation is filed.
|
|
97
|
+
|
|
98
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
99
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
100
|
+
modifications, and in Source or Object form, provided that You
|
|
101
|
+
meet the following conditions:
|
|
102
|
+
|
|
103
|
+
(a) You must give any other recipients of the Work or
|
|
104
|
+
Derivative Works a copy of this License; and
|
|
105
|
+
|
|
106
|
+
(b) You must cause any modified files to carry prominent notices
|
|
107
|
+
stating that You changed the files; and
|
|
108
|
+
|
|
109
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
110
|
+
that You distribute, all copyright, patent, trademark, and
|
|
111
|
+
attribution notices from the Source form of the Work,
|
|
112
|
+
excluding those notices that do not pertain to any part of
|
|
113
|
+
the Derivative Works; and
|
|
114
|
+
|
|
115
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
116
|
+
distribution, then any Derivative Works that You distribute must
|
|
117
|
+
include a readable copy of the attribution notices contained
|
|
118
|
+
within such NOTICE file, excluding those notices that do not
|
|
119
|
+
pertain to any part of the Derivative Works, in at least one
|
|
120
|
+
of the following places: within a NOTICE text file distributed
|
|
121
|
+
as part of the Derivative Works; within the Source form or
|
|
122
|
+
documentation, if provided along with the Derivative Works; or,
|
|
123
|
+
within a display generated by the Derivative Works, if and
|
|
124
|
+
wherever such third-party notices normally appear. The contents
|
|
125
|
+
of the NOTICE file are for informational purposes only and
|
|
126
|
+
do not modify the License. You may add Your own attribution
|
|
127
|
+
notices within Derivative Works that You distribute, alongside
|
|
128
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
129
|
+
that such additional attribution notices cannot be construed
|
|
130
|
+
as modifying the License.
|
|
131
|
+
|
|
132
|
+
You may add Your own copyright statement to Your modifications and
|
|
133
|
+
may provide additional or different license terms and conditions
|
|
134
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
135
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
136
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
137
|
+
the conditions stated in this License.
|
|
138
|
+
|
|
139
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
140
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
141
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
142
|
+
this License, without any additional terms or conditions.
|
|
143
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
144
|
+
the terms of any separate license agreement you may have executed
|
|
145
|
+
with Licensor regarding such Contributions.
|
|
146
|
+
|
|
147
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
148
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
149
|
+
except as required for reasonable and customary use in describing the
|
|
150
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
151
|
+
|
|
152
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
153
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
154
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
155
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
156
|
+
implied, including, without limitation, any warranties or conditions
|
|
157
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
158
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
159
|
+
appropriateness of using or redistributing the Work and assume any
|
|
160
|
+
risks associated with Your exercise of permissions under this License.
|
|
161
|
+
|
|
162
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
163
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
164
|
+
unless required by applicable law (such as deliberate and grossly
|
|
165
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
166
|
+
liable to You for damages, including any direct, indirect, special,
|
|
167
|
+
incidental, or consequential damages of any character arising as a
|
|
168
|
+
result of this License or out of the use or inability to use the
|
|
169
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
170
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
171
|
+
other commercial damages or losses), even if such Contributor
|
|
172
|
+
has been advised of the possibility of such damages.
|
|
173
|
+
|
|
174
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
175
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
176
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
177
|
+
or other liability obligations and/or rights consistent with this
|
|
178
|
+
License. However, in accepting such obligations, You may act only
|
|
179
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
180
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
181
|
+
defend, and hold each Contributor harmless for any liability
|
|
182
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
183
|
+
of your accepting any such warranty or additional liability.
|
|
184
|
+
|
|
185
|
+
END OF TERMS AND CONDITIONS
|
|
186
|
+
|
|
187
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
188
|
+
|
|
189
|
+
To apply the Apache License to your work, attach the following
|
|
190
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
191
|
+
replaced with your own identifying information. (Don't include
|
|
192
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
193
|
+
comment syntax for the file format. We also recommend that a
|
|
194
|
+
file or class name and description of purpose be included on the
|
|
195
|
+
same "printed page" as the copyright notice for easier
|
|
196
|
+
identification within third-party archives.
|
|
197
|
+
|
|
198
|
+
Copyright 2026 Alex Kwon <ask@collapseindex.org>
|
|
199
|
+
|
|
200
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
201
|
+
you may not use this file except in compliance with the License.
|
|
202
|
+
You may obtain a copy of the License at
|
|
203
|
+
|
|
204
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
205
|
+
|
|
206
|
+
Unless required by applicable law or agreed to in writing, software
|
|
207
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
208
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
209
|
+
See the License for the specific language governing permissions and
|
|
210
|
+
limitations under the License.
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jev-ultralightspeed
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A pile of text, one question about each: bulk classification with TypeSafe's Jev at 16x the throughput and 41% less money, same accuracy.
|
|
5
|
+
Author-email: Alex Kwon <ask@collapseindex.org>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/collapseindex/jev-ultralightspeed
|
|
8
|
+
Project-URL: Source, https://github.com/collapseindex/jev-ultralightspeed
|
|
9
|
+
Keywords: jev,typesafe,llm,classification,throughput,batching
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: fast
|
|
19
|
+
Requires-Dist: httpx[http2]>=0.27; extra == "fast"
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
22
|
+
Requires-Dist: httpx[http2]>=0.27; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# jev-ultralightspeed
|
|
26
|
+
|
|
27
|
+
**v0.1.0** · Apache-2.0 · no required dependencies
|
|
28
|
+
|
|
29
|
+
<img src="docs/infographic.png" alt="Faster, cheaper, same accuracy: hundreds of items a second against dozens, with agreement against human labels unchanged" width="100%" />
|
|
30
|
+
|
|
31
|
+
**You have a pile of text and one question about each.** Fifty thousand support tickets to triage.
|
|
32
|
+
A quarter of reviews to sort by sentiment. A month of logs to flag. A column to backfill on a table
|
|
33
|
+
you already have. This answers the question for all of them, with
|
|
34
|
+
[TypeSafe's Jev](https://typesafe.ai), in the time it takes to get a coffee.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from jev_ultralightspeed import classify
|
|
38
|
+
|
|
39
|
+
answers = classify(tickets, "Does this message need a human to act on it today?")
|
|
40
|
+
urgent = [a.item for a in answers if a.yes]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**15.9x the throughput of one request per item, 41% less money, and the same accuracy.** Measured
|
|
44
|
+
over 30,000 judgements against human labels, in one run, with a script in this repository.
|
|
45
|
+
|
|
46
|
+
**Not for one item at a time.** If somebody is waiting on the answer, call the API directly: packing
|
|
47
|
+
makes a single item slower, not faster. This is for a queue.
|
|
48
|
+
|
|
49
|
+
Not affiliated with TypeSafe; the hedgehog is a parody and belongs to nobody.
|
|
50
|
+
|
|
51
|
+
## The benchmark
|
|
52
|
+
|
|
53
|
+
30,000 judgements over the 1,347 completions in
|
|
54
|
+
[dinostomp's](https://github.com/collapseindex/dinostomp) `xstest-refusal` pod, labelled
|
|
55
|
+
compliance, refusal or partial by two human annotators, each completion seen about 22 times. Two
|
|
56
|
+
arms, identical but for the shape of the requests. This is not Jev against another model: it is
|
|
57
|
+
**jev-1.13.0 against itself**, same question, same items, same criteria.
|
|
58
|
+
|
|
59
|
+
| | regular jev | jev + ultralightspeed |
|
|
60
|
+
| --- | ---: | ---: |
|
|
61
|
+
| throughput | 41.1 items/s | **653.4 items/s** |
|
|
62
|
+
| wall clock | 12 min 11 s | **46 seconds** |
|
|
63
|
+
| requests | 30,000 | 942 |
|
|
64
|
+
| cost | $0.729 | **$0.430** |
|
|
65
|
+
| agreement with the human labels | 89.3% (89.0 to 89.7) | **89.2% (88.9 to 89.6)** |
|
|
66
|
+
| same answer across an item's repeats | 99.6% | 98.0% |
|
|
67
|
+
| failed | 0 | 0 |
|
|
68
|
+
| retried | 1 | 63 |
|
|
69
|
+
|
|
70
|
+
**15.9x the throughput, 41% less money, and the accuracy is the same**: 89.3% against 89.2%, with
|
|
71
|
+
30,000 judgements behind each figure and the intervals sitting on top of each other.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install "jev-ultralightspeed[fast]"
|
|
75
|
+
git clone https://github.com/collapseindex/dinostomp.git ../dinostomp
|
|
76
|
+
TYPESAFE_API_KEY=... python bench_eval.py # about 13 minutes, about $1.20
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Three things in that table are worth reading twice.
|
|
80
|
+
|
|
81
|
+
**The baseline is not slow.** It is one item per request with the same eight requests in flight, so
|
|
82
|
+
the 15.9x is against a client that is already parallel. Against an actual sequential loop it is far
|
|
83
|
+
larger and far less interesting.
|
|
84
|
+
|
|
85
|
+
**Sixty-three retries, and nothing failed.** Packing 32 deep with 8 in flight does hit transient
|
|
86
|
+
limits at volume. The client backs off and sends them again, which is why this arm came in at 653
|
|
87
|
+
items/s rather than the 800 it reaches on short bursts. Retries are counted in `usage.retries`, so
|
|
88
|
+
this is a number rather than an absence of complaints.
|
|
89
|
+
|
|
90
|
+
**Aggregate accuracy is identical; individual answers are slightly less repeatable.** Ask about the
|
|
91
|
+
same completion 22 times and the unpacked client gives the same label 99.6% of the time, the packed
|
|
92
|
+
one 98.0%. So pack freely when you want the total, and keep the pack size fixed when you are
|
|
93
|
+
comparing item by item across runs.
|
|
94
|
+
|
|
95
|
+
Shorter items do better than this on every axis, because the per-item text is a smaller share of
|
|
96
|
+
each request: a million synthetic support messages (138 tokens each) ran at 1,135 items/s, 14.7
|
|
97
|
+
minutes and $4.99 for the lot, over 31,400 requests with nothing retried. `soak.py --items 1000000`
|
|
98
|
+
reproduces that, and it is a different corpus, so it is a footnote here rather than a headline.
|
|
99
|
+
|
|
100
|
+
## How
|
|
101
|
+
|
|
102
|
+
Nothing clever. Four things the obvious loop does not do, in order of how much they gave:
|
|
103
|
+
|
|
104
|
+
1. **Pack.** Several items go in one request as `item_1..item_N`, each with its own question that
|
|
105
|
+
names the item it judges. One round trip covers thirty-two items, and the shared overhead is paid
|
|
106
|
+
once instead of thirty-two times. This is where both the speed and the token saving come from.
|
|
107
|
+
2. **Parallel.** Several packed requests in flight, under a sliding-window limiter set below
|
|
108
|
+
TypeSafe's published 1,200 requests a minute.
|
|
109
|
+
3. **One connection, kept open, multiplexed.** With httpx and h2 installed, every request in flight
|
|
110
|
+
shares a single HTTP/2 connection on one event loop, which measured about twice a thread per
|
|
111
|
+
connection on HTTP/1.1; keeping it open between calls rather than rebuilding it per batch was
|
|
112
|
+
worth another 2.5x. The transport idea is lifted from
|
|
113
|
+
[browser-use/jev-ultrafast](https://github.com/browser-use/jev-ultrafast), who got there first.
|
|
114
|
+
4. **Never ask twice.** Identical text within a batch is asked once; a bounded cache keyed by model,
|
|
115
|
+
question and text answers repeats for free.
|
|
116
|
+
|
|
117
|
+
## Install
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pip install "jev-ultralightspeed[fast] @ git+https://github.com/collapseindex/jev-ultralightspeed"
|
|
121
|
+
export TYPESAFE_API_KEY=...
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The `[fast]` extra pulls in httpx and h2, which measured about twice the standard library path.
|
|
125
|
+
Without it the client still works on the standard library alone:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pip install "git+https://github.com/collapseindex/jev-ultralightspeed"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Not on PyPI yet.
|
|
132
|
+
|
|
133
|
+
## Use
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from jev_ultralightspeed import Client
|
|
137
|
+
|
|
138
|
+
client = Client(pack=8, workers=8) # the defaults are pack=8, workers=4
|
|
139
|
+
client.warm() # open the connections before the work arrives
|
|
140
|
+
|
|
141
|
+
answers = client.classify(
|
|
142
|
+
messages,
|
|
143
|
+
"Does this message need a human to act on it today?",
|
|
144
|
+
criteria={"true": "something is broken or costing money right now",
|
|
145
|
+
"false": "a question or a thank-you that can wait"},
|
|
146
|
+
on_progress=lambda done, total: print(f"{done}/{total}", end="\r"),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
for answer in answers:
|
|
150
|
+
print(answer.label, round(answer.p, 2), answer.item[:60])
|
|
151
|
+
|
|
152
|
+
print(client.usage) # 256 items in 1.16s (221.1/s, 32 requests, 156 tokens/item, $0.00166)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Pick-one questions work the same way:
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
answers = classify(tickets, "Which team should handle this?", options={
|
|
159
|
+
"billing": "payments, invoices, refunds",
|
|
160
|
+
"technical": "errors, outages, integrations",
|
|
161
|
+
"account": "logins, passwords, security",
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Every answer carries `item`, `label`, `p`, `distribution`, `confidence` and `kind`, and comes back in
|
|
166
|
+
the order you passed the items in, however the requests were shuffled to get there.
|
|
167
|
+
|
|
168
|
+
### Knobs
|
|
169
|
+
|
|
170
|
+
| argument | default | what it does |
|
|
171
|
+
| --- | --- | --- |
|
|
172
|
+
| `pack` | 8 | items per request. Higher is faster and cheaper, and slower per request. On short items: pack 8 does 320 items/s, pack 32 does 1,130. |
|
|
173
|
+
| `workers` | 4 | requests in flight. |
|
|
174
|
+
| `transport` | `auto` | `http2` when httpx is installed, otherwise `threads`. |
|
|
175
|
+
| `requests_per_minute` | 1000 | the ceiling the limiter holds, under TypeSafe's published 1,200. |
|
|
176
|
+
| `cache` | True | answer repeats from memory, keyed by model, question and text. |
|
|
177
|
+
| `model` | `jev-latest` | passed straight through. |
|
|
178
|
+
| `url` | the Jev endpoint | point it at a gateway or a mock. |
|
|
179
|
+
|
|
180
|
+
## What it does not do
|
|
181
|
+
|
|
182
|
+
- **It does not change your question.** The only difference between a packed question and a single
|
|
183
|
+
one is the sentence naming which item to judge. There is no bitstring trick and no compressed
|
|
184
|
+
output format, because Jev returns a structured probability per question rather than generated
|
|
185
|
+
text: the output is already about twenty tokens per request.
|
|
186
|
+
- **It does not cache across processes.** The cache lives in the client, in memory, bounded at
|
|
187
|
+
10,000 entries.
|
|
188
|
+
- **It does not hide failures.** Retries cover 429, 500, 502, 503, 504 and 529 with backoff; anything
|
|
189
|
+
else is raised with what the API said.
|
|
190
|
+
- **It is not an eval harness.** It makes a judge fast, not trustworthy. See Related below.
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
pip install pytest
|
|
196
|
+
python -m pytest tests -q # 21 tests, no network, no key needed
|
|
197
|
+
|
|
198
|
+
TYPESAFE_API_KEY=... python bench_eval.py # the table above, ~13 min, ~$1.20
|
|
199
|
+
TYPESAFE_API_KEY=... python bench.py --items 256 # pack and concurrency sweep, ~5 cents
|
|
200
|
+
TYPESAFE_API_KEY=... python soak.py --items 100000 # sustained load, ~50 cents
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
The tests replace the one method that talks to the API, so the packing, the deduplication, the cache,
|
|
204
|
+
the ordering, the limiter and the error paths are all checked offline.
|
|
205
|
+
|
|
206
|
+
## Related
|
|
207
|
+
|
|
208
|
+
Three tools, one workflow, all Apache-2.0:
|
|
209
|
+
|
|
210
|
+
Costs are input tokens at TypeSafe's published $0.042 per million for jev-1.13.0, which is the only
|
|
211
|
+
rate they list; output tokens are counted but not priced. Every dollar figure here was checked
|
|
212
|
+
against the account balance after the run.
|
|
213
|
+
|
|
214
|
+
- **[dinostomp](https://github.com/collapseindex/dinostomp)** is the harness the benchmark above was
|
|
215
|
+
measured against: pods of labelled items, pre-registered thresholds, a checks registry and a
|
|
216
|
+
findings ledger. It is where you go when the question is whether a judge is any good, not how
|
|
217
|
+
fast it runs. The 1,347 labelled completions in the table are one of its audit pods.
|
|
218
|
+
- **[jev-builder](https://collapseindex.github.io/jev-builder/)** writes the request in the first
|
|
219
|
+
place: paste your text, describe the question, and get something you can paste here.
|
|
220
|
+
- **jev-ultralightspeed**, this repository, is for when the question already works and there are a
|
|
221
|
+
million rows waiting.
|
|
222
|
+
|
|
223
|
+
If any of it saves you an afternoon, [sponsorship](https://github.com/sponsors/collapseindex) keeps
|
|
224
|
+
it maintained. Not required, and nothing here is gated.
|
|
225
|
+
|
|
226
|
+
## Security
|
|
227
|
+
|
|
228
|
+
The key comes from your environment, goes to one endpoint and is never logged, printed, put in an
|
|
229
|
+
exception or written to disk. What the library sends, what it keeps in memory, and what it does not
|
|
230
|
+
protect you from: [SECURITY.md](SECURITY.md).
|
|
231
|
+
|
|
232
|
+
## Contributing
|
|
233
|
+
|
|
234
|
+
Issues and pull requests are welcome. The rules that matter: no required dependencies, never log the
|
|
235
|
+
key, and a performance claim needs a measurement rather than an opinion about how HTTP works. See
|
|
236
|
+
[CONTRIBUTING.md](CONTRIBUTING.md).
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
[Apache-2.0](LICENSE). Not affiliated with TypeSafe.
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# jev-ultralightspeed
|
|
2
|
+
|
|
3
|
+
**v0.1.0** · Apache-2.0 · no required dependencies
|
|
4
|
+
|
|
5
|
+
<img src="docs/infographic.png" alt="Faster, cheaper, same accuracy: hundreds of items a second against dozens, with agreement against human labels unchanged" width="100%" />
|
|
6
|
+
|
|
7
|
+
**You have a pile of text and one question about each.** Fifty thousand support tickets to triage.
|
|
8
|
+
A quarter of reviews to sort by sentiment. A month of logs to flag. A column to backfill on a table
|
|
9
|
+
you already have. This answers the question for all of them, with
|
|
10
|
+
[TypeSafe's Jev](https://typesafe.ai), in the time it takes to get a coffee.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from jev_ultralightspeed import classify
|
|
14
|
+
|
|
15
|
+
answers = classify(tickets, "Does this message need a human to act on it today?")
|
|
16
|
+
urgent = [a.item for a in answers if a.yes]
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**15.9x the throughput of one request per item, 41% less money, and the same accuracy.** Measured
|
|
20
|
+
over 30,000 judgements against human labels, in one run, with a script in this repository.
|
|
21
|
+
|
|
22
|
+
**Not for one item at a time.** If somebody is waiting on the answer, call the API directly: packing
|
|
23
|
+
makes a single item slower, not faster. This is for a queue.
|
|
24
|
+
|
|
25
|
+
Not affiliated with TypeSafe; the hedgehog is a parody and belongs to nobody.
|
|
26
|
+
|
|
27
|
+
## The benchmark
|
|
28
|
+
|
|
29
|
+
30,000 judgements over the 1,347 completions in
|
|
30
|
+
[dinostomp's](https://github.com/collapseindex/dinostomp) `xstest-refusal` pod, labelled
|
|
31
|
+
compliance, refusal or partial by two human annotators, each completion seen about 22 times. Two
|
|
32
|
+
arms, identical but for the shape of the requests. This is not Jev against another model: it is
|
|
33
|
+
**jev-1.13.0 against itself**, same question, same items, same criteria.
|
|
34
|
+
|
|
35
|
+
| | regular jev | jev + ultralightspeed |
|
|
36
|
+
| --- | ---: | ---: |
|
|
37
|
+
| throughput | 41.1 items/s | **653.4 items/s** |
|
|
38
|
+
| wall clock | 12 min 11 s | **46 seconds** |
|
|
39
|
+
| requests | 30,000 | 942 |
|
|
40
|
+
| cost | $0.729 | **$0.430** |
|
|
41
|
+
| agreement with the human labels | 89.3% (89.0 to 89.7) | **89.2% (88.9 to 89.6)** |
|
|
42
|
+
| same answer across an item's repeats | 99.6% | 98.0% |
|
|
43
|
+
| failed | 0 | 0 |
|
|
44
|
+
| retried | 1 | 63 |
|
|
45
|
+
|
|
46
|
+
**15.9x the throughput, 41% less money, and the accuracy is the same**: 89.3% against 89.2%, with
|
|
47
|
+
30,000 judgements behind each figure and the intervals sitting on top of each other.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install "jev-ultralightspeed[fast]"
|
|
51
|
+
git clone https://github.com/collapseindex/dinostomp.git ../dinostomp
|
|
52
|
+
TYPESAFE_API_KEY=... python bench_eval.py # about 13 minutes, about $1.20
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Three things in that table are worth reading twice.
|
|
56
|
+
|
|
57
|
+
**The baseline is not slow.** It is one item per request with the same eight requests in flight, so
|
|
58
|
+
the 15.9x is against a client that is already parallel. Against an actual sequential loop it is far
|
|
59
|
+
larger and far less interesting.
|
|
60
|
+
|
|
61
|
+
**Sixty-three retries, and nothing failed.** Packing 32 deep with 8 in flight does hit transient
|
|
62
|
+
limits at volume. The client backs off and sends them again, which is why this arm came in at 653
|
|
63
|
+
items/s rather than the 800 it reaches on short bursts. Retries are counted in `usage.retries`, so
|
|
64
|
+
this is a number rather than an absence of complaints.
|
|
65
|
+
|
|
66
|
+
**Aggregate accuracy is identical; individual answers are slightly less repeatable.** Ask about the
|
|
67
|
+
same completion 22 times and the unpacked client gives the same label 99.6% of the time, the packed
|
|
68
|
+
one 98.0%. So pack freely when you want the total, and keep the pack size fixed when you are
|
|
69
|
+
comparing item by item across runs.
|
|
70
|
+
|
|
71
|
+
Shorter items do better than this on every axis, because the per-item text is a smaller share of
|
|
72
|
+
each request: a million synthetic support messages (138 tokens each) ran at 1,135 items/s, 14.7
|
|
73
|
+
minutes and $4.99 for the lot, over 31,400 requests with nothing retried. `soak.py --items 1000000`
|
|
74
|
+
reproduces that, and it is a different corpus, so it is a footnote here rather than a headline.
|
|
75
|
+
|
|
76
|
+
## How
|
|
77
|
+
|
|
78
|
+
Nothing clever. Four things the obvious loop does not do, in order of how much they gave:
|
|
79
|
+
|
|
80
|
+
1. **Pack.** Several items go in one request as `item_1..item_N`, each with its own question that
|
|
81
|
+
names the item it judges. One round trip covers thirty-two items, and the shared overhead is paid
|
|
82
|
+
once instead of thirty-two times. This is where both the speed and the token saving come from.
|
|
83
|
+
2. **Parallel.** Several packed requests in flight, under a sliding-window limiter set below
|
|
84
|
+
TypeSafe's published 1,200 requests a minute.
|
|
85
|
+
3. **One connection, kept open, multiplexed.** With httpx and h2 installed, every request in flight
|
|
86
|
+
shares a single HTTP/2 connection on one event loop, which measured about twice a thread per
|
|
87
|
+
connection on HTTP/1.1; keeping it open between calls rather than rebuilding it per batch was
|
|
88
|
+
worth another 2.5x. The transport idea is lifted from
|
|
89
|
+
[browser-use/jev-ultrafast](https://github.com/browser-use/jev-ultrafast), who got there first.
|
|
90
|
+
4. **Never ask twice.** Identical text within a batch is asked once; a bounded cache keyed by model,
|
|
91
|
+
question and text answers repeats for free.
|
|
92
|
+
|
|
93
|
+
## Install
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install "jev-ultralightspeed[fast] @ git+https://github.com/collapseindex/jev-ultralightspeed"
|
|
97
|
+
export TYPESAFE_API_KEY=...
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The `[fast]` extra pulls in httpx and h2, which measured about twice the standard library path.
|
|
101
|
+
Without it the client still works on the standard library alone:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install "git+https://github.com/collapseindex/jev-ultralightspeed"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Not on PyPI yet.
|
|
108
|
+
|
|
109
|
+
## Use
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from jev_ultralightspeed import Client
|
|
113
|
+
|
|
114
|
+
client = Client(pack=8, workers=8) # the defaults are pack=8, workers=4
|
|
115
|
+
client.warm() # open the connections before the work arrives
|
|
116
|
+
|
|
117
|
+
answers = client.classify(
|
|
118
|
+
messages,
|
|
119
|
+
"Does this message need a human to act on it today?",
|
|
120
|
+
criteria={"true": "something is broken or costing money right now",
|
|
121
|
+
"false": "a question or a thank-you that can wait"},
|
|
122
|
+
on_progress=lambda done, total: print(f"{done}/{total}", end="\r"),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
for answer in answers:
|
|
126
|
+
print(answer.label, round(answer.p, 2), answer.item[:60])
|
|
127
|
+
|
|
128
|
+
print(client.usage) # 256 items in 1.16s (221.1/s, 32 requests, 156 tokens/item, $0.00166)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Pick-one questions work the same way:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
answers = classify(tickets, "Which team should handle this?", options={
|
|
135
|
+
"billing": "payments, invoices, refunds",
|
|
136
|
+
"technical": "errors, outages, integrations",
|
|
137
|
+
"account": "logins, passwords, security",
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Every answer carries `item`, `label`, `p`, `distribution`, `confidence` and `kind`, and comes back in
|
|
142
|
+
the order you passed the items in, however the requests were shuffled to get there.
|
|
143
|
+
|
|
144
|
+
### Knobs
|
|
145
|
+
|
|
146
|
+
| argument | default | what it does |
|
|
147
|
+
| --- | --- | --- |
|
|
148
|
+
| `pack` | 8 | items per request. Higher is faster and cheaper, and slower per request. On short items: pack 8 does 320 items/s, pack 32 does 1,130. |
|
|
149
|
+
| `workers` | 4 | requests in flight. |
|
|
150
|
+
| `transport` | `auto` | `http2` when httpx is installed, otherwise `threads`. |
|
|
151
|
+
| `requests_per_minute` | 1000 | the ceiling the limiter holds, under TypeSafe's published 1,200. |
|
|
152
|
+
| `cache` | True | answer repeats from memory, keyed by model, question and text. |
|
|
153
|
+
| `model` | `jev-latest` | passed straight through. |
|
|
154
|
+
| `url` | the Jev endpoint | point it at a gateway or a mock. |
|
|
155
|
+
|
|
156
|
+
## What it does not do
|
|
157
|
+
|
|
158
|
+
- **It does not change your question.** The only difference between a packed question and a single
|
|
159
|
+
one is the sentence naming which item to judge. There is no bitstring trick and no compressed
|
|
160
|
+
output format, because Jev returns a structured probability per question rather than generated
|
|
161
|
+
text: the output is already about twenty tokens per request.
|
|
162
|
+
- **It does not cache across processes.** The cache lives in the client, in memory, bounded at
|
|
163
|
+
10,000 entries.
|
|
164
|
+
- **It does not hide failures.** Retries cover 429, 500, 502, 503, 504 and 529 with backoff; anything
|
|
165
|
+
else is raised with what the API said.
|
|
166
|
+
- **It is not an eval harness.** It makes a judge fast, not trustworthy. See Related below.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
pip install pytest
|
|
172
|
+
python -m pytest tests -q # 21 tests, no network, no key needed
|
|
173
|
+
|
|
174
|
+
TYPESAFE_API_KEY=... python bench_eval.py # the table above, ~13 min, ~$1.20
|
|
175
|
+
TYPESAFE_API_KEY=... python bench.py --items 256 # pack and concurrency sweep, ~5 cents
|
|
176
|
+
TYPESAFE_API_KEY=... python soak.py --items 100000 # sustained load, ~50 cents
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The tests replace the one method that talks to the API, so the packing, the deduplication, the cache,
|
|
180
|
+
the ordering, the limiter and the error paths are all checked offline.
|
|
181
|
+
|
|
182
|
+
## Related
|
|
183
|
+
|
|
184
|
+
Three tools, one workflow, all Apache-2.0:
|
|
185
|
+
|
|
186
|
+
Costs are input tokens at TypeSafe's published $0.042 per million for jev-1.13.0, which is the only
|
|
187
|
+
rate they list; output tokens are counted but not priced. Every dollar figure here was checked
|
|
188
|
+
against the account balance after the run.
|
|
189
|
+
|
|
190
|
+
- **[dinostomp](https://github.com/collapseindex/dinostomp)** is the harness the benchmark above was
|
|
191
|
+
measured against: pods of labelled items, pre-registered thresholds, a checks registry and a
|
|
192
|
+
findings ledger. It is where you go when the question is whether a judge is any good, not how
|
|
193
|
+
fast it runs. The 1,347 labelled completions in the table are one of its audit pods.
|
|
194
|
+
- **[jev-builder](https://collapseindex.github.io/jev-builder/)** writes the request in the first
|
|
195
|
+
place: paste your text, describe the question, and get something you can paste here.
|
|
196
|
+
- **jev-ultralightspeed**, this repository, is for when the question already works and there are a
|
|
197
|
+
million rows waiting.
|
|
198
|
+
|
|
199
|
+
If any of it saves you an afternoon, [sponsorship](https://github.com/sponsors/collapseindex) keeps
|
|
200
|
+
it maintained. Not required, and nothing here is gated.
|
|
201
|
+
|
|
202
|
+
## Security
|
|
203
|
+
|
|
204
|
+
The key comes from your environment, goes to one endpoint and is never logged, printed, put in an
|
|
205
|
+
exception or written to disk. What the library sends, what it keeps in memory, and what it does not
|
|
206
|
+
protect you from: [SECURITY.md](SECURITY.md).
|
|
207
|
+
|
|
208
|
+
## Contributing
|
|
209
|
+
|
|
210
|
+
Issues and pull requests are welcome. The rules that matter: no required dependencies, never log the
|
|
211
|
+
key, and a performance claim needs a measurement rather than an opinion about how HTTP works. See
|
|
212
|
+
[CONTRIBUTING.md](CONTRIBUTING.md).
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
[Apache-2.0](LICENSE). Not affiliated with TypeSafe.
|