ckptkit 0.3.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.
Files changed (38) hide show
  1. ckptkit-0.3.0/.github/workflows/ci.yml +41 -0
  2. ckptkit-0.3.0/.gitignore +22 -0
  3. ckptkit-0.3.0/CHANGELOG.md +25 -0
  4. ckptkit-0.3.0/LICENSE +177 -0
  5. ckptkit-0.3.0/PKG-INFO +223 -0
  6. ckptkit-0.3.0/README.md +185 -0
  7. ckptkit-0.3.0/assets/diff.svg +136 -0
  8. ckptkit-0.3.0/assets/inspect.svg +166 -0
  9. ckptkit-0.3.0/examples/diff_checkpoints.py +49 -0
  10. ckptkit-0.3.0/examples/estimate_size.py +59 -0
  11. ckptkit-0.3.0/examples/inspect_checkpoint.py +55 -0
  12. ckptkit-0.3.0/pyproject.toml +75 -0
  13. ckptkit-0.3.0/scripts/generate_assets.py +93 -0
  14. ckptkit-0.3.0/src/ckptkit/__init__.py +112 -0
  15. ckptkit-0.3.0/src/ckptkit/_types.py +164 -0
  16. ckptkit-0.3.0/src/ckptkit/cli.py +163 -0
  17. ckptkit-0.3.0/src/ckptkit/convert.py +366 -0
  18. ckptkit-0.3.0/src/ckptkit/diff.py +233 -0
  19. ckptkit-0.3.0/src/ckptkit/estimator.py +193 -0
  20. ckptkit-0.3.0/src/ckptkit/gguf.py +348 -0
  21. ckptkit-0.3.0/src/ckptkit/inspect.py +192 -0
  22. ckptkit-0.3.0/src/ckptkit/merge.py +116 -0
  23. ckptkit-0.3.0/src/ckptkit/metadata.py +265 -0
  24. ckptkit-0.3.0/src/ckptkit/py.typed +0 -0
  25. ckptkit-0.3.0/src/ckptkit/stats.py +148 -0
  26. ckptkit-0.3.0/src/ckptkit/validate.py +141 -0
  27. ckptkit-0.3.0/tests/test_cli.py +92 -0
  28. ckptkit-0.3.0/tests/test_convert.py +254 -0
  29. ckptkit-0.3.0/tests/test_diff.py +108 -0
  30. ckptkit-0.3.0/tests/test_diff_visual.py +181 -0
  31. ckptkit-0.3.0/tests/test_estimator.py +169 -0
  32. ckptkit-0.3.0/tests/test_gguf.py +292 -0
  33. ckptkit-0.3.0/tests/test_inspect.py +206 -0
  34. ckptkit-0.3.0/tests/test_merge.py +103 -0
  35. ckptkit-0.3.0/tests/test_metadata.py +222 -0
  36. ckptkit-0.3.0/tests/test_stats.py +98 -0
  37. ckptkit-0.3.0/tests/test_types.py +128 -0
  38. ckptkit-0.3.0/tests/test_validate.py +119 -0
