headroom-winnow 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.
- headroom_winnow-0.2.0/.gitignore +11 -0
- headroom_winnow-0.2.0/LICENSE +202 -0
- headroom_winnow-0.2.0/NOTICE +17 -0
- headroom_winnow-0.2.0/PKG-INFO +279 -0
- headroom_winnow-0.2.0/README.md +247 -0
- headroom_winnow-0.2.0/headroom_winnow/__init__.py +31 -0
- headroom_winnow-0.2.0/headroom_winnow/backends.py +382 -0
- headroom_winnow-0.2.0/headroom_winnow/compressor.py +203 -0
- headroom_winnow-0.2.0/headroom_winnow/markers.py +59 -0
- headroom_winnow-0.2.0/headroom_winnow/selection.py +201 -0
- headroom_winnow-0.2.0/pyproject.toml +101 -0
- headroom_winnow-0.2.0/tests/conftest.py +58 -0
- headroom_winnow-0.2.0/tests/test_backends.py +93 -0
- headroom_winnow-0.2.0/tests/test_compressor.py +149 -0
- headroom_winnow-0.2.0/tests/test_markers.py +31 -0
- headroom_winnow-0.2.0/tests/test_real_model.py +60 -0
- headroom_winnow-0.2.0/tests/test_router.py +137 -0
- headroom_winnow-0.2.0/tests/test_selection.py +86 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
headroom-winnow
|
|
2
|
+
Copyright 2026 headroom-winnow contributors
|
|
3
|
+
|
|
4
|
+
This product is a plugin for Headroom (https://github.com/headroomlabs-ai/headroom),
|
|
5
|
+
licensed under the Apache License, Version 2.0. It implements Headroom's
|
|
6
|
+
``headroom.compressor`` contract and follows its coding conventions and tool
|
|
7
|
+
configuration.
|
|
8
|
+
|
|
9
|
+
This product uses the Squeez approach and models by KRLabs
|
|
10
|
+
(https://github.com/KRLabsOrg/squeez), licensed under the Apache License,
|
|
11
|
+
Version 2.0, including the model KRLabsOrg/verbatim-rag-modern-bert-v2 and the
|
|
12
|
+
dataset KRLabsOrg/tool-output-extraction-swebench.
|
|
13
|
+
|
|
14
|
+
The pooled model distributed in this project's releases is fine-tuned from
|
|
15
|
+
jhu-clsp/ettin-encoder-32m (https://huggingface.co/jhu-clsp/ettin-encoder-32m),
|
|
16
|
+
licensed under the MIT License, on the dataset above using Squeez's training
|
|
17
|
+
code.
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: headroom-winnow
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Winnow: task-aware pruning of coding-agent tool output for Headroom, powered by Squeez models
|
|
5
|
+
Project-URL: Homepage, https://github.com/RecepKurtulus/headroom-winnow
|
|
6
|
+
Project-URL: Issues, https://github.com/RecepKurtulus/headroom-winnow/issues
|
|
7
|
+
Project-URL: Benchmarks, https://github.com/RecepKurtulus/headroom-winnow/blob/main/benchmarks/RESULTS.md
|
|
8
|
+
Author: Recep Kurtulus
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: agents,compression,context,headroom,llm,squeez,winnow
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
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: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: headroom-ai<0.40,>=0.39
|
|
21
|
+
Provides-Extra: bench
|
|
22
|
+
Requires-Dist: datasets>=2.18; extra == 'bench'
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
25
|
+
Requires-Dist: numpy<2.3; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
28
|
+
Provides-Extra: model
|
|
29
|
+
Requires-Dist: torch>=2.1; extra == 'model'
|
|
30
|
+
Requires-Dist: transformers>=4.48; extra == 'model'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<img src="https://raw.githubusercontent.com/RecepKurtulus/headroom-winnow/main/docs/assets/logo.png" width="112" alt="Winnow logo">
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
<h1 align="center">Winnow</h1>
|
|
38
|
+
|
|
39
|
+
<p align="center">
|
|
40
|
+
<b>Separate the grain from the chaff in your coding agent's tool output.</b><br>
|
|
41
|
+
A task-aware pruner for <a href="https://github.com/headroomlabs-ai/headroom">Headroom</a>, powered by <a href="https://github.com/KRLabsOrg/squeez">Squeez</a> models.
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
<a href="https://github.com/RecepKurtulus/headroom-winnow/actions/workflows/ci.yml"><img src="https://github.com/RecepKurtulus/headroom-winnow/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
46
|
+
<img src="https://img.shields.io/badge/python-3.10%2B-blue" alt="Python 3.10+">
|
|
47
|
+
<img src="https://img.shields.io/badge/license-Apache--2.0-green" alt="Apache-2.0">
|
|
48
|
+
<a href="https://recepkurtulus.github.io/headroom-winnow/"><img src="https://img.shields.io/badge/docs-site-5c6bc0" alt="Docs"></a>
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
Coding agents spend most of their context on tool output: test runs, builds,
|
|
52
|
+
grep hits, logs. Usually only a handful of those lines matter for the agent's
|
|
53
|
+
next step. Winnow plugs a small model trained on real agent traces
|
|
54
|
+
into Headroom's compression pipeline. It keeps the lines the task needs, never
|
|
55
|
+
drops an error or a traceback, and turns everything else into retrievable
|
|
56
|
+
markers.
|
|
57
|
+
|
|
58
|
+
<p align="center"><img src="https://raw.githubusercontent.com/RecepKurtulus/headroom-winnow/main/docs/assets/demo.gif" width="760" alt="Winnow pruning a go build output from 1,838 to 479 tokens"></p>
|
|
59
|
+
|
|
60
|
+
> **41% fewer tokens with 0.85 gold-line recall, zero lost error lines, and
|
|
61
|
+
> 0.29 s median latency on a consumer GPU.** At equal compression it keeps
|
|
62
|
+
> 15-27 points more of the relevant lines than Headroom's built-in
|
|
63
|
+
> `relevance_split`. [Full results →](https://github.com/RecepKurtulus/headroom-winnow/blob/main/benchmarks/RESULTS.md)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Example
|
|
68
|
+
|
|
69
|
+
The agent asks *"Find the build output block that reports the missing
|
|
70
|
+
`GetObject` method in the `UserHandler` implementation of
|
|
71
|
+
`storage.StorageService`"* and runs `go build ./...`:
|
|
72
|
+
|
|
73
|
+
<table>
|
|
74
|
+
<tr><th>Before: 119 lines, 1,838 tokens</th><th>After: 32 lines, 479 tokens (−74%)</th></tr>
|
|
75
|
+
<tr><td>
|
|
76
|
+
|
|
77
|
+
```text
|
|
78
|
+
$ go build ./...
|
|
79
|
+
# .../handlers/user_handler.go:23:12: cannot use h
|
|
80
|
+
(type *UserHandler) as type storage.StorageService:
|
|
81
|
+
*UserHandler does not implement storage.StorageService
|
|
82
|
+
(missing GetObject method)
|
|
83
|
+
# .../handlers/order_handler.go:45:9: cannot use orderSvc ...
|
|
84
|
+
# .../auth/auth.go:12:5: import cycle not allowed
|
|
85
|
+
# .../permissions/perm.go:8:2: import cycle not allowed
|
|
86
|
+
# .../api/v2/client.go:67:15: undefined: storage.ObjectMetadata
|
|
87
|
+
# .../api/v2/client.go:88:20: cannot assign string literal ...
|
|
88
|
+
# .../database/migration.go:33:10: cannot find module ...
|
|
89
|
+
# .../cache/lru_test.go:78:5: race detector: data race
|
|
90
|
+
Read at 0x00c0000a1230 by goroutine 9:
|
|
91
|
+
github.com/example/project/internal/cache.(*LRUCache).Get()
|
|
92
|
+
.../internal/cache/lru.go:44 +0x7c
|
|
93
|
+
... 100 more lines of goroutine dumps,
|
|
94
|
+
unrelated packages and test output
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
</td><td>
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
$ go build ./...
|
|
101
|
+
# .../handlers/user_handler.go:23:12: cannot use h
|
|
102
|
+
(type *UserHandler) as type storage.StorageService:
|
|
103
|
+
*UserHandler does not implement storage.StorageService
|
|
104
|
+
(missing GetObject method)
|
|
105
|
+
# .../handlers/order_handler.go:45:9: cannot use orderSvc ...
|
|
106
|
+
# .../auth/auth.go:12:5: import cycle not allowed
|
|
107
|
+
imports github.com/example/project/internal/permissions
|
|
108
|
+
<<ccr:e2e73bc3f2f290a77efc7426 52_lines_offloaded>>
|
|
109
|
+
--- FAIL: TestUserHandler_Get (0.00s)
|
|
110
|
+
user_handler_test.go:45:
|
|
111
|
+
Error: Not equal:
|
|
112
|
+
expected: &storage.Object{...}
|
|
113
|
+
actual : <nil>
|
|
114
|
+
FAIL
|
|
115
|
+
exit status 1
|
|
116
|
+
<<ccr:0bac82ae58f9e3ba08a67445 15_lines_offloaded>>
|
|
117
|
+
--- FAIL: TestConcurrentAccess (0.01s)
|
|
118
|
+
panic: runtime error: invalid memory address ...
|
|
119
|
+
FAIL
|
|
120
|
+
exit status 1
|
|
121
|
+
<<ccr:407242e9f3f948833f58dd56 23_lines_offloaded>>
|
|
122
|
+
...
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
</td></tr>
|
|
126
|
+
</table>
|
|
127
|
+
|
|
128
|
+
The block the agent asked for is kept verbatim, every failure line survives,
|
|
129
|
+
and each `<<ccr:…>>` marker can be expanded through Headroom's retrieval tool if
|
|
130
|
+
the agent needs the dropped lines after all. (Real model output on an example
|
|
131
|
+
from the Squeez test set; long paths and lines shortened to fit.)
|
|
132
|
+
|
|
133
|
+
## How it works
|
|
134
|
+
|
|
135
|
+
```mermaid
|
|
136
|
+
flowchart LR
|
|
137
|
+
A[Agent tool call] --> B[Headroom proxy]
|
|
138
|
+
B --> C{Content router}
|
|
139
|
+
C -- "log / search / diff / text" --> D[WinnowCompressor]
|
|
140
|
+
C -- "JSON / code / HTML" --> E[Headroom built-ins]
|
|
141
|
+
D --> F[Span model<br/>which lines matter?]
|
|
142
|
+
F --> G[Safety rules<br/>errors, tracebacks,<br/>±2 context, edges]
|
|
143
|
+
G --> H[Render<br/>kept lines verbatim +<br/>ccr markers]
|
|
144
|
+
H --> I[(CCR store<br/>hash → original)]
|
|
145
|
+
H --> J[Pruned context to LLM]
|
|
146
|
+
D -. "no query / too short /<br/>too large / low savings" .-> E
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
1. **Gate.** Blocks without a task query, under 40 lines, over the device's token
|
|
150
|
+
budget, or where pruning would save less than 20% pass through untouched, so
|
|
151
|
+
Headroom's own compressors handle them.
|
|
152
|
+
2. **Score.** A span model reads the task query and the whole output and marks
|
|
153
|
+
the lines that matter for the next step.
|
|
154
|
+
3. **Protect.** Lines with errors, failures, exit codes, panics or pytest `E`
|
|
155
|
+
details are always kept, as are whole Python tracebacks, two neighbours of
|
|
156
|
+
every kept line, and the first and last two lines.
|
|
157
|
+
4. **Render.** Kept lines stay byte-identical. Each dropped run becomes one
|
|
158
|
+
`<<ccr:HASH N_lines_offloaded>>` marker whose original text goes into the
|
|
159
|
+
CCR store. Hashes are deterministic, so identical input yields identical
|
|
160
|
+
output and prompt caches stay warm.
|
|
161
|
+
|
|
162
|
+
The plugin never raises. Any failure (missing torch, model download error,
|
|
163
|
+
inference error) falls back to Headroom's own path.
|
|
164
|
+
|
|
165
|
+
## Installation
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pip install "headroom-winnow[model]"
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Installing changes nothing until you opt in:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
headroom proxy --compressor winnow
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
or in Python:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from headroom.transforms.content_router import ContentRouter, ContentRouterConfig
|
|
181
|
+
|
|
182
|
+
router = ContentRouter(ContentRouterConfig(active_external_compressors=["winnow"]))
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
On first use Winnow downloads its model,
|
|
186
|
+
[`rbk4209/winnow-pooled-32m`](https://huggingface.co/rbk4209/winnow-pooled-32m)
|
|
187
|
+
(128 MB), from the Hugging Face Hub at a pinned commit. A GPU is strongly
|
|
188
|
+
recommended; on CPU Winnow only scores shorter outputs and leaves the rest to
|
|
189
|
+
Headroom.
|
|
190
|
+
|
|
191
|
+
### Models
|
|
192
|
+
|
|
193
|
+
| Backend | Model | When to use |
|
|
194
|
+
|---|---|---|
|
|
195
|
+
| `pooled` (default) | [`rbk4209/winnow-pooled-32m`](https://huggingface.co/rbk4209/winnow-pooled-32m), 32M line classifier trained for Winnow | Fast enough to score any tool output on a GPU |
|
|
196
|
+
| `highlighter` | [`KRLabsOrg/verbatim-rag-modern-bert-v2`](https://huggingface.co/KRLabsOrg/verbatim-rag-modern-bert-v2), 150M span model | Squeez's original extractive model; slower, so limited to short outputs |
|
|
197
|
+
|
|
198
|
+
### Configuration
|
|
199
|
+
|
|
200
|
+
| Variable | Default | Meaning |
|
|
201
|
+
|---|---|---|
|
|
202
|
+
| `HEADROOM_WINNOW_BACKEND` | `pooled` | `pooled` or `highlighter` |
|
|
203
|
+
| `HEADROOM_WINNOW_MODEL` | the backend's published model | Hub id or local path |
|
|
204
|
+
| `HEADROOM_WINNOW_REVISION` | pinned commit of the default model | Model revision |
|
|
205
|
+
| `HEADROOM_WINNOW_DEVICE` | `auto` | `auto` (CUDA if available), `cuda` or `cpu` |
|
|
206
|
+
| `HEADROOM_WINNOW_DTYPE` | `float32` | `float16` is faster only on GPUs with tensor cores |
|
|
207
|
+
| `HEADROOM_WINNOW_MAX_TOKENS` | per backend and device | Largest output the model scores; larger ones go to Headroom |
|
|
208
|
+
|
|
209
|
+
## Results
|
|
210
|
+
|
|
211
|
+
On the 618-example test split of the Squeez dataset:
|
|
212
|
+
|
|
213
|
+
| Method | Recall | Token reduction | Error lines lost | p50 latency |
|
|
214
|
+
|---|---|---|---|---|
|
|
215
|
+
| Headroom `relevance_split` (BM25) | 0.725 | 58.6%¹ | 7,953 | 1 ms |
|
|
216
|
+
| Headroom `relevance_split` (hybrid) | 0.753 | 57.6%¹ | 7,771 | 2.2 s |
|
|
217
|
+
| **Winnow (32M pooled)** | **0.847** | **41.4%** | **0** | **0.29 s** |
|
|
218
|
+
|
|
219
|
+
¹ Upper bound: the dropped tail is Kompressed inside Headroom, not removed.
|
|
220
|
+
|
|
221
|
+
At equal compression (50 / 70 / 90% of lines dropped) the pooled model keeps
|
|
222
|
+
0.89 / 0.84 / 0.68 of the gold lines, against 0.73 / 0.63 / 0.46 for
|
|
223
|
+
`relevance_split`. Details, the 150M highlighter numbers and reproduction
|
|
224
|
+
commands are in [`benchmarks/RESULTS.md`](https://github.com/RecepKurtulus/headroom-winnow/blob/main/benchmarks/RESULTS.md).
|
|
225
|
+
|
|
226
|
+
## Training your own model
|
|
227
|
+
|
|
228
|
+
[`training/kaggle_train_pooled.ipynb`](https://github.com/RecepKurtulus/headroom-winnow/blob/main/training/kaggle_train_pooled.ipynb)
|
|
229
|
+
trains the 32M pooled classifier on a free Kaggle T4 in about six hours. It
|
|
230
|
+
uses [Squeez](https://github.com/KRLabsOrg/squeez)'s own training code at a
|
|
231
|
+
pinned commit and evaluates on the same test split as the benchmark. Swap
|
|
232
|
+
`--base-model` to try other encoders.
|
|
233
|
+
|
|
234
|
+
## Project layout
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
headroom_winnow/
|
|
238
|
+
compressor.py WinnowCompressor: the headroom.compressor contract, gates, fail-open
|
|
239
|
+
selection.py spans → lines, safety rules, rendering with markers
|
|
240
|
+
markers.py CCR marker format and deterministic hashes
|
|
241
|
+
backends.py highlighter and pooled backends: lazy, pinned, device-aware
|
|
242
|
+
benchmarks/ compare.py and RESULTS.md
|
|
243
|
+
training/ Kaggle notebook for the pooled model
|
|
244
|
+
upstream/ patch proposed to Headroom (see below)
|
|
245
|
+
tests/ unit tests with a fake model, router end-to-end, real-model tests
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Limitations
|
|
249
|
+
|
|
250
|
+
- **Headroom's lossless fold runs first.** Headroom applies its byte-exact fold
|
|
251
|
+
(and, for logs and search results, `relevance_split`) before the external
|
|
252
|
+
compressor hook and returns early when either succeeds, so such blocks never
|
|
253
|
+
reach this plugin. See `tests/test_router.py::test_known_gap_lossless_fold_preempts_external`.
|
|
254
|
+
- **Passthroughs skip Headroom's compressors in 0.39.1.** When the plugin
|
|
255
|
+
declines a block, the router still adopts the unchanged block. The one-line
|
|
256
|
+
fix is in [`upstream/router-respect-passthrough.patch`](https://github.com/RecepKurtulus/headroom-winnow/blob/main/upstream/router-respect-passthrough.patch);
|
|
257
|
+
the matching test is a strict `xfail` until it lands.
|
|
258
|
+
|
|
259
|
+
## Development
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
pip install -e ".[dev,model]"
|
|
263
|
+
ruff check . && ruff format --check . && mypy headroom_winnow tests benchmarks
|
|
264
|
+
pytest # fast tests, no downloads
|
|
265
|
+
pytest -m slow # downloads and runs the real highlighter
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Acknowledgements
|
|
269
|
+
|
|
270
|
+
- [Headroom](https://github.com/headroomlabs-ai/headroom) for the proxy, CCR
|
|
271
|
+
store and the external compressor contract this plugin implements.
|
|
272
|
+
- [Squeez](https://github.com/KRLabsOrg/squeez) by KRLabs for the task-conditioned
|
|
273
|
+
pruning approach, the training code, the highlighter model and the dataset.
|
|
274
|
+
- [Ettin](https://huggingface.co/jhu-clsp/ettin-encoder-32m) for the 32M encoder
|
|
275
|
+
the pooled model is fine-tuned from.
|
|
276
|
+
|
|
277
|
+
## License
|
|
278
|
+
|
|
279
|
+
Apache-2.0. See [`LICENSE`](https://github.com/RecepKurtulus/headroom-winnow/blob/main/LICENSE) and [`NOTICE`](https://github.com/RecepKurtulus/headroom-winnow/blob/main/NOTICE).
|