hulder 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.
- hulder-0.1.0/LICENSE +201 -0
- hulder-0.1.0/PKG-INFO +60 -0
- hulder-0.1.0/docs/pypi.md +31 -0
- hulder-0.1.0/pyproject.toml +74 -0
- hulder-0.1.0/pyproject.toml.orig +69 -0
- hulder-0.1.0/src/hulder/__init__.py +21 -0
- hulder-0.1.0/src/hulder/capture/__init__.py +21 -0
- hulder-0.1.0/src/hulder/capture/base_model.py +43 -0
- hulder-0.1.0/src/hulder/capture/hidden_states.py +106 -0
- hulder-0.1.0/src/hulder/capture/metadata.py +47 -0
- hulder-0.1.0/src/hulder/cli.py +342 -0
- hulder-0.1.0/src/hulder/data/NOTICE.md +14 -0
- hulder-0.1.0/src/hulder/data/demo_awq.npz +0 -0
- hulder-0.1.0/src/hulder/data/demo_fp16.npz +0 -0
- hulder-0.1.0/src/hulder/data/demo_fp16_run1.npz +0 -0
- hulder-0.1.0/src/hulder/data/probe_demo.npz +0 -0
- hulder-0.1.0/src/hulder/gate/__init__.py +0 -0
- hulder-0.1.0/src/hulder/gate/atomic.py +41 -0
- hulder-0.1.0/src/hulder/gate/check.py +549 -0
- hulder-0.1.0/src/hulder/gate/npz.py +35 -0
- hulder-0.1.0/src/hulder/gate/pairing.py +63 -0
- hulder-0.1.0/src/hulder/gate/probe.py +75 -0
- hulder-0.1.0/src/hulder/gate/snapshot.py +109 -0
- hulder-0.1.0/src/hulder/gate/validate.py +32 -0
hulder-0.1.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 [yyyy] [name of copyright owner]
|
|
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.
|
hulder-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hulder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Release gate for thresholded scores, such as activation probes, across LLM serving configs
|
|
5
|
+
Keywords: activation probes,llm,vllm,quantization,release gate,mlops,monitoring
|
|
6
|
+
Author: Utku Özbek
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
17
|
+
Requires-Dist: numpy>=2.3
|
|
18
|
+
Requires-Dist: scipy>=1.16
|
|
19
|
+
Requires-Dist: scikit-learn>=1.7 ; extra == 'train'
|
|
20
|
+
Requires-Dist: vllm==0.30.0 ; extra == 'vllm'
|
|
21
|
+
Requires-Dist: pyyaml>=6.0.3 ; extra == 'vllm'
|
|
22
|
+
Requires-Dist: huggingface-hub>=1.33.0 ; extra == 'vllm'
|
|
23
|
+
Requires-Python: >=3.12
|
|
24
|
+
Project-URL: Source, https://github.com/revtheundead/hulder
|
|
25
|
+
Project-URL: Issues, https://github.com/revtheundead/hulder/issues
|
|
26
|
+
Provides-Extra: train
|
|
27
|
+
Provides-Extra: vllm
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# Hulder
|
|
31
|
+
|
|
32
|
+
[](https://github.com/revtheundead/hulder/actions/workflows/ci.yml)
|
|
33
|
+
|
|
34
|
+
A release gate for activation probes, and any other thresholded scorer, across LLM serving configs.
|
|
35
|
+
|
|
36
|
+
Teams tune a probe's threshold on one serving config, then change it: FP8 or AWQ weights, an FP8 KV cache, a vLLM upgrade. The hidden states move, and the threshold silently stops giving its target false-positive rate. `hulder check` compares a reference and a candidate on the same labelled examples and returns PASS, THRESHOLD STALE, SCORER DEGRADED or INCONCLUSIVE, with confidence intervals and a CI exit code.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install hulder
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The base install is numpy and scipy only and runs on CPU. Capturing activations from vLLM needs the `vllm` extra (`pip install "hulder[vllm]"`), which adds `hulder.capture`, experimental in v0.1.
|
|
45
|
+
|
|
46
|
+
## Quickstart
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
hulder quickstart
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
It runs two checks on bundled data with a demo probe, under a minute on CPU. An fp16 rerun as candidate gives PASS. The official AWQ int4 checkpoint of Qwen2.5-1.5B-Instruct gives INCONCLUSIVE, with the shift flagged against the rerun's noise floor. `hulder check --help` lists the options.
|
|
53
|
+
|
|
54
|
+
v0.1 is an early release. It has run only on a Turing GPU in fp16 and AWQ, and its tolerance bands are fixed.
|
|
55
|
+
|
|
56
|
+
## More
|
|
57
|
+
|
|
58
|
+
Design, statistical method, results and the cases where it loses: https://github.com/revtheundead/hulder
|
|
59
|
+
|
|
60
|
+
Apache-2.0. The bundled demo data is derived from a CC-BY-4.0 dataset, attributed in `hulder/data/NOTICE.md`.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Hulder
|
|
2
|
+
|
|
3
|
+
[](https://github.com/revtheundead/hulder/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
A release gate for activation probes, and any other thresholded scorer, across LLM serving configs.
|
|
6
|
+
|
|
7
|
+
Teams tune a probe's threshold on one serving config, then change it: FP8 or AWQ weights, an FP8 KV cache, a vLLM upgrade. The hidden states move, and the threshold silently stops giving its target false-positive rate. `hulder check` compares a reference and a candidate on the same labelled examples and returns PASS, THRESHOLD STALE, SCORER DEGRADED or INCONCLUSIVE, with confidence intervals and a CI exit code.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install hulder
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The base install is numpy and scipy only and runs on CPU. Capturing activations from vLLM needs the `vllm` extra (`pip install "hulder[vllm]"`), which adds `hulder.capture`, experimental in v0.1.
|
|
16
|
+
|
|
17
|
+
## Quickstart
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
hulder quickstart
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
It runs two checks on bundled data with a demo probe, under a minute on CPU. An fp16 rerun as candidate gives PASS. The official AWQ int4 checkpoint of Qwen2.5-1.5B-Instruct gives INCONCLUSIVE, with the shift flagged against the rerun's noise floor. `hulder check --help` lists the options.
|
|
24
|
+
|
|
25
|
+
v0.1 is an early release. It has run only on a Turing GPU in fp16 and AWQ, and its tolerance bands are fixed.
|
|
26
|
+
|
|
27
|
+
## More
|
|
28
|
+
|
|
29
|
+
Design, statistical method, results and the cases where it loses: https://github.com/revtheundead/hulder
|
|
30
|
+
|
|
31
|
+
Apache-2.0. The bundled demo data is derived from a CC-BY-4.0 dataset, attributed in `hulder/data/NOTICE.md`.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "hulder"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Release gate for thresholded scores, such as activation probes, across LLM serving configs"
|
|
5
|
+
readme = "docs/pypi.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
keywords = [
|
|
10
|
+
"activation probes",
|
|
11
|
+
"llm",
|
|
12
|
+
"vllm",
|
|
13
|
+
"quantization",
|
|
14
|
+
"release gate",
|
|
15
|
+
"mlops",
|
|
16
|
+
"monitoring",
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 3 - Alpha",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Intended Audience :: Science/Research",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
26
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"numpy>=2.3",
|
|
30
|
+
"scipy>=1.16",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[[project.authors]]
|
|
34
|
+
name = "Utku Özbek"
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Source = "https://github.com/revtheundead/hulder"
|
|
38
|
+
Issues = "https://github.com/revtheundead/hulder/issues"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
vllm = [
|
|
42
|
+
"vllm==0.30.0",
|
|
43
|
+
"pyyaml>=6.0.3",
|
|
44
|
+
"huggingface-hub>=1.33.0",
|
|
45
|
+
]
|
|
46
|
+
train = ["scikit-learn>=1.7"]
|
|
47
|
+
|
|
48
|
+
[project.scripts]
|
|
49
|
+
hulder = "hulder.cli:main"
|
|
50
|
+
|
|
51
|
+
[dependency-groups]
|
|
52
|
+
dev = [
|
|
53
|
+
{ include-group = "test" },
|
|
54
|
+
"hulder[vllm,train]",
|
|
55
|
+
"pandas>=2.3",
|
|
56
|
+
"pyarrow>=21",
|
|
57
|
+
"huggingface-hub",
|
|
58
|
+
"torch",
|
|
59
|
+
]
|
|
60
|
+
test = [
|
|
61
|
+
"pytest>=8",
|
|
62
|
+
"ruff==0.16.10",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[build-system]
|
|
66
|
+
requires = ["uv_build>=0.12.21,<0.13.0"]
|
|
67
|
+
build-backend = "uv_build"
|
|
68
|
+
|
|
69
|
+
[tool.uv]
|
|
70
|
+
python-preference = "only-managed"
|
|
71
|
+
python-downloads = "manual"
|
|
72
|
+
|
|
73
|
+
[tool.ruff]
|
|
74
|
+
line-length = 120
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "hulder"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Release gate for thresholded scores, such as activation probes, across LLM serving configs"
|
|
5
|
+
readme = "docs/pypi.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Utku Özbek" }
|
|
8
|
+
]
|
|
9
|
+
license = "Apache-2.0"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
keywords = ["activation probes", "llm", "vllm", "quantization", "release gate", "mlops", "monitoring"]
|
|
13
|
+
# No License :: classifier: PEP 639 forbids one alongside the license expression above.
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
22
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
23
|
+
]
|
|
24
|
+
# Base install: the gate library and CLI, numpy and scipy only (docs/design.md §4).
|
|
25
|
+
dependencies = [
|
|
26
|
+
"numpy>=2.3",
|
|
27
|
+
"scipy>=1.16",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Source = "https://github.com/revtheundead/hulder"
|
|
32
|
+
Issues = "https://github.com/revtheundead/hulder/issues"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
# hulder.capture imports pyyaml and huggingface_hub itself; the floors are the versions
|
|
36
|
+
# uv.lock resolves under the vllm pin.
|
|
37
|
+
vllm = ["vllm==0.30.0", "pyyaml>=6.0.3", "huggingface-hub>=1.33.0"]
|
|
38
|
+
train = ["scikit-learn>=1.7"]
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
# Default for `uv run`/`uv sync`, so local work keeps both extras installed.
|
|
42
|
+
dev = [
|
|
43
|
+
{include-group = "test"},
|
|
44
|
+
"hulder[vllm,train]",
|
|
45
|
+
"pandas>=2.3",
|
|
46
|
+
"pyarrow>=21",
|
|
47
|
+
# Imported directly by experiments/; versions come from the vllm pin via uv.lock.
|
|
48
|
+
"huggingface-hub",
|
|
49
|
+
"torch",
|
|
50
|
+
]
|
|
51
|
+
# The fast suite and lint on the base install, as CI runs them.
|
|
52
|
+
test = ["pytest>=8", "ruff==0.16.10"]
|
|
53
|
+
|
|
54
|
+
[project.scripts]
|
|
55
|
+
hulder = "hulder.cli:main"
|
|
56
|
+
|
|
57
|
+
[build-system]
|
|
58
|
+
requires = ["uv_build>=0.12.21,<0.13.0"]
|
|
59
|
+
build-backend = "uv_build"
|
|
60
|
+
|
|
61
|
+
[tool.uv]
|
|
62
|
+
# Managed interpreter only (it ships Python.h, which Triton's JIT needs), never
|
|
63
|
+
# downloaded implicitly. scripts/dev-env.sh points UV_PYTHON_INSTALL_DIR into the repo.
|
|
64
|
+
python-preference = "only-managed"
|
|
65
|
+
python-downloads = "manual"
|
|
66
|
+
|
|
67
|
+
[tool.ruff]
|
|
68
|
+
# Matches the existing code; most lines stay within 120.
|
|
69
|
+
line-length = 120
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from importlib.metadata import version
|
|
2
|
+
|
|
3
|
+
from hulder.gate.check import Estimate, Report, Verdict, check, check_snapshots
|
|
4
|
+
from hulder.gate.pairing import PairingError, prompt_ids_sha256
|
|
5
|
+
from hulder.gate.probe import Probe, apply_probe
|
|
6
|
+
from hulder.gate.snapshot import Snapshot
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"Estimate",
|
|
10
|
+
"PairingError",
|
|
11
|
+
"Probe",
|
|
12
|
+
"Report",
|
|
13
|
+
"Snapshot",
|
|
14
|
+
"Verdict",
|
|
15
|
+
"apply_probe",
|
|
16
|
+
"check",
|
|
17
|
+
"check_snapshots",
|
|
18
|
+
"prompt_ids_sha256",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
__version__ = version("hulder")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Activation capture from vLLM, the hulder[vllm] extra (docs/design.md §5). Public but experimental
|
|
2
|
+
in v0.1: these names may change in any 0.x release (docs/design.md §4).
|
|
3
|
+
|
|
4
|
+
capture, CaptureConfig and Capture import vLLM and torch, so they load on first use. The
|
|
5
|
+
other names, and importing this package, need neither.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import importlib
|
|
9
|
+
|
|
10
|
+
from hulder.capture.base_model import base_model_for
|
|
11
|
+
from hulder.capture.metadata import snapshot_metadata
|
|
12
|
+
|
|
13
|
+
__all__ = ["Capture", "CaptureConfig", "base_model_for", "capture", "snapshot_metadata"]
|
|
14
|
+
|
|
15
|
+
_NEEDS_VLLM = ("Capture", "CaptureConfig", "capture")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def __getattr__(name: str):
|
|
19
|
+
if name in _NEEDS_VLLM:
|
|
20
|
+
return getattr(importlib.import_module("hulder.capture.hidden_states"), name)
|
|
21
|
+
raise AttributeError(f"module 'hulder.capture' has no attribute {name!r}")
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""The base_model a capture records, which check requires to match across runs.
|
|
2
|
+
|
|
3
|
+
Kept apart from hidden_states.py so it imports without vLLM.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import re
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def card_base_model(model: str, revision: str) -> str | None:
|
|
12
|
+
"""The base_model field of a model card's YAML front matter at a pinned revision."""
|
|
13
|
+
# Imported here so base_model_for, and its tests, run on the base install.
|
|
14
|
+
import yaml
|
|
15
|
+
from huggingface_hub import hf_hub_download
|
|
16
|
+
|
|
17
|
+
text = Path(hf_hub_download(model, "README.md", revision=revision)).read_text()
|
|
18
|
+
front = re.match(r"^---\n(.*?)\n---", text, re.DOTALL)
|
|
19
|
+
value = yaml.safe_load(front.group(1)).get("base_model") if front else None
|
|
20
|
+
return value if isinstance(value, str) else None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def base_model_for(
|
|
24
|
+
model: str,
|
|
25
|
+
revision: str,
|
|
26
|
+
quantization: str | None,
|
|
27
|
+
override: str | None = None,
|
|
28
|
+
card: Callable[[str, str], str | None] = card_base_model,
|
|
29
|
+
) -> tuple[str | None, str | None]:
|
|
30
|
+
"""(base_model, warning). Unquantized, the model is its own base: a card's base_model
|
|
31
|
+
names the parent it was fine-tuned from, not what it re-encodes. Quantized, the override
|
|
32
|
+
or else the card's field; with neither, None and a warning rather than a guess."""
|
|
33
|
+
if override is not None:
|
|
34
|
+
return override, None
|
|
35
|
+
if quantization is None:
|
|
36
|
+
return model, None
|
|
37
|
+
base_model = card(model, revision)
|
|
38
|
+
if base_model is None:
|
|
39
|
+
return None, (
|
|
40
|
+
f"{model}@{revision} is quantized but its model card names no single base_model; "
|
|
41
|
+
"pass the base model explicitly so check can confirm both runs serve the same model."
|
|
42
|
+
)
|
|
43
|
+
return base_model, None
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Activation capture from vLLM, the hulder[vllm] extra (docs/design.md §4 and §5).
|
|
2
|
+
|
|
3
|
+
Offline extraction through vLLM's hidden-state connector, prefix caching off, chunked
|
|
4
|
+
prefill off, fixed prompt order and batch size. Never imported by the base package.
|
|
5
|
+
Any script calling `capture` needs an `if __name__ == "__main__":` guard (spawn on WSL).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import tempfile
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import torch
|
|
14
|
+
from vllm import LLM, SamplingParams
|
|
15
|
+
from vllm.config.kv_transfer import KVTransferConfig
|
|
16
|
+
from vllm.distributed.kv_transfer.kv_connector.v1 import example_hidden_states_connector
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class CaptureConfig:
|
|
21
|
+
"""Everything that fixes the captured values. Recorded verbatim in the run manifest."""
|
|
22
|
+
|
|
23
|
+
model: str
|
|
24
|
+
revision: str
|
|
25
|
+
layers: tuple[int, ...] # id k = residual stream after k decoder layers, 0 = embeddings
|
|
26
|
+
positions: tuple[int, ...] # negative indices into the templated prompt
|
|
27
|
+
system_prompt: str
|
|
28
|
+
quantization: str | None = None
|
|
29
|
+
dtype: str = "float16"
|
|
30
|
+
batch_size: int = 8
|
|
31
|
+
# Fits Qwen2.5-1.5B on an 8 GB RTX 2070 with extraction on (measured 2026-10-02).
|
|
32
|
+
gpu_memory_utilization: float = 0.7
|
|
33
|
+
max_model_len: int = 1024
|
|
34
|
+
max_num_batched_tokens: int = 1024
|
|
35
|
+
seed: int = 0
|
|
36
|
+
# Passed to the chat template when set. Pinned for hybrid-thinking models such as Qwen3,
|
|
37
|
+
# whose templated prompt, and so its last token, depends on it. None leaves the template's default.
|
|
38
|
+
enable_thinking: bool | None = None
|
|
39
|
+
# Required off for reproducible snapshots. Fields so the manifest records them.
|
|
40
|
+
enable_prefix_caching: bool = False
|
|
41
|
+
enable_chunked_prefill: bool = False
|
|
42
|
+
|
|
43
|
+
def __post_init__(self) -> None:
|
|
44
|
+
if self.enable_prefix_caching or self.enable_chunked_prefill:
|
|
45
|
+
raise ValueError("capture needs prefix caching and chunked prefill off (docs/design.md §5)")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True)
|
|
49
|
+
class Capture:
|
|
50
|
+
activations: np.ndarray # (n, layers, positions, d), float16, prompt order preserved
|
|
51
|
+
position_tokens: list[list[str]] # token string at each requested position, per prompt
|
|
52
|
+
# torch.cuda.get_device_name() of the current device, the first visible one. Under tensor
|
|
53
|
+
# parallelism the other GPUs aren't recorded, a known limit. Another GPU is another serving
|
|
54
|
+
# config (docs/design.md §6, metadata rules).
|
|
55
|
+
gpu: str
|
|
56
|
+
enable_thinking: bool | None # as passed to the chat template, None for its default
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def capture(prompts: list[str], cfg: CaptureConfig) -> Capture:
|
|
60
|
+
convs = [[{"role": "system", "content": cfg.system_prompt}, {"role": "user", "content": p}] for p in prompts]
|
|
61
|
+
params = SamplingParams(max_tokens=1, temperature=0)
|
|
62
|
+
template = {} if cfg.enable_thinking is None else {"chat_template_kwargs": {"enable_thinking": cfg.enable_thinking}}
|
|
63
|
+
acts, tokens = [], []
|
|
64
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
65
|
+
llm = LLM(
|
|
66
|
+
model=cfg.model,
|
|
67
|
+
revision=cfg.revision,
|
|
68
|
+
quantization=cfg.quantization,
|
|
69
|
+
dtype=cfg.dtype,
|
|
70
|
+
gpu_memory_utilization=cfg.gpu_memory_utilization,
|
|
71
|
+
max_model_len=cfg.max_model_len,
|
|
72
|
+
max_num_batched_tokens=cfg.max_num_batched_tokens,
|
|
73
|
+
max_num_seqs=cfg.batch_size,
|
|
74
|
+
seed=cfg.seed,
|
|
75
|
+
enable_chunked_prefill=cfg.enable_chunked_prefill,
|
|
76
|
+
enable_prefix_caching=cfg.enable_prefix_caching,
|
|
77
|
+
speculative_config={
|
|
78
|
+
"method": "extract_hidden_states",
|
|
79
|
+
"num_speculative_tokens": 1,
|
|
80
|
+
"draft_model_config": {"hf_config": {"eagle_aux_hidden_state_layer_ids": list(cfg.layers)}},
|
|
81
|
+
},
|
|
82
|
+
kv_transfer_config=KVTransferConfig(
|
|
83
|
+
kv_connector="ExampleHiddenStatesConnector",
|
|
84
|
+
kv_role="kv_producer",
|
|
85
|
+
kv_connector_extra_config={"shared_storage_path": tmp},
|
|
86
|
+
),
|
|
87
|
+
)
|
|
88
|
+
tok = llm.get_tokenizer()
|
|
89
|
+
pos = list(cfg.positions)
|
|
90
|
+
for start in range(0, len(convs), cfg.batch_size):
|
|
91
|
+
for out in llm.chat(convs[start : start + cfg.batch_size], params, use_tqdm=False, **template):
|
|
92
|
+
path = out.kv_transfer_params["hidden_states_path"]
|
|
93
|
+
obj = example_hidden_states_connector.load_hidden_states(path)
|
|
94
|
+
assert obj["token_ids"].tolist() == list(out.prompt_token_ids)
|
|
95
|
+
# hidden_states is [tokens, layers, d]; keep only the requested positions.
|
|
96
|
+
acts.append(obj["hidden_states"][pos].transpose(0, 1).to("cpu").numpy().astype(np.float16))
|
|
97
|
+
tokens.append(tok.convert_ids_to_tokens(obj["token_ids"][pos].tolist()))
|
|
98
|
+
os.remove(path)
|
|
99
|
+
if start // cfg.batch_size % 100 == 0:
|
|
100
|
+
print(f"captured {min(start + cfg.batch_size, len(convs))}/{len(convs)}", flush=True)
|
|
101
|
+
return Capture(
|
|
102
|
+
activations=np.stack(acts),
|
|
103
|
+
position_tokens=tokens,
|
|
104
|
+
gpu=torch.cuda.get_device_name(),
|
|
105
|
+
enable_thinking=cfg.enable_thinking,
|
|
106
|
+
)
|