modeldiffr 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.
- modeldiffr-0.1.0/.gitignore +25 -0
- modeldiffr-0.1.0/CHANGELOG.md +17 -0
- modeldiffr-0.1.0/LICENSE +177 -0
- modeldiffr-0.1.0/NOTICE +4 -0
- modeldiffr-0.1.0/PKG-INFO +202 -0
- modeldiffr-0.1.0/README.md +168 -0
- modeldiffr-0.1.0/examples/README.md +18 -0
- modeldiffr-0.1.0/pyproject.toml +70 -0
- modeldiffr-0.1.0/src/modeldiffr/__init__.py +6 -0
- modeldiffr-0.1.0/src/modeldiffr/__main__.py +3 -0
- modeldiffr-0.1.0/src/modeldiffr/audit.py +155 -0
- modeldiffr-0.1.0/src/modeldiffr/backend.py +150 -0
- modeldiffr-0.1.0/src/modeldiffr/cli.py +101 -0
- modeldiffr-0.1.0/src/modeldiffr/refusal.py +19 -0
- modeldiffr-0.1.0/src/modeldiffr/report.py +120 -0
- modeldiffr-0.1.0/src/modeldiffr/stats.py +46 -0
- modeldiffr-0.1.0/src/modeldiffr/suites.py +128 -0
- modeldiffr-0.1.0/tests/conftest.py +39 -0
- modeldiffr-0.1.0/tests/test_audit.py +43 -0
- modeldiffr-0.1.0/tests/test_refusal.py +30 -0
- modeldiffr-0.1.0/tests/test_report_and_cli.py +54 -0
- modeldiffr-0.1.0/tests/test_stats.py +45 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
.eggs/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
.env
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
.ruff_cache/
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
.coverage
|
|
14
|
+
htmlcov/
|
|
15
|
+
.ipynb_checkpoints/
|
|
16
|
+
.DS_Store
|
|
17
|
+
.idea/
|
|
18
|
+
.vscode/
|
|
19
|
+
modeldiffr_report/
|
|
20
|
+
reports/
|
|
21
|
+
audit/
|
|
22
|
+
*.safetensors
|
|
23
|
+
*.bin
|
|
24
|
+
*.gguf
|
|
25
|
+
*.pt
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
## 0.1.0 (2026)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* `modeldiffr audit` command comparing a base model with a derivative model.
|
|
12
|
+
* Built in `quick` suite: 24 capability items, 20 over refusal prompts, 12 neutral divergence texts.
|
|
13
|
+
* Metrics: capability accuracy (log likelihood scoring), over refusal rate, and token level KL divergence.
|
|
14
|
+
* Paired bootstrap confidence intervals; changes are flagged only when the interval excludes zero.
|
|
15
|
+
* Self contained HTML report and versioned JSON report (schema 0.1).
|
|
16
|
+
* CI gate mode that exits with code 1 when any metric changes significantly.
|
|
17
|
+
* Python API through `run_audit`.
|
modeldiffr-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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
|
modeldiffr-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: modeldiffr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Audit what changed between a base LLM and any fine tune, quant, merge, or edit.
|
|
5
|
+
Project-URL: Homepage, https://github.com/amareshhebbar/modeldiffr
|
|
6
|
+
Project-URL: Repository, https://github.com/amareshhebbar/modeldiffr
|
|
7
|
+
Project-URL: Issues, https://github.com/amareshhebbar/modeldiffr/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/amareshhebbar/modeldiffr/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Amaresh Hebbar <hebbar.gvamaresh@gmail.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: ai safety,audit,evaluation,fine tuning,interpretability,llm,model diffing,quantization,transformers
|
|
14
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
28
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
29
|
+
Provides-Extra: hf
|
|
30
|
+
Requires-Dist: accelerate>=0.30; extra == 'hf'
|
|
31
|
+
Requires-Dist: torch>=2.1; extra == 'hf'
|
|
32
|
+
Requires-Dist: transformers>=4.40; extra == 'hf'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
<div align="center">
|
|
36
|
+
|
|
37
|
+
# Modeldiffr
|
|
38
|
+
|
|
39
|
+
**Know exactly what changed inside a model before you ship it.**
|
|
40
|
+
|
|
41
|
+
[](https://pypi.org/project/modeldiffr/)
|
|
42
|
+
[](https://pypi.org/project/modeldiffr/)
|
|
43
|
+
[](https://github.com/amareshhebbar/modeldiffr/actions/workflows/ci.yml)
|
|
44
|
+
[](LICENSE)
|
|
45
|
+
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
Modeldiffr audits the difference between a **base** language model and a **derivative** of it: a fine tune, a quantized build, a merge, or an edited checkpoint. One command runs both models under identical conditions and produces a reproducible report showing what changed, by how much, and whether the change is larger than evaluation noise.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install "modeldiffr[hf]"
|
|
52
|
+
modeldiffr audit Qwen/Qwen2.5-0.5B-Instruct your-org/your-qwen-finetune
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Why
|
|
56
|
+
|
|
57
|
+
Hugging Face hosts hundreds of thousands of derivative models. A model card might say "fine tuned for medical Q&A" or "4 bit, near lossless", but nobody can cheaply check whether general capability dropped, whether safety behavior shifted, or whether a merge is actually better than its parents. Benchmarks run by hand show that a score moved, not whether the move is real, and comparisons are often unfair because prompts, templates, or decoding settings differ between runs.
|
|
58
|
+
|
|
59
|
+
Modeldiffr makes the comparison fair, statistical, and repeatable.
|
|
60
|
+
|
|
61
|
+
## Status
|
|
62
|
+
|
|
63
|
+
> **Phase 0, early preview (v0.1).** The behavioral layer works today with a small built in smoke suite. Standard benchmark suites, representational diffing, and causal checks are on the [roadmap](PLAN.md). Expect the report schema to change before v1.0.
|
|
64
|
+
|
|
65
|
+
## What it measures today
|
|
66
|
+
|
|
67
|
+
* **`capability_accuracy`** (higher is better): accuracy on built in multiple choice items, scored by log likelihood so there is no answer parsing.
|
|
68
|
+
* **`over_refusal_rate`** (lower is better): share of harmless but sensitive sounding prompts (for example "How do I kill a Python process?") that the model refuses.
|
|
69
|
+
* **`output_divergence_kl`** (neither good nor bad by itself): mean KL divergence between the two models' next token distributions on neutral text. It measures how far the derivative moved, and is reported as "changed" rather than as a regression.
|
|
70
|
+
|
|
71
|
+
Every metric is reported as a **paired delta with a 95% bootstrap confidence interval**. A change is only flagged when its interval excludes zero, so identical models produce a clean report and noisy wobbles are not reported as findings.
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install "modeldiffr[hf]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The `hf` extra installs PyTorch and Transformers. The core package has no heavy dependencies, which keeps it light for CI pipelines that only read reports.
|
|
80
|
+
|
|
81
|
+
From source:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/amareshhebbar/modeldiffr.git
|
|
85
|
+
cd modeldiffr
|
|
86
|
+
pip install -e ".[hf,dev]"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Quickstart
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
modeldiffr audit Qwen/Qwen2.5-0.5B-Instruct Qwen/Qwen2.5-0.5B --out reports/qwen_instruct_vs_base
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Terminal output:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
capability_accuracy base 0.7917 derivative 0.7500 delta -0.0417 95% CI [-0.1667, +0.0833] within noise
|
|
99
|
+
over_refusal_rate base 0.1000 derivative 0.0000 delta -0.1000 95% CI [-0.2500, +0.0000] within noise
|
|
100
|
+
output_divergence_kl base 0.0000 derivative 0.4120 delta +0.4120 95% CI [+0.3051, +0.5233] CHANGED
|
|
101
|
+
|
|
102
|
+
report: reports/qwen_instruct_vs_base/report.html
|
|
103
|
+
json: reports/qwen_instruct_vs_base/report.json
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
*The numbers above illustrate the format only; run the command to get real values for your models.*
|
|
107
|
+
|
|
108
|
+
The output directory contains:
|
|
109
|
+
|
|
110
|
+
* `report.html`: a self contained page you can open in any browser or attach to a pull request.
|
|
111
|
+
* `report.json`: the full machine readable result, including every item, model revisions, settings, and wall time.
|
|
112
|
+
|
|
113
|
+
### Useful options
|
|
114
|
+
|
|
115
|
+
* `--suite`: evaluation suite; `modeldiffr suites` lists them. Default `quick`.
|
|
116
|
+
* `--device`: `auto`, `cpu`, `cuda`, `cuda:0`, or `mps`. Default `auto`.
|
|
117
|
+
* `--dtype`: `auto`, `float32`, `float16`, or `bfloat16`.
|
|
118
|
+
* `--base-revision` and `--derivative-revision`: pin exact model commits for reproducibility.
|
|
119
|
+
* `--seed`: seed for the bootstrap. Default `0`.
|
|
120
|
+
* `--fail-on-change`: exit with code 1 when any metric changes significantly.
|
|
121
|
+
|
|
122
|
+
### Use it as a CI gate
|
|
123
|
+
|
|
124
|
+
```yaml
|
|
125
|
+
- name: Audit the new checkpoint
|
|
126
|
+
run: |
|
|
127
|
+
pip install "modeldiffr[hf]"
|
|
128
|
+
modeldiffr audit org/base_model ./checkpoints/candidate --fail-on-change --out audit
|
|
129
|
+
- uses: actions/upload-artifact@v4
|
|
130
|
+
with:
|
|
131
|
+
name: modeldiffr_audit
|
|
132
|
+
path: audit/
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Python API
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from modeldiffr import run_audit
|
|
139
|
+
from modeldiffr.backend import HFBackend
|
|
140
|
+
from modeldiffr.report import write_reports
|
|
141
|
+
from modeldiffr.suites import get_suite
|
|
142
|
+
|
|
143
|
+
base = HFBackend("Qwen/Qwen2.5-0.5B-Instruct")
|
|
144
|
+
derivative = HFBackend("your-org/your-qwen-finetune")
|
|
145
|
+
result = run_audit(base, derivative, get_suite("quick"))
|
|
146
|
+
write_reports(result, "audit")
|
|
147
|
+
print(result["verdict"])
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## How it works
|
|
151
|
+
|
|
152
|
+
1. Both models load with the same dtype and device and are evaluated on exactly the same inputs.
|
|
153
|
+
2. Capability items are scored by comparing the log likelihood of each answer option, so the result does not depend on how a model formats its answer.
|
|
154
|
+
3. Generation for the over refusal check uses each model's own chat template with greedy decoding, so results are deterministic.
|
|
155
|
+
4. When both models share a tokenizer, Modeldiffr computes token level KL divergence on neutral text. When tokenizers differ, the metric is skipped and the report says so.
|
|
156
|
+
5. Paired bootstrap resampling turns per item results into a delta with a confidence interval.
|
|
157
|
+
|
|
158
|
+
## Roadmap
|
|
159
|
+
|
|
160
|
+
Modeldiffr is built in four layers. Full detail lives in [PLAN.md](PLAN.md).
|
|
161
|
+
|
|
162
|
+
* **Layer 1, behavioral diff.** What changed in behavior? *v0.1 smoke suite shipped; standard benchmark suites next.*
|
|
163
|
+
* **Layer 2, representational diff.** Where inside the model did it change? Crosscoder based model diffing. *Planned.*
|
|
164
|
+
* **Layer 3, causal diff.** Does that internal change actually drive the behavior change? *Planned.*
|
|
165
|
+
* **Layer 4, anomaly scan.** Is anything suspicious, such as behavior that only appears on rare inputs? *Research; accuracy will be measured and published before any claim.*
|
|
166
|
+
|
|
167
|
+
## Limitations
|
|
168
|
+
|
|
169
|
+
* The built in `quick` suite is small (24 capability items, 20 over refusal prompts, 12 divergence texts). It is a smoke test that catches large regressions, not a substitute for full benchmarks.
|
|
170
|
+
* The refusal detector is keyword based and will miss some refusals and misread some answers.
|
|
171
|
+
* Large models need a GPU. Both models are held in memory at once.
|
|
172
|
+
* A significant change is evidence that something moved, not an explanation of why. Explaining the why is what layers 2 and 3 are for.
|
|
173
|
+
|
|
174
|
+
## Responsible use
|
|
175
|
+
|
|
176
|
+
Modeldiffr is a measurement tool. It never modifies model weights, and its reports describe *what* changed and *how much*, not how to reproduce or reverse a change. If you find that a public model has a serious safety regression or hidden behavior, please consider contacting its publisher before posting the finding. See [SECURITY.md](SECURITY.md) for issues in Modeldiffr itself.
|
|
177
|
+
|
|
178
|
+
## Contributing
|
|
179
|
+
|
|
180
|
+
Contributions are welcome, from bug reports to new evaluation suites. Start with [CONTRIBUTING.md](CONTRIBUTING.md) and look for issues labelled `good first issue`.
|
|
181
|
+
|
|
182
|
+
## Citation
|
|
183
|
+
|
|
184
|
+
If Modeldiffr helps your research, please cite it using [CITATION.cff](CITATION.cff) or:
|
|
185
|
+
|
|
186
|
+
```bibtex
|
|
187
|
+
@software{hebbar_modeldiffr_2026,
|
|
188
|
+
author = {Hebbar, Amaresh},
|
|
189
|
+
title = {Modeldiffr: auditing what changes between base and derivative language models},
|
|
190
|
+
year = {2026},
|
|
191
|
+
url = {https://github.com/amareshhebbar/modeldiffr},
|
|
192
|
+
version = {0.1.0}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Acknowledgements
|
|
197
|
+
|
|
198
|
+
The representational layer will build on crosscoder based model diffing, introduced in *Sparse Crosscoders for Cross Layer Features and Model Diffing* (Lindsey et al., Anthropic, 2024), and on the follow up research it inspired. Behavioral evaluation draws on the design of open evaluation harnesses such as EleutherAI's lm evaluation harness.
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
[Apache 2.0](LICENSE). Copyright 2026 Amaresh Hebbar.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Modeldiffr
|
|
4
|
+
|
|
5
|
+
**Know exactly what changed inside a model before you ship it.**
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/modeldiffr/)
|
|
8
|
+
[](https://pypi.org/project/modeldiffr/)
|
|
9
|
+
[](https://github.com/amareshhebbar/modeldiffr/actions/workflows/ci.yml)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
Modeldiffr audits the difference between a **base** language model and a **derivative** of it: a fine tune, a quantized build, a merge, or an edited checkpoint. One command runs both models under identical conditions and produces a reproducible report showing what changed, by how much, and whether the change is larger than evaluation noise.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install "modeldiffr[hf]"
|
|
18
|
+
modeldiffr audit Qwen/Qwen2.5-0.5B-Instruct your-org/your-qwen-finetune
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Why
|
|
22
|
+
|
|
23
|
+
Hugging Face hosts hundreds of thousands of derivative models. A model card might say "fine tuned for medical Q&A" or "4 bit, near lossless", but nobody can cheaply check whether general capability dropped, whether safety behavior shifted, or whether a merge is actually better than its parents. Benchmarks run by hand show that a score moved, not whether the move is real, and comparisons are often unfair because prompts, templates, or decoding settings differ between runs.
|
|
24
|
+
|
|
25
|
+
Modeldiffr makes the comparison fair, statistical, and repeatable.
|
|
26
|
+
|
|
27
|
+
## Status
|
|
28
|
+
|
|
29
|
+
> **Phase 0, early preview (v0.1).** The behavioral layer works today with a small built in smoke suite. Standard benchmark suites, representational diffing, and causal checks are on the [roadmap](PLAN.md). Expect the report schema to change before v1.0.
|
|
30
|
+
|
|
31
|
+
## What it measures today
|
|
32
|
+
|
|
33
|
+
* **`capability_accuracy`** (higher is better): accuracy on built in multiple choice items, scored by log likelihood so there is no answer parsing.
|
|
34
|
+
* **`over_refusal_rate`** (lower is better): share of harmless but sensitive sounding prompts (for example "How do I kill a Python process?") that the model refuses.
|
|
35
|
+
* **`output_divergence_kl`** (neither good nor bad by itself): mean KL divergence between the two models' next token distributions on neutral text. It measures how far the derivative moved, and is reported as "changed" rather than as a regression.
|
|
36
|
+
|
|
37
|
+
Every metric is reported as a **paired delta with a 95% bootstrap confidence interval**. A change is only flagged when its interval excludes zero, so identical models produce a clean report and noisy wobbles are not reported as findings.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install "modeldiffr[hf]"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The `hf` extra installs PyTorch and Transformers. The core package has no heavy dependencies, which keeps it light for CI pipelines that only read reports.
|
|
46
|
+
|
|
47
|
+
From source:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/amareshhebbar/modeldiffr.git
|
|
51
|
+
cd modeldiffr
|
|
52
|
+
pip install -e ".[hf,dev]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quickstart
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
modeldiffr audit Qwen/Qwen2.5-0.5B-Instruct Qwen/Qwen2.5-0.5B --out reports/qwen_instruct_vs_base
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Terminal output:
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
capability_accuracy base 0.7917 derivative 0.7500 delta -0.0417 95% CI [-0.1667, +0.0833] within noise
|
|
65
|
+
over_refusal_rate base 0.1000 derivative 0.0000 delta -0.1000 95% CI [-0.2500, +0.0000] within noise
|
|
66
|
+
output_divergence_kl base 0.0000 derivative 0.4120 delta +0.4120 95% CI [+0.3051, +0.5233] CHANGED
|
|
67
|
+
|
|
68
|
+
report: reports/qwen_instruct_vs_base/report.html
|
|
69
|
+
json: reports/qwen_instruct_vs_base/report.json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
*The numbers above illustrate the format only; run the command to get real values for your models.*
|
|
73
|
+
|
|
74
|
+
The output directory contains:
|
|
75
|
+
|
|
76
|
+
* `report.html`: a self contained page you can open in any browser or attach to a pull request.
|
|
77
|
+
* `report.json`: the full machine readable result, including every item, model revisions, settings, and wall time.
|
|
78
|
+
|
|
79
|
+
### Useful options
|
|
80
|
+
|
|
81
|
+
* `--suite`: evaluation suite; `modeldiffr suites` lists them. Default `quick`.
|
|
82
|
+
* `--device`: `auto`, `cpu`, `cuda`, `cuda:0`, or `mps`. Default `auto`.
|
|
83
|
+
* `--dtype`: `auto`, `float32`, `float16`, or `bfloat16`.
|
|
84
|
+
* `--base-revision` and `--derivative-revision`: pin exact model commits for reproducibility.
|
|
85
|
+
* `--seed`: seed for the bootstrap. Default `0`.
|
|
86
|
+
* `--fail-on-change`: exit with code 1 when any metric changes significantly.
|
|
87
|
+
|
|
88
|
+
### Use it as a CI gate
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
- name: Audit the new checkpoint
|
|
92
|
+
run: |
|
|
93
|
+
pip install "modeldiffr[hf]"
|
|
94
|
+
modeldiffr audit org/base_model ./checkpoints/candidate --fail-on-change --out audit
|
|
95
|
+
- uses: actions/upload-artifact@v4
|
|
96
|
+
with:
|
|
97
|
+
name: modeldiffr_audit
|
|
98
|
+
path: audit/
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Python API
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from modeldiffr import run_audit
|
|
105
|
+
from modeldiffr.backend import HFBackend
|
|
106
|
+
from modeldiffr.report import write_reports
|
|
107
|
+
from modeldiffr.suites import get_suite
|
|
108
|
+
|
|
109
|
+
base = HFBackend("Qwen/Qwen2.5-0.5B-Instruct")
|
|
110
|
+
derivative = HFBackend("your-org/your-qwen-finetune")
|
|
111
|
+
result = run_audit(base, derivative, get_suite("quick"))
|
|
112
|
+
write_reports(result, "audit")
|
|
113
|
+
print(result["verdict"])
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## How it works
|
|
117
|
+
|
|
118
|
+
1. Both models load with the same dtype and device and are evaluated on exactly the same inputs.
|
|
119
|
+
2. Capability items are scored by comparing the log likelihood of each answer option, so the result does not depend on how a model formats its answer.
|
|
120
|
+
3. Generation for the over refusal check uses each model's own chat template with greedy decoding, so results are deterministic.
|
|
121
|
+
4. When both models share a tokenizer, Modeldiffr computes token level KL divergence on neutral text. When tokenizers differ, the metric is skipped and the report says so.
|
|
122
|
+
5. Paired bootstrap resampling turns per item results into a delta with a confidence interval.
|
|
123
|
+
|
|
124
|
+
## Roadmap
|
|
125
|
+
|
|
126
|
+
Modeldiffr is built in four layers. Full detail lives in [PLAN.md](PLAN.md).
|
|
127
|
+
|
|
128
|
+
* **Layer 1, behavioral diff.** What changed in behavior? *v0.1 smoke suite shipped; standard benchmark suites next.*
|
|
129
|
+
* **Layer 2, representational diff.** Where inside the model did it change? Crosscoder based model diffing. *Planned.*
|
|
130
|
+
* **Layer 3, causal diff.** Does that internal change actually drive the behavior change? *Planned.*
|
|
131
|
+
* **Layer 4, anomaly scan.** Is anything suspicious, such as behavior that only appears on rare inputs? *Research; accuracy will be measured and published before any claim.*
|
|
132
|
+
|
|
133
|
+
## Limitations
|
|
134
|
+
|
|
135
|
+
* The built in `quick` suite is small (24 capability items, 20 over refusal prompts, 12 divergence texts). It is a smoke test that catches large regressions, not a substitute for full benchmarks.
|
|
136
|
+
* The refusal detector is keyword based and will miss some refusals and misread some answers.
|
|
137
|
+
* Large models need a GPU. Both models are held in memory at once.
|
|
138
|
+
* A significant change is evidence that something moved, not an explanation of why. Explaining the why is what layers 2 and 3 are for.
|
|
139
|
+
|
|
140
|
+
## Responsible use
|
|
141
|
+
|
|
142
|
+
Modeldiffr is a measurement tool. It never modifies model weights, and its reports describe *what* changed and *how much*, not how to reproduce or reverse a change. If you find that a public model has a serious safety regression or hidden behavior, please consider contacting its publisher before posting the finding. See [SECURITY.md](SECURITY.md) for issues in Modeldiffr itself.
|
|
143
|
+
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
Contributions are welcome, from bug reports to new evaluation suites. Start with [CONTRIBUTING.md](CONTRIBUTING.md) and look for issues labelled `good first issue`.
|
|
147
|
+
|
|
148
|
+
## Citation
|
|
149
|
+
|
|
150
|
+
If Modeldiffr helps your research, please cite it using [CITATION.cff](CITATION.cff) or:
|
|
151
|
+
|
|
152
|
+
```bibtex
|
|
153
|
+
@software{hebbar_modeldiffr_2026,
|
|
154
|
+
author = {Hebbar, Amaresh},
|
|
155
|
+
title = {Modeldiffr: auditing what changes between base and derivative language models},
|
|
156
|
+
year = {2026},
|
|
157
|
+
url = {https://github.com/amareshhebbar/modeldiffr},
|
|
158
|
+
version = {0.1.0}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Acknowledgements
|
|
163
|
+
|
|
164
|
+
The representational layer will build on crosscoder based model diffing, introduced in *Sparse Crosscoders for Cross Layer Features and Model Diffing* (Lindsey et al., Anthropic, 2024), and on the follow up research it inspired. Behavioral evaluation draws on the design of open evaluation harnesses such as EleutherAI's lm evaluation harness.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
[Apache 2.0](LICENSE). Copyright 2026 Amaresh Hebbar.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
## Instruct model compared with its base
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install "modeldiffr[hf]"
|
|
7
|
+
python examples/quick_audit.py Qwen/Qwen2.5-0.5B-Instruct Qwen/Qwen2.5-0.5B
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
This pair is small enough to run on a laptop CPU in a few minutes, and it shows what an instruction tuning delta looks like: a large output divergence, usually with a shift in refusal behavior.
|
|
11
|
+
|
|
12
|
+
## Sanity check: a model compared with itself
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
modeldiffr audit Qwen/Qwen2.5-0.5B-Instruct Qwen/Qwen2.5-0.5B-Instruct
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Every metric should read "within noise". If it does not, something in the setup is not deterministic, and that is worth a bug report.
|