weightlab 0.1.0a1__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 (57) hide show
  1. weightlab-0.1.0a1/PKG-INFO +268 -0
  2. weightlab-0.1.0a1/README.md +245 -0
  3. weightlab-0.1.0a1/pyproject.toml +118 -0
  4. weightlab-0.1.0a1/pyproject.toml.orig +98 -0
  5. weightlab-0.1.0a1/weightlab/__init__.py +23 -0
  6. weightlab-0.1.0a1/weightlab/analysis/__init__.py +0 -0
  7. weightlab-0.1.0a1/weightlab/analysis/accumulate.py +311 -0
  8. weightlab-0.1.0a1/weightlab/analysis/change_report.py +669 -0
  9. weightlab-0.1.0a1/weightlab/analysis/compat.py +146 -0
  10. weightlab-0.1.0a1/weightlab/analysis/diff.py +93 -0
  11. weightlab-0.1.0a1/weightlab/analysis/lineage.py +245 -0
  12. weightlab-0.1.0a1/weightlab/analysis/lora.py +483 -0
  13. weightlab-0.1.0a1/weightlab/analysis/pyramid.py +779 -0
  14. weightlab-0.1.0a1/weightlab/analysis/report_io.py +374 -0
  15. weightlab-0.1.0a1/weightlab/analysis/roi.py +128 -0
  16. weightlab-0.1.0a1/weightlab/analysis/roles.py +75 -0
  17. weightlab-0.1.0a1/weightlab/analysis/sampling.py +221 -0
  18. weightlab-0.1.0a1/weightlab/analysis/tile.py +516 -0
  19. weightlab-0.1.0a1/weightlab/analysis/tile_codec.py +311 -0
  20. weightlab-0.1.0a1/weightlab/api/__init__.py +1 -0
  21. weightlab-0.1.0a1/weightlab/api/app.py +466 -0
  22. weightlab-0.1.0a1/weightlab/api/catalog.py +327 -0
  23. weightlab-0.1.0a1/weightlab/api/config.py +80 -0
  24. weightlab-0.1.0a1/weightlab/api/errors.py +89 -0
  25. weightlab-0.1.0a1/weightlab/api/relations.py +321 -0
  26. weightlab-0.1.0a1/weightlab/api/roi.py +221 -0
  27. weightlab-0.1.0a1/weightlab/api/schemas.py +295 -0
  28. weightlab-0.1.0a1/weightlab/api/security.py +203 -0
  29. weightlab-0.1.0a1/weightlab/api/server.py +46 -0
  30. weightlab-0.1.0a1/weightlab/api/tiles.py +509 -0
  31. weightlab-0.1.0a1/weightlab/cache.py +509 -0
  32. weightlab-0.1.0a1/weightlab/cli.py +224 -0
  33. weightlab-0.1.0a1/weightlab/core/__init__.py +0 -0
  34. weightlab-0.1.0a1/weightlab/core/errors.py +40 -0
  35. weightlab-0.1.0a1/weightlab/core/limits.py +29 -0
  36. weightlab-0.1.0a1/weightlab/core/memory.py +121 -0
  37. weightlab-0.1.0a1/weightlab/db/__init__.py +44 -0
  38. weightlab-0.1.0a1/weightlab/db/migrations/0001_initial.sql +121 -0
  39. weightlab-0.1.0a1/weightlab/db/migrations/0002_model_files_ctime.sql +11 -0
  40. weightlab-0.1.0a1/weightlab/db/migrations/__init__.py +1 -0
  41. weightlab-0.1.0a1/weightlab/db/schema.py +292 -0
  42. weightlab-0.1.0a1/weightlab/db/store.py +418 -0
  43. weightlab-0.1.0a1/weightlab/formats/__init__.py +0 -0
  44. weightlab-0.1.0a1/weightlab/formats/base.py +83 -0
  45. weightlab-0.1.0a1/weightlab/formats/checkpoint.py +497 -0
  46. weightlab-0.1.0a1/weightlab/formats/dtypes.py +88 -0
  47. weightlab-0.1.0a1/weightlab/formats/fileio.py +168 -0
  48. weightlab-0.1.0a1/weightlab/formats/safetensors_reader.py +120 -0
  49. weightlab-0.1.0a1/weightlab/formats/selection.py +140 -0
  50. weightlab-0.1.0a1/weightlab/formats/shards.py +78 -0
  51. weightlab-0.1.0a1/weightlab/jobs.py +386 -0
  52. weightlab-0.1.0a1/weightlab/schemas/change_report.schema.json +101 -0
  53. weightlab-0.1.0a1/weightlab/ui/__init__.py +72 -0
  54. weightlab-0.1.0a1/weightlab/ui/static/assets/index-DQKuRsGl.js +9 -0
  55. weightlab-0.1.0a1/weightlab/ui/static/assets/index-hkYppvgX.css +1 -0
  56. weightlab-0.1.0a1/weightlab/ui/static/favicon.svg +1 -0
  57. weightlab-0.1.0a1/weightlab/ui/static/index.html +17 -0
