Statistical model analysis for ML model weights.
Project description
weightlens
Weightlens is an analysis tool for checkpoint weights.
What it solves
- Corruption detection (empty / partial failures, tensor access failures and NaN/zero floods)
- Per-layer metrics (mean, std, min/max, L2 norm, sparsity and p99 absolute)
- Global distribution stats which are streamed to prevent OOM and memory crashes.
- deterministic diagnostics for unhealthy layers.
What's next?
- Improve diagnostics by bucketing components and softening constraints (bias, weights, norm_params, etc.)
- Integrate checkpoint diffing - compare regressions, drift, and training failures between two or more checkpoints
- Extend Weightlens for
h5,safetensors,joblib, etc. (DCP has been covered from a user request.) - Research on deeper failure modes and detecting them accurately.
Performance
Benchmarked on an ultrabook (Intel 4-core, 8GB LPDDR3, SATA SSD ~500 MB/s):
| Checkpoint | Format | Size | Tensors | Params | Wall time |
|---|---|---|---|---|---|
| BEiT-3 training checkpoint | .pth |
8 GB | 977 | 676M | ~29s |
| Mixtral MoE (multi-shard) | DCP | 70 GB | 456 | 20B | ~293s |
Performance is I/O-bound on SATA SSDs. On NVMe storage (3-7 GB/s), expect roughly proportional speedups. The --num-workers flag enables parallel stats computation which helps when I/O is not the bottleneck.
To use
Simply run pip install weightlens into your virtual environment and start by running:
lens analyze <filename>.pth
lens analyze <dcp_directory> --format dcp
lens analyze <checkpoint>.pth --num-workers 2
Demo: corrupted checkpoints
Generate a clean checkpoint and two corrupted variants, then compare manual loading versus Weightlens diagnostics.
python demo/make_clean_ckpt.py
python demo/corrupt_ckpt.py
lens analyze demo/checkpoints/clean.pth
lens analyze demo/checkpoints/corrupted_zero.pth
lens analyze demo/checkpoints/corrupted_spike.pth
If lens is not on your PATH, use python -m weightlens.cli analyze ... instead.
Status
ALL TESTS AND LINT CHECKS PASS.
Contributing
- Step 0: Clone this repo.
- Step 1: Setup a virtual environment of your choice. The standard is uv as a
requirements.txtdoes not exist here. - Step 2: Run
uv pip install -e .[dev] - Step 3: Start contributing!
If you would like to contribute, please do create Pull Requests.
Final Notes
This was a weekend project to work on, but it solves a real frustration by shedding some light onto how model checkpoints fail all the time. This library is NOT perfect. I will work on it!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weightlens-0.1.2.tar.gz.
File metadata
- Download URL: weightlens-0.1.2.tar.gz
- Upload date:
- Size: 39.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd61ca46c1883187c358ddfec6e0e51bfad7ec3d175e3732a6f230c74be426f7
|
|
| MD5 |
1c31b97f3f1f6967d70333ef47420ffc
|
|
| BLAKE2b-256 |
81032b71c8195709169ac7eb16a5a7d7ef966cf49beee51d9bf7d0874ec3325f
|
Provenance
The following attestation bundles were made for weightlens-0.1.2.tar.gz:
Publisher:
publish.yml on akshathmangudi/weightlens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
weightlens-0.1.2.tar.gz -
Subject digest:
fd61ca46c1883187c358ddfec6e0e51bfad7ec3d175e3732a6f230c74be426f7 - Sigstore transparency entry: 975921178
- Sigstore integration time:
-
Permalink:
akshathmangudi/weightlens@3ba0c2a708eec622c4a27907b1a756b16fd3cf90 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/akshathmangudi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ba0c2a708eec622c4a27907b1a756b16fd3cf90 -
Trigger Event:
push
-
Statement type:
File details
Details for the file weightlens-0.1.2-py3-none-any.whl.
File metadata
- Download URL: weightlens-0.1.2-py3-none-any.whl
- Upload date:
- Size: 36.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72a932a0b04c230bafec67ae867f7cd87078a753e93667c0c2e1d04841b315ba
|
|
| MD5 |
925b3e6d3a63e543addffa974bdb56a7
|
|
| BLAKE2b-256 |
58b59825ba7a27781b9dac2b9e59c23c88c04978a44cf95e110f957acd5c84e8
|
Provenance
The following attestation bundles were made for weightlens-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on akshathmangudi/weightlens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
weightlens-0.1.2-py3-none-any.whl -
Subject digest:
72a932a0b04c230bafec67ae867f7cd87078a753e93667c0c2e1d04841b315ba - Sigstore transparency entry: 975921182
- Sigstore integration time:
-
Permalink:
akshathmangudi/weightlens@3ba0c2a708eec622c4a27907b1a756b16fd3cf90 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/akshathmangudi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ba0c2a708eec622c4a27907b1a756b16fd3cf90 -
Trigger Event:
push
-
Statement type: