Skip to main content

Extract simplex arrays from PyTorch model outputs

Project description

fisher-torch

Extract simplex arrays from PyTorch model outputs.

Built on fisher-simplex for simplex geometry and invariants.

Install

pip install fisher-torch

With transformers support:

pip install fisher-torch[transformers]

Quick start

import torch
from fisher_torch import extract_predictions, capture_forward
from fisher_torch import SamplingPolicy

# From raw logits
logits = torch.randn(10, 50000)  # (seq_len, vocab_size)
simplex = extract_predictions(logits, top_k=50)
# simplex.shape == (10, 51)  — top-50 + remainder bin, valid simplex

# From a HuggingFace model
policy = SamplingPolicy(top_k=50, final_token_only=True)
result = capture_forward(model, input_ids, predictions=True, policy=policy)
# result.predictions is a float64 numpy simplex array
# result.projection_spec describes the projection geometry

Multi-prompt batch extraction

from fisher_torch import capture_batch, SamplingPolicy

prompts = [tokenizer.encode(p, return_tensors="pt") for p in texts]
policy = SamplingPolicy(position_preset="atlas")
batch = capture_batch(model, prompts, attention=True, policy=policy)
# batch.aligned_attention.shape ==
#   (n_prompts, n_layers, n_heads, n_positions, max_seq_len)
# batch.metadata["seq_lens"] gives each prompt's valid length

Gradient-enabled extraction

result = capture_forward(
    model, input_ids,
    predictions=True, attention=True,
    no_grad=False,
)
# result.prediction_tensors — torch.Tensor with grad graph intact
# result.attention_tensors  — dict[int, Tensor]
result.detach_to_numpy()  # convert tensor fields to numpy in-place

Raw hidden states

result = capture_forward(
    model, input_ids,
    predictions=False, hidden_states=True, raw_hidden_states=True,
)
# result.hidden_states     — logit-lens projected predictions per layer
# result.raw_hidden_states — raw vectors without lm_head projection

Modules

Module Purpose
extractors Stateless functions: logits, attention, hidden states, routing → simplex arrays
capture capture_forward (single pass) and capture_batch (multi-prompt with alignment)
convert Tensor ↔ numpy simplex conversion, stack_attention, truncate_and_renormalize
sampling SamplingPolicy — layers, heads, positions, presets ("atlas", "quartiles")
utils Numerically stable softmax, top-k simplex projection, device helpers

Project details


Download files

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

Source Distribution

fisher_torch-0.3.0.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

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

fisher_torch-0.3.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file fisher_torch-0.3.0.tar.gz.

File metadata

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

File hashes

Hashes for fisher_torch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9962f3a47beb1a15851e58e3c2764d8ad6296149eb0ebe89d8049233d40aa963
MD5 90461bc5fbb20fa216c79d18907041bd
BLAKE2b-256 149c5e5cb9099a953e8f0e55e69ccc3f1c11b4c05edf2ef4d4d9e250c57763bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fisher_torch-0.3.0.tar.gz:

Publisher: workflow.yml on syzygyhack/fisher-torch

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

File details

Details for the file fisher_torch-0.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for fisher_torch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8576b8960cba80aa26711d317434f931181bfdb0248feb6aef8544d274a4b144
MD5 8a6d8306a7c92a2c20b58b3fdd359080
BLAKE2b-256 765e6acf4b6b0f90e256bade7904336120da6493dbe8cfca4936b5fb234259d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fisher_torch-0.3.0-py3-none-any.whl:

Publisher: workflow.yml on syzygyhack/fisher-torch

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 Pingdom Monitoring Sentry Error logging StatusPage Status page