@@ -0,0 +1,268 @@
1
+ Metadata-Version: 2.3
2
+ Name: weightlab
3
+ Version: 0.1.0a1
4
+ Summary: Explore LLM weights locally: heatmaps, exact tensor inspection, checkpoint and LoRA change reports.
5
+ Classifier: Development Status :: 3 - Alpha
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Intended Audience :: Science/Research
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Requires-Dist: numpy==2.5.4
13
+ Requires-Dist: fastapi==0.162.0
14
+ Requires-Dist: pydantic==2.14.3
15
+ Requires-Dist: uvicorn==0.54.0
16
+ Requires-Dist: platformdirs==4.14.5
17
+ Requires-Python: >=3.12
18
+ Project-URL: Homepage, https://github.com/szaher/weightlab
19
+ Project-URL: Source, https://github.com/szaher/weightlab
20
+ Project-URL: Documentation, https://github.com/szaher/weightlab#readme
21
+ Project-URL: Issues, https://github.com/szaher/weightlab/issues
22
+ Description-Content-Type: text/markdown
23
+
24
+ <div align="center">
25
+
26
+ ![WeightLab — Explore what changed inside your LLM](assets/weightlab-hero.svg)
27
+
28
+ **Explore LLM weights locally. Visualize tensor structure, inspect exact values, and measure checkpoint changes.**
29
+
30
+ [Quickstart](#quickstart) · [Screenshots](#see-it-in-action) · [Checkpoint comparison](#compare-checkpoints) · [Python API](#python-api) · [Limitations](#current-scope-and-limitations)
31
+
32
+ [![CI](https://github.com/szaher/weightlab/actions/workflows/ci.yml/badge.svg)](https://github.com/szaher/weightlab/actions/workflows/ci.yml)
33
+ [![Python 3.12+](https://img.shields.io/badge/Python-3.12%2B-3776AB)](pyproject.toml)
34
+ [![CPU only](https://img.shields.io/badge/GPU-not%20required-0F766E)](#quickstart)
35
+ [![Local first](https://img.shields.io/badge/local-first-2563EB)](#privacy-and-security)
36
+ [![Pre-release](https://img.shields.io/badge/status-pre--release-F59E0B)](#current-scope-and-limitations)
37
+
38
+ </div>
39
+
40
+ ## Why WeightLab?
41
+
42
+ You fine-tuned a model. **What changed inside its weights?** Which matrices moved the most? Can you inspect individual parameter values without loading the whole checkpoint into memory?
43
+
44
+ **WeightLab is a local-first, CPU-only toolkit for answering those questions.** It reads SafeTensors checkpoints in place and offers a browser-based tensor explorer alongside a Python library and command-line checkpoint/LoRA change reports.
45
+
46
+ - **See the structure:** browse tensor metadata and explore entire matrices as multiresolution heatmaps.
47
+ - **Get the actual numbers:** select a region to inspect and copy lossless source values.
48
+ - **Measure the change:** rank checkpoint differences by tensor, layer, and role, with reproducible JSON, CSV, and Markdown reports.
49
+ - **Control the cost:** use bounded reads, cancellable pyramid builds, caching, and clearly labeled sampled previews.
50
+ - **Keep weights local:** no account, GPU, model inference runtime, or hosted backend required.
51
+
52
+ > **Scientific boundary:** A change in weight magnitude does **not** demonstrate improved reasoning, accuracy, or behavior. WeightLab measures parameters; behavioral claims require independent evaluation and controlled experiments.
53
+
54
+ ## See it in action
55
+
56
+ These are **real screenshots** captured by browser tests on pinned [Qwen2.5 checkpoints](evidence/phase1-real-models/README.md), not design mockups.
57
+
58
+ <table>
59
+ <tr>
60
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-02-mlp-gate-overview.png"><img src="evidence/phase1-real-models/screenshots/real-02-mlp-gate-overview.png" width="100%" alt="Interactive multiresolution heatmap of a Qwen MLP gate projection"/></a><br/><b>Whole-tensor heatmaps</b><br/>Pan, zoom, change aggregation, and select regions.</td>
61
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-04-exact-roi.png"><img src="evidence/phase1-real-models/screenshots/real-04-exact-roi.png" width="100%" alt="Exact values for a selected Qwen tensor region"/></a><br/><b>Exact region inspection</b><br/>Go from visual patterns to original tensor values.</td>
62
+ </tr>
63
+ <tr>
64
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-06-embedding-exact.png"><img src="evidence/phase1-real-models/screenshots/real-06-embedding-exact.png" width="100%" alt="Exact-coverage visualization of a large Qwen embedding tensor"/></a><br/><b>Large embedding matrices</b><br/>Build an exact overview using resource-bounded pyramids.</td>
65
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-08-math-embedding-sampled.png"><img src="evidence/phase1-real-models/screenshots/real-08-math-embedding-sampled.png" width="100%" alt="Row-sampled visualization of a large Qwen embedding tensor"/></a><br/><b>Sampling you can see</b><br/>Previews disclose quality, row sampling, and coverage.</td>
66
+ </tr>
67
+ </table>
68
+
69
+ [Workspace](evidence/phase1-real-models/screenshots/real-01-workspace.png) · [Selecting a region](evidence/phase1-real-models/screenshots/real-03-attention-selected.png) · [Pyramid build](evidence/phase1-real-models/screenshots/real-05-embedding-building.png) · [ROI screenshots](evidence/phase1-roi/screenshots/) · [More UI screenshots](evidence/phase1-ui/screenshots/)
70
+
71
+ ## What works today
72
+
73
+ | Feature | Available | Interface |
74
+ | --- | --- | --- |
75
+ | Create projects, import local SafeTensors, inspect/search/filter tensor metadata | Yes | Browser app |
76
+ | Explore whole 2-D tensors (and 2-D slices of higher-rank tensors), pan/zoom/transpose, five aggregations | Yes | Browser app |
77
+ | Exact ROI heatmap and accessible per-cell values table | Yes | Browser app / Python |
78
+ | Exact tiles, streamed pyramids, labeled row-sampled previews, cancellable jobs | Yes | Browser app / local API |
79
+ | Base vs. fine-tuned checkpoint difference reports | Yes | CLI / Python |
80
+ | Supported PEFT LoRA effective-delta analysis | Yes | CLI / Python |
81
+ | Graphical checkpoint-delta overlays, Compare and Adapters screens | **Not yet** | Planned |
82
+ | Whole-tensor stats jobs, image/report export from UI, inference, activations, causal evaluations | **Not yet** | Planned |
83
+
84
+ **Important distinction:** You can compare checkpoints and supported LoRA adapters **today via the CLI**. The current UI visualizes *individual checkpoint tensors*, not a side-by-side checkpoint comparison.
85
+
86
+ ## Quickstart
87
+
88
+ **Requirements:** Python **3.12+**, [uv](https://docs.astral.sh/uv/), and Git. No GPU or Node.js is needed to **run** the app. Repository CI covers macOS, Linux, and Windows; the real-checkpoint visual evaluation was run on macOS/Chromium.
89
+
90
+ ```bash
91
+ git clone https://github.com/szaher/weightlab.git
92
+ cd weightlab
93
+ uv sync --locked
94
+ uv run weightlab start
95
+ ```
96
+
97
+ Open the link printed in your terminal, which looks like:
98
+
99
+ ```text
100
+ http://127.0.0.1:<port>/#token=...
101
+ ```
102
+
103
+ WeightLab serves the browser UI and local FastAPI backend on the same loopback origin. The URL contains a **per-launch access token**: open it locally, don't share it, and keep the terminal running.
104
+
105
+ ### Your first five minutes
106
+
107
+ 1. Click **Create project** in the browser.
108
+ 2. Import a checkpoint by **absolute path**, specifying an allowed **selected root**. You can use the repository's bundled `examples/fixtures/tiny_base.safetensors` and make `examples/fixtures` the selected root. This reads the file *in place*; there is no upload.
109
+ 3. Open **Explore**, select a 2-D weight tensor, and inspect its shape, dtype, and metadata.
110
+ 4. Open **Overview** to pan, zoom, change aggregation (mean, mean-absolute, RMS, min, max), and select a region.
111
+ 5. Choose **Inspect exact values** to see the original source values in the Exact ROI heatmap or values table.
112
+
113
+ Print the fixture's absolute paths if needed:
114
+
115
+ ```bash
116
+ uv run python -c "from pathlib import Path; p=Path('examples/fixtures').resolve(); print('Root:',p); print('Model:',p/'tiny_base.safetensors')"
117
+ ```
118
+
119
+ **No models to download:** the bundled deterministic fixtures are enough to try the UI and CLI. To reproduce the real-Qwen workflow, see the [pinned checkpoint validation](evidence/phase1-real-models/README.md).
120
+
121
+ ### Install a local wheel
122
+
123
+ ```bash
124
+ uv build --wheel
125
+ uv tool install dist/weightlab-*.whl
126
+ weightlab start
127
+ ```
128
+
129
+ The wheel includes the compiled web UI, so **Node.js is only needed to rebuild it**. WeightLab **`0.1.0a1` (alpha)** is being prepared for PyPI. After the first release is published, install with `uv tool install "weightlab==0.1.0a1"` or `python -m pip install "weightlab==0.1.0a1"`. Until then, use the source or local wheel instructions above.
130
+
131
+ ## Compare checkpoints
132
+
133
+ Use `weightlab diff` to measure numerical changes between two checkpoints, including compatible sharded SafeTensors directories:
134
+
135
+ ```bash
136
+ uv run weightlab diff \
137
+ examples/fixtures/tiny_base.safetensors \
138
+ examples/fixtures/tiny_ft.safetensors \
139
+ --out ./weightlab-report
140
+
141
+ # report.json, report.md, tensors.csv, layers.csv, roles.csv
142
+ ```
143
+
144
+ For your own checkpoints:
145
+
146
+ ```bash
147
+ uv run weightlab diff /path/to/base /path/to/fine-tuned --out /path/to/reports
148
+ ```
149
+
150
+ Or inspect a supported **PEFT LoRA** adapter's effective weight changes against its base:
151
+
152
+ ```bash
153
+ uv run weightlab diff \
154
+ examples/fixtures/tiny_base.safetensors \
155
+ --adapter examples/fixtures/tiny_lora \
156
+ --out ./weightlab-lora-report
157
+ ```
158
+
159
+ Reports include per-tensor and rollup **delta L2, delta RMS, relative L2, cosine similarity, max absolute delta, and non-finite counts**. Compatibility classes distinguish verified file identity from declared lineage or mere shape matching. Support for LoRA variants is intentionally limited and unsupported modules are reported rather than silently interpreted.
160
+
161
+ **Exit codes:** `0` means complete; `3` means a report was written but is **incomplete**; `2` means error; `130` means cancelled. Check `complete` and any caveats before interpreting results.
162
+
163
+ Full details: [CLI reference, metrics and LoRA support](docs/cli/weightlab-diff.md).
164
+
165
+ ## Python API
166
+
167
+ Read a bounded region from a checkpoint without loading the whole model:
168
+
169
+ ```python
170
+ from weightlab import open_checkpoint
171
+ from weightlab.analysis.roi import encode_roi
172
+
173
+ with open_checkpoint(
174
+ "examples/fixtures/tiny_base.safetensors",
175
+ selected_root="examples/fixtures",
176
+ ) as checkpoint:
177
+ print(checkpoint.metadata()[:3])
178
+ roi = checkpoint.read_roi_raw("demo.layers.0.mlp.up_proj.weight", 0, 4, 0, 8)
179
+ print(encode_roi(roi).to_json())
180
+ ```
181
+
182
+ Compute a structured change report:
183
+
184
+ ```python
185
+ from weightlab.analysis.change_report import Options, run
186
+
187
+ report = run(
188
+ "examples/fixtures/tiny_base.safetensors",
189
+ "examples/fixtures/tiny_ft.safetensors",
190
+ options=Options(sort="relative_l2"),
191
+ )
192
+ print(report["complete"])
193
+ ```
194
+
195
+ The Python API remains **pre-release**. See [change report documentation](docs/cli/weightlab-diff.md) and [reader implementation](weightlab/formats/checkpoint.py).
196
+
197
+ ## How it works
198
+
199
+ ```mermaid
200
+ flowchart LR
201
+ A["Local SafeTensors files"] --> B["Strict read-only reader"]
202
+ B --> C["Catalog and project metadata"]
203
+ B --> D["Bounded tile + pyramid engine"]
204
+ D --> E["Whole-tensor heatmaps"]
205
+ E --> F["Exact ROI drilldown"]
206
+ B --> F
207
+ B --> G["Streaming diff / LoRA analysis"]
208
+ G --> H["JSON / CSV / Markdown reports"]
209
+ ```
210
+
211
+ - **Strict file reader:** validates metadata, shards, offsets, and paths; reads only bounded file regions.
212
+ - **Visual layer:** multiresolution `256 × 256` tiles, optional exact pyramids, explicit row-sampled previews, and distinct coverage/precision labels.
213
+ - **Numerical layer:** raw ROI values are lossless; tile aggregate visualizations use float32 and must not be mistaken for exact individual parameters. Non-finite values and unrepresentable numbers get explicit states.
214
+ - **Application:** local FastAPI + React, SQLite for projects, bounded job handling and cache budgets.
215
+
216
+ ### Privacy and security
217
+
218
+ WeightLab runs locally by default and does not require a cloud account. The server accepts **loopback-only** binds and protects its local API with a launch token. Imported model files are read in place, not uploaded, rewritten, or deleted when a project is deleted. The application is designed without background telemetry or model-data exfiltration. Reports contain tensor names, shapes, statistics, file names, sizes, and possibly digests, so **review reports before sharing**. See [security design](docs/12_SECURITY_AND_PRIVACY.md).
219
+
220
+ ### Verified on real models
221
+
222
+ The project contains reproducible validation against pinned **Qwen2.5-0.5B / Instruct** and **Qwen2.5-Math-1.5B / Instruct** checkpoints. The recorded macOS run compared **1,256 tensor metadata entries**, **184 exact ROI windows**, and **1,048 tiles** with an independent reader. It reported zero mismatches for the described numerical checks. During that run the backend's **peak RSS was 166.3 MiB**, with a **36 GiB RAM / Apple M3 Pro** host; this is a benchmark observation, **not** a general memory guarantee or proof of the 8 GiB laptop target.
223
+
224
+ Reproduce the measurements and inspect limitations in [real model evidence](evidence/phase1-real-models/README.md) and [the machine-readable benchmark](evidence/phase1-real-models/results/benchmark.json). Browser validation was in Chromium; a practitioner usability study has **not** been completed.
225
+
226
+ ## Current scope and limitations
227
+
228
+ - **Format:** SafeTensors (single files or sharded indexes). No GGUF, PyTorch `.bin`, or general quantized checkpoint format support.
229
+ - **Overview:** whole-tensor heatmap aggregation is not a lossless display of every original scalar. Use **Exact ROI** for actual values.
230
+ - **Comparison:** numerical deltas are not causal evidence of improved behavior; independent checkpoints may be poorly aligned even when shapes match.
231
+ - **UI:** Compare/Adapters pages, graphical delta/LoRA overlays, stats jobs, and UI export are not built.
232
+ - **Experimental features:** inference, activations, transfer experiments, and evaluation are not present.
233
+ - **Maturity:** pre-release; field-tested practitioner feedback, non-Chromium browser coverage, and the intended 8 GiB laptop target remain unverified.
234
+
235
+ ## Development and contributing
236
+
237
+ The code is under active development. Use reproducible fixtures, add tests for numerical and security behavior, and avoid weakening validation to satisfy an acceptance gate.
238
+
239
+ ```bash
240
+ uv sync --locked
241
+ uv run pytest
242
+ uv run ruff format --check .
243
+ uv run ruff check .
244
+ uv run mypy
245
+ ```
246
+
247
+ Frontend changes require Node.js (see [frontend documentation](frontend/README.md)):
248
+
249
+ ```bash
250
+ cd frontend
251
+ npm ci
252
+ npm run lint
253
+ npm run typecheck
254
+ npm test
255
+ npm run build
256
+ npx playwright install chromium
257
+ npm run e2e
258
+ ```
259
+
260
+ **Explore further:** [evaluation kit](evaluation-kit/README.md) · [test evidence](evidence/) · [OpenAPI contract](contracts/openapi.yaml) · [architecture](docs/03_SYSTEM_ARCHITECTURE.md) · [numerical methods](docs/05_NUMERICAL_METHODS.md) · [roadmap](docs/14_DELIVERY_ROADMAP.md) · [issue tracker](https://github.com/szaher/weightlab/issues).
261
+
262
+ For publishing and packaging instructions, see [RELEASING.md](RELEASING.md).
263
+
264
+ The detailed version **1.2-final specification** remains a frozen engineering baseline; it is **not** the current implementation status. Some historical planning documents and examples describe future behavior, so treat the tested source code and evidence above as the authority for currently working features.
265
+
266
+ ## License
267
+
268
+ No explicit repository-wide open-source license has been selected in the current source tree. **Do not assume the code is licensed for reuse or redistribution** until a license is added. Contributions and distribution should be discussed with the maintainer.
@@ -0,0 +1,245 @@
1
+ <div align="center">
2
+
3
+ ![WeightLab — Explore what changed inside your LLM](assets/weightlab-hero.svg)
4
+
5
+ **Explore LLM weights locally. Visualize tensor structure, inspect exact values, and measure checkpoint changes.**
6
+
7
+ [Quickstart](#quickstart) · [Screenshots](#see-it-in-action) · [Checkpoint comparison](#compare-checkpoints) · [Python API](#python-api) · [Limitations](#current-scope-and-limitations)
8
+
9
+ [![CI](https://github.com/szaher/weightlab/actions/workflows/ci.yml/badge.svg)](https://github.com/szaher/weightlab/actions/workflows/ci.yml)
10
+ [![Python 3.12+](https://img.shields.io/badge/Python-3.12%2B-3776AB)](pyproject.toml)
11
+ [![CPU only](https://img.shields.io/badge/GPU-not%20required-0F766E)](#quickstart)
12
+ [![Local first](https://img.shields.io/badge/local-first-2563EB)](#privacy-and-security)
13
+ [![Pre-release](https://img.shields.io/badge/status-pre--release-F59E0B)](#current-scope-and-limitations)
14
+
15
+ </div>
16
+
17
+ ## Why WeightLab?
18
+
19
+ You fine-tuned a model. **What changed inside its weights?** Which matrices moved the most? Can you inspect individual parameter values without loading the whole checkpoint into memory?
20
+
21
+ **WeightLab is a local-first, CPU-only toolkit for answering those questions.** It reads SafeTensors checkpoints in place and offers a browser-based tensor explorer alongside a Python library and command-line checkpoint/LoRA change reports.
22
+
23
+ - **See the structure:** browse tensor metadata and explore entire matrices as multiresolution heatmaps.
24
+ - **Get the actual numbers:** select a region to inspect and copy lossless source values.
25
+ - **Measure the change:** rank checkpoint differences by tensor, layer, and role, with reproducible JSON, CSV, and Markdown reports.
26
+ - **Control the cost:** use bounded reads, cancellable pyramid builds, caching, and clearly labeled sampled previews.
27
+ - **Keep weights local:** no account, GPU, model inference runtime, or hosted backend required.
28
+
29
+ > **Scientific boundary:** A change in weight magnitude does **not** demonstrate improved reasoning, accuracy, or behavior. WeightLab measures parameters; behavioral claims require independent evaluation and controlled experiments.
30
+
31
+ ## See it in action
32
+
33
+ These are **real screenshots** captured by browser tests on pinned [Qwen2.5 checkpoints](evidence/phase1-real-models/README.md), not design mockups.
34
+
35
+ <table>
36
+ <tr>
37
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-02-mlp-gate-overview.png"><img src="evidence/phase1-real-models/screenshots/real-02-mlp-gate-overview.png" width="100%" alt="Interactive multiresolution heatmap of a Qwen MLP gate projection"/></a><br/><b>Whole-tensor heatmaps</b><br/>Pan, zoom, change aggregation, and select regions.</td>
38
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-04-exact-roi.png"><img src="evidence/phase1-real-models/screenshots/real-04-exact-roi.png" width="100%" alt="Exact values for a selected Qwen tensor region"/></a><br/><b>Exact region inspection</b><br/>Go from visual patterns to original tensor values.</td>
39
+ </tr>
40
+ <tr>
41
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-06-embedding-exact.png"><img src="evidence/phase1-real-models/screenshots/real-06-embedding-exact.png" width="100%" alt="Exact-coverage visualization of a large Qwen embedding tensor"/></a><br/><b>Large embedding matrices</b><br/>Build an exact overview using resource-bounded pyramids.</td>
42
+ <td width="50%"><a href="evidence/phase1-real-models/screenshots/real-08-math-embedding-sampled.png"><img src="evidence/phase1-real-models/screenshots/real-08-math-embedding-sampled.png" width="100%" alt="Row-sampled visualization of a large Qwen embedding tensor"/></a><br/><b>Sampling you can see</b><br/>Previews disclose quality, row sampling, and coverage.</td>
43
+ </tr>
44
+ </table>
45
+
46
+ [Workspace](evidence/phase1-real-models/screenshots/real-01-workspace.png) · [Selecting a region](evidence/phase1-real-models/screenshots/real-03-attention-selected.png) · [Pyramid build](evidence/phase1-real-models/screenshots/real-05-embedding-building.png) · [ROI screenshots](evidence/phase1-roi/screenshots/) · [More UI screenshots](evidence/phase1-ui/screenshots/)
47
+
48
+ ## What works today
49
+
50
+ | Feature | Available | Interface |
51
+ | --- | --- | --- |
52
+ | Create projects, import local SafeTensors, inspect/search/filter tensor metadata | Yes | Browser app |
53
+ | Explore whole 2-D tensors (and 2-D slices of higher-rank tensors), pan/zoom/transpose, five aggregations | Yes | Browser app |
54
+ | Exact ROI heatmap and accessible per-cell values table | Yes | Browser app / Python |
55
+ | Exact tiles, streamed pyramids, labeled row-sampled previews, cancellable jobs | Yes | Browser app / local API |
56
+ | Base vs. fine-tuned checkpoint difference reports | Yes | CLI / Python |
57
+ | Supported PEFT LoRA effective-delta analysis | Yes | CLI / Python |
58
+ | Graphical checkpoint-delta overlays, Compare and Adapters screens | **Not yet** | Planned |
59
+ | Whole-tensor stats jobs, image/report export from UI, inference, activations, causal evaluations | **Not yet** | Planned |
60
+
61
+ **Important distinction:** You can compare checkpoints and supported LoRA adapters **today via the CLI**. The current UI visualizes *individual checkpoint tensors*, not a side-by-side checkpoint comparison.
62
+
63
+ ## Quickstart
64
+
65
+ **Requirements:** Python **3.12+**, [uv](https://docs.astral.sh/uv/), and Git. No GPU or Node.js is needed to **run** the app. Repository CI covers macOS, Linux, and Windows; the real-checkpoint visual evaluation was run on macOS/Chromium.
66
+
67
+ ```bash
68
+ git clone https://github.com/szaher/weightlab.git
69
+ cd weightlab
70
+ uv sync --locked
71
+ uv run weightlab start
72
+ ```
73
+
74
+ Open the link printed in your terminal, which looks like:
75
+
76
+ ```text
77
+ http://127.0.0.1:<port>/#token=...
78
+ ```
79
+
80
+ WeightLab serves the browser UI and local FastAPI backend on the same loopback origin. The URL contains a **per-launch access token**: open it locally, don't share it, and keep the terminal running.
81
+
82
+ ### Your first five minutes
83
+
84
+ 1. Click **Create project** in the browser.
85
+ 2. Import a checkpoint by **absolute path**, specifying an allowed **selected root**. You can use the repository's bundled `examples/fixtures/tiny_base.safetensors` and make `examples/fixtures` the selected root. This reads the file *in place*; there is no upload.
86
+ 3. Open **Explore**, select a 2-D weight tensor, and inspect its shape, dtype, and metadata.
87
+ 4. Open **Overview** to pan, zoom, change aggregation (mean, mean-absolute, RMS, min, max), and select a region.
88
+ 5. Choose **Inspect exact values** to see the original source values in the Exact ROI heatmap or values table.
89
+
90
+ Print the fixture's absolute paths if needed:
91
+
92
+ ```bash
93
+ uv run python -c "from pathlib import Path; p=Path('examples/fixtures').resolve(); print('Root:',p); print('Model:',p/'tiny_base.safetensors')"
94
+ ```
95
+
96
+ **No models to download:** the bundled deterministic fixtures are enough to try the UI and CLI. To reproduce the real-Qwen workflow, see the [pinned checkpoint validation](evidence/phase1-real-models/README.md).
97
+
98
+ ### Install a local wheel
99
+
100
+ ```bash
101
+ uv build --wheel
102
+ uv tool install dist/weightlab-*.whl
103
+ weightlab start
104
+ ```
105
+
106
+ The wheel includes the compiled web UI, so **Node.js is only needed to rebuild it**. WeightLab **`0.1.0a1` (alpha)** is being prepared for PyPI. After the first release is published, install with `uv tool install "weightlab==0.1.0a1"` or `python -m pip install "weightlab==0.1.0a1"`. Until then, use the source or local wheel instructions above.
107
+
108
+ ## Compare checkpoints
109
+
110
+ Use `weightlab diff` to measure numerical changes between two checkpoints, including compatible sharded SafeTensors directories:
111
+
112
+ ```bash
113
+ uv run weightlab diff \
114
+ examples/fixtures/tiny_base.safetensors \
115
+ examples/fixtures/tiny_ft.safetensors \
116
+ --out ./weightlab-report
117
+
118
+ # report.json, report.md, tensors.csv, layers.csv, roles.csv
119
+ ```
120
+
121
+ For your own checkpoints:
122
+
123
+ ```bash
124
+ uv run weightlab diff /path/to/base /path/to/fine-tuned --out /path/to/reports
125
+ ```
126
+
127
+ Or inspect a supported **PEFT LoRA** adapter's effective weight changes against its base:
128
+
129
+ ```bash
130
+ uv run weightlab diff \
131
+ examples/fixtures/tiny_base.safetensors \
132
+ --adapter examples/fixtures/tiny_lora \
133
+ --out ./weightlab-lora-report
134
+ ```
135
+
136
+ Reports include per-tensor and rollup **delta L2, delta RMS, relative L2, cosine similarity, max absolute delta, and non-finite counts**. Compatibility classes distinguish verified file identity from declared lineage or mere shape matching. Support for LoRA variants is intentionally limited and unsupported modules are reported rather than silently interpreted.
137
+
138
+ **Exit codes:** `0` means complete; `3` means a report was written but is **incomplete**; `2` means error; `130` means cancelled. Check `complete` and any caveats before interpreting results.
139
+
140
+ Full details: [CLI reference, metrics and LoRA support](docs/cli/weightlab-diff.md).
141
+
142
+ ## Python API
143
+
144
+ Read a bounded region from a checkpoint without loading the whole model:
145
+
146
+ ```python
147
+ from weightlab import open_checkpoint
148
+ from weightlab.analysis.roi import encode_roi
149
+
150
+ with open_checkpoint(
151
+ "examples/fixtures/tiny_base.safetensors",
152
+ selected_root="examples/fixtures",
153
+ ) as checkpoint:
154
+ print(checkpoint.metadata()[:3])
155
+ roi = checkpoint.read_roi_raw("demo.layers.0.mlp.up_proj.weight", 0, 4, 0, 8)
156
+ print(encode_roi(roi).to_json())
157
+ ```
158
+
159
+ Compute a structured change report:
160
+
161
+ ```python
162
+ from weightlab.analysis.change_report import Options, run
163
+
164
+ report = run(
165
+ "examples/fixtures/tiny_base.safetensors",
166
+ "examples/fixtures/tiny_ft.safetensors",
167
+ options=Options(sort="relative_l2"),
168
+ )
169
+ print(report["complete"])
170
+ ```
171
+
172
+ The Python API remains **pre-release**. See [change report documentation](docs/cli/weightlab-diff.md) and [reader implementation](weightlab/formats/checkpoint.py).
173
+
174
+ ## How it works
175
+
176
+ ```mermaid
177
+ flowchart LR
178
+ A["Local SafeTensors files"] --> B["Strict read-only reader"]
179
+ B --> C["Catalog and project metadata"]
180
+ B --> D["Bounded tile + pyramid engine"]
181
+ D --> E["Whole-tensor heatmaps"]
182
+ E --> F["Exact ROI drilldown"]
183
+ B --> F
184
+ B --> G["Streaming diff / LoRA analysis"]
185
+ G --> H["JSON / CSV / Markdown reports"]
186
+ ```
187
+
188
+ - **Strict file reader:** validates metadata, shards, offsets, and paths; reads only bounded file regions.
189
+ - **Visual layer:** multiresolution `256 × 256` tiles, optional exact pyramids, explicit row-sampled previews, and distinct coverage/precision labels.
190
+ - **Numerical layer:** raw ROI values are lossless; tile aggregate visualizations use float32 and must not be mistaken for exact individual parameters. Non-finite values and unrepresentable numbers get explicit states.
191
+ - **Application:** local FastAPI + React, SQLite for projects, bounded job handling and cache budgets.
192
+
193
+ ### Privacy and security
194
+
195
+ WeightLab runs locally by default and does not require a cloud account. The server accepts **loopback-only** binds and protects its local API with a launch token. Imported model files are read in place, not uploaded, rewritten, or deleted when a project is deleted. The application is designed without background telemetry or model-data exfiltration. Reports contain tensor names, shapes, statistics, file names, sizes, and possibly digests, so **review reports before sharing**. See [security design](docs/12_SECURITY_AND_PRIVACY.md).
196
+
197
+ ### Verified on real models
198
+
199
+ The project contains reproducible validation against pinned **Qwen2.5-0.5B / Instruct** and **Qwen2.5-Math-1.5B / Instruct** checkpoints. The recorded macOS run compared **1,256 tensor metadata entries**, **184 exact ROI windows**, and **1,048 tiles** with an independent reader. It reported zero mismatches for the described numerical checks. During that run the backend's **peak RSS was 166.3 MiB**, with a **36 GiB RAM / Apple M3 Pro** host; this is a benchmark observation, **not** a general memory guarantee or proof of the 8 GiB laptop target.
200
+
201
+ Reproduce the measurements and inspect limitations in [real model evidence](evidence/phase1-real-models/README.md) and [the machine-readable benchmark](evidence/phase1-real-models/results/benchmark.json). Browser validation was in Chromium; a practitioner usability study has **not** been completed.
202
+
203
+ ## Current scope and limitations
204
+
205
+ - **Format:** SafeTensors (single files or sharded indexes). No GGUF, PyTorch `.bin`, or general quantized checkpoint format support.
206
+ - **Overview:** whole-tensor heatmap aggregation is not a lossless display of every original scalar. Use **Exact ROI** for actual values.
207
+ - **Comparison:** numerical deltas are not causal evidence of improved behavior; independent checkpoints may be poorly aligned even when shapes match.
208
+ - **UI:** Compare/Adapters pages, graphical delta/LoRA overlays, stats jobs, and UI export are not built.
209
+ - **Experimental features:** inference, activations, transfer experiments, and evaluation are not present.
210
+ - **Maturity:** pre-release; field-tested practitioner feedback, non-Chromium browser coverage, and the intended 8 GiB laptop target remain unverified.
211
+
212
+ ## Development and contributing
213
+
214
+ The code is under active development. Use reproducible fixtures, add tests for numerical and security behavior, and avoid weakening validation to satisfy an acceptance gate.
215
+
216
+ ```bash
217
+ uv sync --locked
218
+ uv run pytest
219
+ uv run ruff format --check .
220
+ uv run ruff check .
221
+ uv run mypy
222
+ ```
223
+
224
+ Frontend changes require Node.js (see [frontend documentation](frontend/README.md)):
225
+
226
+ ```bash
227
+ cd frontend
228
+ npm ci
229
+ npm run lint
230
+ npm run typecheck
231
+ npm test
232
+ npm run build
233
+ npx playwright install chromium
234
+ npm run e2e
235
+ ```
236
+
237
+ **Explore further:** [evaluation kit](evaluation-kit/README.md) · [test evidence](evidence/) · [OpenAPI contract](contracts/openapi.yaml) · [architecture](docs/03_SYSTEM_ARCHITECTURE.md) · [numerical methods](docs/05_NUMERICAL_METHODS.md) · [roadmap](docs/14_DELIVERY_ROADMAP.md) · [issue tracker](https://github.com/szaher/weightlab/issues).
238
+
239
+ For publishing and packaging instructions, see [RELEASING.md](RELEASING.md).
240
+
241
+ The detailed version **1.2-final specification** remains a frozen engineering baseline; it is **not** the current implementation status. Some historical planning documents and examples describe future behavior, so treat the tested source code and evidence above as the authority for currently working features.
242
+
243
+ ## License
244
+
245
+ No explicit repository-wide open-source license has been selected in the current source tree. **Do not assume the code is licensed for reuse or redistribution** until a license is added. Contributions and distribution should be discussed with the maintainer.
@@ -0,0 +1,118 @@
1
+ [project]
2
+ name = "weightlab"
3
+ version = "0.1.0a1"
4
+ description = "Explore LLM weights locally: heatmaps, exact tensor inspection, checkpoint and LoRA change reports."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ classifiers = [
8
+ "Development Status :: 3 - Alpha",
9
+ "Intended Audience :: Developers",
10
+ "Intended Audience :: Science/Research",
11
+ "Operating System :: OS Independent",
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
15
+ ]
16
+ dependencies = [
17
+ "numpy==2.5.4",
18
+ "fastapi==0.162.0",
19
+ "pydantic==2.14.3",
20
+ "uvicorn==0.54.0",
21
+ "platformdirs==4.14.5",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/szaher/weightlab"
26
+ Source = "https://github.com/szaher/weightlab"
27
+ Documentation = "https://github.com/szaher/weightlab#readme"
28
+ Issues = "https://github.com/szaher/weightlab/issues"
29
+
30
+ [project.scripts]
31
+ weightlab = "weightlab.cli:main"
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "pytest==9.2.0",
36
+ "hypothesis==6.170.14",
37
+ "ruff==0.17.4",
38
+ "mypy==2.4.1",
39
+ "safetensors==0.8.0",
40
+ "jsonschema==4.26.0",
41
+ "pyyaml==6.0.3",
42
+ "httpx2==2.16.0",
43
+ ]
44
+
45
+ [build-system]
46
+ requires = ["uv_build>=0.13.4,<0.14"]
47
+ build-backend = "uv_build"
48
+
49
+ [tool.uv.build-backend]
50
+ module-root = ""
51
+
52
+ [tool.ruff]
53
+ line-length = 120
54
+ target-version = "py312"
55
+ extend-exclude = [
56
+ "examples",
57
+ "tests/fixtures/generated",
58
+ "*.md",
59
+ "scripts/build_documentation.py",
60
+ "scripts/check_contracts.py",
61
+ "scripts/check_demo_fixtures.py",
62
+ "scripts/check_spec.py",
63
+ "scripts/generate_demo_fixtures.py",
64
+ "scripts/manifest.py",
65
+ ]
66
+
67
+ [tool.ruff.lint]
68
+ select = [
69
+ "E",
70
+ "F",
71
+ "W",
72
+ "I",
73
+ "B",
74
+ "UP",
75
+ "SIM",
76
+ "RUF",
77
+ "PT",
78
+ "S",
79
+ ]
80
+ ignore = [
81
+ "S101",
82
+ "RUF001",
83
+ "RUF002",
84
+ "RUF003",
85
+ ]
86
+
87
+ [tool.ruff.lint.per-file-ignores]
88
+ "tests/**" = [
89
+ "S603",
90
+ "S108",
91
+ "S311",
92
+ "S104",
93
+ ]
94
+ "scripts/**" = [
95
+ "S603",
96
+ "S607",
97
+ "E501",
98
+ ]
99
+ "evaluation-kit/**" = ["S603"]
100
+ "evidence/**" = [
101
+ "S603",
102
+ "S607",
103
+ "S310",
104
+ "S311",
105
+ "E501",
106
+ ]
107
+ "weightlab/db/store.py" = ["S608"]
108
+
109
+ [tool.mypy]
110
+ python_version = "3.12"
111
+ strict = true
112
+ packages = ["weightlab"]
113
+
114
+ [tool.pytest.ini_options]
115
+ testpaths = ["tests"]
116
+ addopts = "-ra --strict-markers"
117
+ markers = ["perf: resource measurements on large sparse files (run by default; WEIGHTLAB_SKIP_PERF=1 skips)"]
118
+ xfail_strict = true