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
Atlas extraction (convenience)
from fisher_torch import extract_for_atlas
attention, seq_lens = extract_for_atlas(model, tokenizer, texts, layers=[0, 15, 31])
# attention.shape == (n_prompts, n_positions, n_layers, n_heads, max_seq_len)
# attention.dtype == np.float64
# seq_lens gives each prompt's valid token count
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), capture_batch (multi-prompt with alignment), extract_for_atlas (convenience) |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fisher_torch-0.3.1.tar.gz.
File metadata
- Download URL: fisher_torch-0.3.1.tar.gz
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5c20b95b547d6a1c4b66f353e47fa97d79c2981d7cc9ee7905c04a9d1dba125
|
|
| MD5 |
40c63f37508c8e8e09527055770cbd77
|
|
| BLAKE2b-256 |
1b9460dc0de7c721d37a1f77b6c8516d2f9a1cc3281e3b0269b1df67103a6c44
|
Provenance
The following attestation bundles were made for fisher_torch-0.3.1.tar.gz:
Publisher:
workflow.yml on syzygyhack/fisher-torch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fisher_torch-0.3.1.tar.gz -
Subject digest:
d5c20b95b547d6a1c4b66f353e47fa97d79c2981d7cc9ee7905c04a9d1dba125 - Sigstore transparency entry: 1258200014
- Sigstore integration time:
-
Permalink:
syzygyhack/fisher-torch@a46958464e88ffe1ff5985f6ccf2f36a94fc316c -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/syzygyhack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a46958464e88ffe1ff5985f6ccf2f36a94fc316c -
Trigger Event:
push
-
Statement type:
File details
Details for the file fisher_torch-0.3.1-py3-none-any.whl.
File metadata
- Download URL: fisher_torch-0.3.1-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a61e31686110cec2a8cd5785875673b9b98b4abc664b5619430bcc2271ae3df7
|
|
| MD5 |
df3ee9b2907e8faa34606f553f334720
|
|
| BLAKE2b-256 |
e076090a859336c80db0316bf4b85f095cf2f1358aa2ca881e7a5eb19b095053
|
Provenance
The following attestation bundles were made for fisher_torch-0.3.1-py3-none-any.whl:
Publisher:
workflow.yml on syzygyhack/fisher-torch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fisher_torch-0.3.1-py3-none-any.whl -
Subject digest:
a61e31686110cec2a8cd5785875673b9b98b4abc664b5619430bcc2271ae3df7 - Sigstore transparency entry: 1258200024
- Sigstore integration time:
-
Permalink:
syzygyhack/fisher-torch@a46958464e88ffe1ff5985f6ccf2f36a94fc316c -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/syzygyhack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a46958464e88ffe1ff5985f6ccf2f36a94fc316c -
Trigger Event:
push
-
Statement type: