TensorSpectra
TensorSpectra is a reproducible Python framework for extracting user-selected tensor populations from Hugging Face Transformer models and computing numerical and spectral descriptors. The KV cache is the flagship target, accompanied by queries, hidden states, MLP activations, attention maps, and decoder projection weights.
Every run pins the model revision, records the resolved configuration, its hash, and the environment, and writes a schema-versioned JSON result (plus an optional NPZ sidecar) that the figure renderer and the interactive explorer read without loading the model.
Installation
Install the PyPI package (Python 3.10 or newer):
python -m pip install tensor-spectra==0.2.0
python -m tensor_spectra --help
The distribution is named tensor-spectra; the Python import is tensor_spectra.
Quick start
Analyze a model (latest main revision, resolved to a commit SHA) with schema defaults —
KV-cache K/V, one synthetic sample of 1024 tokens, bfloat16, automatic device placement:
python -m tensor_spectra run --model HuggingFaceTB/SmolLM2-135M
A small CPU run with dotted overrides, a YAML config, or a dry run that only prints the plan:
python -m tensor_spectra run --model HuggingFaceTB/SmolLM2-135M \
--model.dtype float32 --model.device_map cpu --data.sequence_lengths '[32]'
python -m tensor_spectra run --config tests/configs/tiny.yaml
python -m tensor_spectra run --config tests/configs/tiny.yaml --dry-run
Render figures or explore a saved result:
python -m tensor_spectra figures --input runs/<run_name>/result.json --out figures
python -m tensor_spectra explore --input runs/<run_name>/result.json --port 8050
The same pipeline is available from Python:
from tensor_spectra.config import load_config
from tensor_spectra.pipeline import run_pipeline
outcome = run_pipeline(load_config("tests/configs/tiny.yaml"))
print(outcome.output_path)
Documentation
| Document | Contents |
|---|---|
| docs/architecture.md | Pipeline, module map, data model, invariants, how to add targets/metrics/figures |
| docs/configuration.md | Reproducibility, YAML configuration and overrides, model loading, run CLI options |
| docs/targets.md | Extraction targets (KV cache, queries, hidden states, MLP, attention, weights) and benchmark data |
| docs/analysis.md | Spectral engine, orchestration, cross-layer similarity, approximation, result logging |
| docs/model-analysis-output.md | Field-by-field reference of the result document |
| docs/visualization.md | Static figure catalogue and the web explorer |
| docs/figures-and-analysis.md | How to read each figure (local file, not versioned) |
| docs/examples.md | Real-model example scripts and presets |
| docs/history/ | Original specification and past audits |
Development
Install uv, then create the project environment and install the locked dependencies:
uv sync --dev
This creates .venv and uses the Python version in .python-version. Run commands inside the
environment without activating it:
uv run pytest
uv run ruff check .
uv run ruff format --check .
After changing dependencies, run uv lock and commit the updated uv.lock.
Numerical regressions are guarded by golden-output tests (tests/test_golden.py, see
tests/golden/README.md); analysis performance is measured with
benchmarks/bench_analysis.py on synthetic, model-shaped inputs.
Contributor and AI-agent orientation (commands, layout, conventions) is in AGENTS.md.
Branches and releases
devis the integration branch: push work and open feature pull requests againstdev.mainonly receives pull requests fromdev, merged with a merge commit. Each merge intomainis a release: theReleaseworkflow runs the CI, publishes the package to PyPI, then tagsvX.Y.Zand creates the GitHub release.- Before opening the
dev→mainpull request, bumpproject.versioninpyproject.tomlabove the latest version on PyPI. TheRelease gatechecks reject pull requests intomainthat do not come fromdevor that reuse a published version; branch rules onmainrequire these checks and the CI to pass.
Metadata
Release files for tensor-spectra 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tensor_spectra-0.3.0.tar.gz | 833.0 kB | With provenance | Details for tensor_spectra-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tensor_spectra-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for tensor_spectra-0.3.0-py3-none-any.whl |
Total release size: 967.5 kB
Release files / tensor_spectra-0.3.0.tar.gz
| Download URL | tensor_spectra-0.3.0.tar.gz |
|---|---|
| Size | 833.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37cb37c9117d3acfb68281007ea59ac54bfe7511c2724c531e203c1372eb0b71
|
|
BLAKE2b-256 checksum How to use checksums |
7281742799c4cd203f49310eec4e76b8df7fdf901d41c74b04b3986f6d643775
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logRelease files / tensor_spectra-0.3.0-py3-none-any.whl
| Download URL | tensor_spectra-0.3.0-py3-none-any.whl |
|---|---|
| Size | 134.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9258d6e583ec6d99b114cb30c82a299e32b1e212f4c6b2e2fc158f81d40f5c6c
|
|
BLAKE2b-256 checksum How to use checksums |
cb30678ba4b9ba28cb2bad16d7301be571fd95e1a3805a59072a8c8769b73c75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logSecurity for tensor-spectra 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tensor_spectra-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.