Skip to main content

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, streamed to avoid 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

Remote checkpoints (safetensors)

Analyze checkpoints straight from object storage. Only tensor bytes are fetched, nothing is downloaded or consolidated:

pip install weightlens[s3]     # or [gcs], or [remote] for local fsspec only

lens analyze s3://bucket/model.safetensors
lens analyze s3://bucket/model.safetensors.index.json   # sharded
lens analyze gs://bucket/model.safetensors

Credentials use your existing AWS/GCS credential chain (env vars, ~/.aws/..., instance roles). Weightlens stores no secrets. Remote .pth is supported via download-to-cache (.pth cannot be byte-ranged).

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.

Contributing

  1. Clone this repo.
  2. Set up a virtual environment. The standard is uv (no requirements.txt).
  3. Run uv pip install -e .[dev]
  4. Start contributing.

If you would like to contribute, please do create Pull Requests.

Final Notes

This library is not perfect and is actively developed.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weightlens-0.2.0.tar.gz (74.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weightlens-0.2.0-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

File details

Details for the file weightlens-0.2.0.tar.gz.

File metadata

  • Download URL: weightlens-0.2.0.tar.gz
  • Upload date:
  • Size: 74.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for weightlens-0.2.0.tar.gz
Algorithm Hash digest
SHA256 823f28f9a96148e86ae40a3989ad360444b52f13c11a34effb16a645e0517bb7
MD5 42abdd4c8a388b4cc4ef6cfae2b4f98f
BLAKE2b-256 94428fee1a60d9ee017606d77e29ba9a7cbf96dbb5c80e6ef8f54bb2eb322471

See more details on using hashes here.

Provenance

The following attestation bundles were made for weightlens-0.2.0.tar.gz:

Publisher: publish.yml on akshathmangudi/weightlens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file weightlens-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: weightlens-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 48.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for weightlens-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88c961e81bed1c8a32123ad4d52ec7b5d1822201bc97bbe83a1538fb5266540e
MD5 974facad320f440be3265c26bfa18216
BLAKE2b-256 0168ecad8246feeaa2c781d6a97c6beccabf19fe4e8649c5cb1c70352864c6e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for weightlens-0.2.0-py3-none-any.whl:

Publisher: publish.yml on akshathmangudi/weightlens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page