Skip to main content

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

  • dev is the integration branch: push work and open feature pull requests against dev.
  • main only receives pull requests from dev, merged with a merge commit. Each merge into main is a release: the Release workflow runs the CI, publishes the package to PyPI, then tags vX.Y.Z and creates the GitHub release.
  • Before opening the dev → main pull request, bump project.version in pyproject.toml above the latest version on PyPI. The Release gate checks reject pull requests into main that do not come from dev or that reuse a published version; branch rules on main require these checks and the CI to pass.

Metadata

Release files for tensor-spectra 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tensor-spectra 0.4.0
File Size Uploaded Provenance Actions
tensor_spectra-0.4.0.tar.gz 862.5 kB With provenance Details for tensor_spectra-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tensor-spectra 0.4.0
File Interpreter ABI Platform Actions
tensor_spectra-0.4.0-py3-none-any.whl Python 3 none any Details for tensor_spectra-0.4.0-py3-none-any.whl

Total release size: 1.0 MB

Release files / tensor_spectra-0.4.0.tar.gz

Download URL tensor_spectra-0.4.0.tar.gz
Size 862.5 kB
Tags Source
SHA-256 checksum
How to use checksums
48f8d8a6a86cdf607bf50e4f109570004e720192507a5915237c5541f4f38dc6
BLAKE2b-256 checksum
How to use checksums
31afa96ca302509fb50a4bfbfdf9703a60969bfe64aba39a313672c40ff330bf
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 log

Release files / tensor_spectra-0.4.0-py3-none-any.whl

Download URL tensor_spectra-0.4.0-py3-none-any.whl
Size 147.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db36a58e071cbd3ccdb74480fbec560dcf6dc3067b64246bc6b218a49424b641
BLAKE2b-256 checksum
How to use checksums
6c2fa37ce9d4e229be6d458c73be662d0dc87610fa6340d490cb9e399af0bcd4
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 log

Security for tensor-spectra 0.4.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.

Select from 2 files

Attestation for tensor_spectra-0.4.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page