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.2.0.tar.gz (26.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.2.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fisher_torch-0.2.0.tar.gz
  • Upload date:
  • Size: 26.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.2.0.tar.gz
Algorithm Hash digest
SHA256 5af5ab99f24a3c5b12b1d8f17cd824aa844b008ba8f389939c27853a0e06cafa
MD5 cd7617c7e443b19f46d366428dc74aaa
BLAKE2b-256 487e32a4a97c5468abe86a09fe99c4d10b42a640664ac0b0ca78adb72bda87aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for fisher_torch-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: fisher_torch-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 103aa105477f7deba82e67810a945a5f2c5cdbdbb8127eff21a40c6908d4f580
MD5 1c1629bd690b84c165e45dea5bc539b9
BLAKE2b-256 a457fb08ff8b400c51eb53e4f972320529a753077e3c33afada5814f421e20de

See more details on using hashes here.

Provenance

The following attestation bundles were made for fisher_torch-0.2.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