@@ -0,0 +1,41 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ uses: actions/setup-python@v5
25
+ with:
26
+ python-version: ${{ matrix.python-version }}
27
+
28
+ - name: Install dependencies
29
+ run: |
30
+ python -m pip install --upgrade pip
31
+ pip install -e ".[cli]"
32
+ pip install pytest numpy ruff mypy
33
+
34
+ - name: Lint with ruff
35
+ run: ruff check src/ tests/
36
+
37
+ - name: Type check with mypy
38
+ run: mypy src/ckptkit/
39
+
40
+ - name: Run tests
41
+ run: pytest tests/ -v --tb=short
@@ -0,0 +1,22 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ *.egg
6
+ dist/
7
+ build/
8
+ .eggs/
9
+ *.so
10
+ .venv/
11
+ venv/
12
+ env/
13
+ .env
14
+ .mypy_cache/
15
+ .pytest_cache/
16
+ .ruff_cache/
17
+ htmlcov/
18
+ .coverage
19
+ coverage.xml
20
+ *.log
21
+ .DS_Store
22
+ Thumbs.db
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.0] - 2025-04-10
9
+
10
+ ### Added
11
+ - Add checkpoint format conversion via `convert.py`
12
+ - Add metadata editor in `metadata.py`
13
+
14
+ ## [0.2.0] - 2026-04-10
15
+
16
+ ### Added
17
+ - Add GGUF format parsing and inspection
18
+ - Add checkpoint size reduction estimator
19
+ - Add colored diff visualization for terminal
20
+
21
+ ## [0.1.0] - 2026-04-10
22
+
23
+ ### Added
24
+ - Initial release: universal checkpoint inspection, diff, and merge
25
+
ckptkit-0.3.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 the 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 the 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 any 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
ckptkit-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,223 @@
1
+ Metadata-Version: 2.4
2
+ Name: ckptkit
3
+ Version: 0.3.0
4
+ Summary: Inspect, convert, diff, and merge model checkpoints. The missing Swiss Army knife for ML weights.
5
+ Project-URL: Homepage, https://github.com/stef41/ckptkit
6
+ Project-URL: Repository, https://github.com/stef41/ckptkit
7
+ Project-URL: Issues, https://github.com/stef41/ckptkit/issues
8
+ Author: Zacharie B
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: checkpoint,diff,inspect,lora,machine-learning,merge,model-weights,pytorch,safetensors
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Provides-Extra: all
26
+ Requires-Dist: click>=8.0; extra == 'all'
27
+ Requires-Dist: rich>=13.0; extra == 'all'
28
+ Requires-Dist: safetensors>=0.4; extra == 'all'
29
+ Requires-Dist: torch>=2.0; extra == 'all'
30
+ Provides-Extra: cli
31
+ Requires-Dist: click>=8.0; extra == 'cli'
32
+ Requires-Dist: rich>=13.0; extra == 'cli'
33
+ Provides-Extra: safetensors
34
+ Requires-Dist: safetensors>=0.4; extra == 'safetensors'
35
+ Provides-Extra: torch
36
+ Requires-Dist: torch>=2.0; extra == 'torch'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # ckptkit
40
+
41
+ [![CI](https://github.com/stef41/ckptkit/actions/workflows/ci.yml/badge.svg)](https://github.com/stef41/ckptkit/actions/workflows/ci.yml)
42
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
43
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
44
+
45
+ **The missing Swiss Army knife for model checkpoints.**
46
+
47
+ ckptkit inspects, diffs, validates, and merges model checkpoints without loading them into GPU memory. Parse SafeTensors headers in milliseconds, compare checkpoints after fine-tuning, merge LoRA adapters, and validate file integrity — all from the command line or Python.
48
+
49
+ ![Inspect](assets/inspect.svg)
50
+
51
+ ## Why ckptkit?
52
+
53
+ Working with model weights means dealing with:
54
+
55
+ - "What layers are in this checkpoint?" → `ckptkit info`
56
+ - "What changed after fine-tuning?" → `ckptkit diff`
57
+ - "Is this download corrupt?" → `ckptkit validate`
58
+ - "Merge this LoRA adapter into the base" → `merge_lora_state_dicts()`
59
+ - "Show me parameter counts per layer" → `ckptkit stats`
60
+
61
+ mergekit handles model merging (TIES, DARE, SLERP), but nobody built the everyday checkpoint utility. ckptkit is that tool.
62
+
63
+ ## Install
64
+
65
+ ```bash
66
+ pip install ckptkit
67
+ ```
68
+
69
+ With SafeTensors support (recommended):
70
+
71
+ ```bash
72
+ pip install ckptkit[safetensors]
73
+ ```
74
+
75
+ With PyTorch support:
76
+
77
+ ```bash
78
+ pip install ckptkit[torch]
79
+ ```
80
+
81
+ Everything:
82
+
83
+ ```bash
84
+ pip install ckptkit[all]
85
+ ```
86
+
87
+ ## CLI
88
+
89
+ ### Inspect
90
+
91
+ ```bash
92
+ # See what's inside a checkpoint
93
+ ckptkit info model.safetensors
94
+
95
+ # JSON output for scripts
96
+ ckptkit info model.safetensors --json | jq '.n_parameters'
97
+ ```
98
+
99
+ ### Diff
100
+
101
+ Compare two checkpoints — see what changed during fine-tuning:
102
+
103
+ ![Diff](assets/diff.svg)
104
+
105
+ ```bash
106
+ ckptkit diff base_model.safetensors finetuned_model.safetensors
107
+ ```
108
+
109
+ ### Validate
110
+
111
+ Check for corruption before a long training run:
112
+
113
+ ```bash
114
+ ckptkit validate model.safetensors
115
+ # ✓ model.safetensors: valid (safetensors)
116
+ ```
117
+
118
+ ### Stats
119
+
120
+ ```bash
121
+ ckptkit stats model.safetensors
122
+ ```
123
+
124
+ ## Python API
125
+
126
+ ### Inspect
127
+
128
+ ```python
129
+ from ckptkit import inspect
130
+
131
+ info = inspect("model.safetensors")
132
+ print(f"Parameters: {info.n_parameters:,}")
133
+ print(f"Tensors: {info.n_tensors}")
134
+ print(f"Format: {info.format.value}")
135
+
136
+ for t in info.tensors[:5]:
137
+ print(f" {t.name}: {t.shape} {t.dtype.value} ({t.numel:,} params)")
138
+ ```
139
+
140
+ ### Diff
141
+
142
+ ```python
143
+ from ckptkit import diff, format_diff
144
+
145
+ result = diff("base.safetensors", "finetuned.safetensors")
146
+ print(f"Changes: {result.n_changes}")
147
+ print(f"Identical: {result.n_identical} / {result.n_shared}")
148
+
149
+ for entry in result.entries:
150
+ print(f" {entry.change_type}: {entry.tensor_name} — {entry.details}")
151
+ ```
152
+
153
+ ### Merge LoRA
154
+
155
+ ```python
156
+ import torch
157
+ from ckptkit import merge_lora_state_dicts
158
+
159
+ base = torch.load("base_model.bin", map_location="cpu")
160
+ adapter = torch.load("adapter_model.bin", map_location="cpu")
161
+
162
+ merged = merge_lora_state_dicts(base, adapter, alpha=1.0)
163
+ torch.save(merged, "merged_model.bin")
164
+ ```
165
+
166
+ ### Validate
167
+
168
+ ```python
169
+ from ckptkit import validate
170
+
171
+ result = validate("model.safetensors")
172
+ if not result.valid:
173
+ for issue in result.issues:
174
+ print(f" {issue.severity}: {issue.message}")
175
+ ```
176
+
177
+ ### Stats
178
+
179
+ ```python
180
+ from ckptkit import inspect, stats_from_info
181
+
182
+ info = inspect("model.safetensors")
183
+ stats = stats_from_info(info)
184
+
185
+ print(f"Total size: {stats.total_size_human}")
186
+ for dtype, count in stats.dtype_counts.items():
187
+ print(f" {dtype}: {count:,} parameters")
188
+ ```
189
+
190
+ ## Format support
191
+
192
+ | Format | Inspect | Diff | Validate | Merge |
193
+ |--------|---------|------|----------|-------|
194
+ | SafeTensors | ✓ (header-only, fast) | ✓ | ✓ (full integrity) | ✓ |
195
+ | PyTorch (.bin/.pt) | ✓ (requires torch) | ✓ | basic | ✓ |
196
+
197
+ ## How it works
198
+
199
+ **SafeTensors inspection is fast** because the format puts all tensor metadata (names, shapes, dtypes, offsets) in a JSON header at the start of the file. ckptkit reads only the first few KB, never loading the actual weight data.
200
+
201
+ LoRA merging performs `base_weight += alpha * (lora_B @ lora_A)` for each matched layer pair, with automatic key resolution for common adapter formats (PEFT, HuggingFace).
202
+
203
+ ## See Also
204
+
205
+ Part of the **stef41 LLM toolkit** — open-source tools for every stage of the LLM lifecycle:
206
+
207
+ | Project | What it does |
208
+ |---------|-------------|
209
+ | [tokonomics](https://github.com/stef41/tokonomix) | Token counting & cost management for LLM APIs |
210
+ | [datacrux](https://github.com/stef41/datacruxai) | Training data quality — dedup, PII, contamination |
211
+ | [castwright](https://github.com/stef41/castwright) | Synthetic instruction data generation |
212
+ | [datamix](https://github.com/stef41/datamix) | Dataset mixing & curriculum optimization |
213
+ | [toksight](https://github.com/stef41/toksight) | Tokenizer analysis & comparison |
214
+ | [trainpulse](https://github.com/stef41/trainpulse) | Training health monitoring |
215
+ | [quantbench](https://github.com/stef41/quantbenchx) | Quantization quality analysis |
216
+ | [infermark](https://github.com/stef41/infermark) | Inference benchmarking |
217
+ | [modeldiff](https://github.com/stef41/modeldiffx) | Behavioral regression testing |
218
+ | [vibesafe](https://github.com/stef41/vibesafex) | AI-generated code safety scanner |
219
+ | [injectionguard](https://github.com/stef41/injectionguard) | Prompt injection detection |
220
+
221
+ ## License
222
+
223
+ Apache-2.0
@@ -0,0 +1,185 @@
1
+ # ckptkit
2
+
3
+ [![CI](https://github.com/stef41/ckptkit/actions/workflows/ci.yml/badge.svg)](https://github.com/stef41/ckptkit/actions/workflows/ci.yml)
4
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
6
+
7
+ **The missing Swiss Army knife for model checkpoints.**
8
+
9
+ ckptkit inspects, diffs, validates, and merges model checkpoints without loading them into GPU memory. Parse SafeTensors headers in milliseconds, compare checkpoints after fine-tuning, merge LoRA adapters, and validate file integrity — all from the command line or Python.
10
+
11
+ ![Inspect](assets/inspect.svg)
12
+
13
+ ## Why ckptkit?
14
+
15
+ Working with model weights means dealing with:
16
+
17
+ - "What layers are in this checkpoint?" → `ckptkit info`
18
+ - "What changed after fine-tuning?" → `ckptkit diff`
19
+ - "Is this download corrupt?" → `ckptkit validate`
20
+ - "Merge this LoRA adapter into the base" → `merge_lora_state_dicts()`
21
+ - "Show me parameter counts per layer" → `ckptkit stats`
22
+
23
+ mergekit handles model merging (TIES, DARE, SLERP), but nobody built the everyday checkpoint utility. ckptkit is that tool.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install ckptkit
29
+ ```
30
+
31
+ With SafeTensors support (recommended):
32
+
33
+ ```bash
34
+ pip install ckptkit[safetensors]
35
+ ```
36
+
37
+ With PyTorch support:
38
+
39
+ ```bash
40
+ pip install ckptkit[torch]
41
+ ```
42
+
43
+ Everything:
44
+
45
+ ```bash
46
+ pip install ckptkit[all]
47
+ ```
48
+
49
+ ## CLI
50
+
51
+ ### Inspect
52
+
53
+ ```bash
54
+ # See what's inside a checkpoint
55
+ ckptkit info model.safetensors
56
+
57
+ # JSON output for scripts
58
+ ckptkit info model.safetensors --json | jq '.n_parameters'
59
+ ```
60
+
61
+ ### Diff
62
+
63
+ Compare two checkpoints — see what changed during fine-tuning:
64
+
65
+ ![Diff](assets/diff.svg)
66
+
67
+ ```bash
68
+ ckptkit diff base_model.safetensors finetuned_model.safetensors
69
+ ```
70
+
71
+ ### Validate
72
+
73
+ Check for corruption before a long training run:
74
+
75
+ ```bash
76
+ ckptkit validate model.safetensors
77
+ # ✓ model.safetensors: valid (safetensors)
78
+ ```
79
+
80
+ ### Stats
81
+
82
+ ```bash
83
+ ckptkit stats model.safetensors
84
+ ```
85
+
86
+ ## Python API
87
+
88
+ ### Inspect
89
+
90
+ ```python
91
+ from ckptkit import inspect
92
+
93
+ info = inspect("model.safetensors")
94
+ print(f"Parameters: {info.n_parameters:,}")
95
+ print(f"Tensors: {info.n_tensors}")
96
+ print(f"Format: {info.format.value}")
97
+
98
+ for t in info.tensors[:5]:
99
+ print(f" {t.name}: {t.shape} {t.dtype.value} ({t.numel:,} params)")
100
+ ```
101
+
102
+ ### Diff
103
+
104
+ ```python
105
+ from ckptkit import diff, format_diff
106
+
107
+ result = diff("base.safetensors", "finetuned.safetensors")
108
+ print(f"Changes: {result.n_changes}")
109
+ print(f"Identical: {result.n_identical} / {result.n_shared}")
110
+
111
+ for entry in result.entries:
112
+ print(f" {entry.change_type}: {entry.tensor_name} — {entry.details}")
113
+ ```
114
+
115
+ ### Merge LoRA
116
+
117
+ ```python
118
+ import torch
119
+ from ckptkit import merge_lora_state_dicts
120
+
121
+ base = torch.load("base_model.bin", map_location="cpu")
122
+ adapter = torch.load("adapter_model.bin", map_location="cpu")
123
+
124
+ merged = merge_lora_state_dicts(base, adapter, alpha=1.0)
125
+ torch.save(merged, "merged_model.bin")
126
+ ```
127
+
128
+ ### Validate
129
+
130
+ ```python
131
+ from ckptkit import validate
132
+
133
+ result = validate("model.safetensors")
134
+ if not result.valid:
135
+ for issue in result.issues:
136
+ print(f" {issue.severity}: {issue.message}")
137
+ ```
138
+
139
+ ### Stats
140
+
141
+ ```python
142
+ from ckptkit import inspect, stats_from_info
143
+
144
+ info = inspect("model.safetensors")
145
+ stats = stats_from_info(info)
146
+
147
+ print(f"Total size: {stats.total_size_human}")
148
+ for dtype, count in stats.dtype_counts.items():
149
+ print(f" {dtype}: {count:,} parameters")
150
+ ```
151
+
152
+ ## Format support
153
+
154
+ | Format | Inspect | Diff | Validate | Merge |
155
+ |--------|---------|------|----------|-------|
156
+ | SafeTensors | ✓ (header-only, fast) | ✓ | ✓ (full integrity) | ✓ |
157
+ | PyTorch (.bin/.pt) | ✓ (requires torch) | ✓ | basic | ✓ |
158
+
159
+ ## How it works
160
+
161
+ **SafeTensors inspection is fast** because the format puts all tensor metadata (names, shapes, dtypes, offsets) in a JSON header at the start of the file. ckptkit reads only the first few KB, never loading the actual weight data.
162
+
163
+ LoRA merging performs `base_weight += alpha * (lora_B @ lora_A)` for each matched layer pair, with automatic key resolution for common adapter formats (PEFT, HuggingFace).
164
+
165
+ ## See Also
166
+
167
+ Part of the **stef41 LLM toolkit** — open-source tools for every stage of the LLM lifecycle:
168
+
169
+ | Project | What it does |
170
+ |---------|-------------|
171
+ | [tokonomics](https://github.com/stef41/tokonomix) | Token counting & cost management for LLM APIs |
172
+ | [datacrux](https://github.com/stef41/datacruxai) | Training data quality — dedup, PII, contamination |
173
+ | [castwright](https://github.com/stef41/castwright) | Synthetic instruction data generation |
174
+ | [datamix](https://github.com/stef41/datamix) | Dataset mixing & curriculum optimization |
175
+ | [toksight](https://github.com/stef41/toksight) | Tokenizer analysis & comparison |
176
+ | [trainpulse](https://github.com/stef41/trainpulse) | Training health monitoring |
177
+ | [quantbench](https://github.com/stef41/quantbenchx) | Quantization quality analysis |
178
+ | [infermark](https://github.com/stef41/infermark) | Inference benchmarking |
179
+ | [modeldiff](https://github.com/stef41/modeldiffx) | Behavioral regression testing |
180
+ | [vibesafe](https://github.com/stef41/vibesafex) | AI-generated code safety scanner |
181
+ | [injectionguard](https://github.com/stef41/injectionguard) | Prompt injection detection |
182
+
183
+ ## License
184
+
185
+ Apache-2.0