A numeric strict-causality (and cross-example independence) certificate for PyTorch sequence models, via vector-Jacobian products.
Project description
causal-certificate
A small, numeric strict-causality certificate for PyTorch sequence models.
One forward pass + T−1 vector-Jacobian products tells you whether any output at
position t depends on an input at position s > t — the silent bug that
manufactures phantom autoregressive results.
from causal_certificate import certify, assert_strictly_causal
report = certify(my_mixer, x) # x: (B, T, D) float; my_mixer: x -> y
print(report.summary())
# CausalCertificate(T=128, exhaustive cuts)
# temporal : leak=0.000e+00 frac=0.000e+00 -> STRICTLY CAUSAL
# cross-batch: leak=0.000e+00 frac=0.000e+00 -> BATCH-INDEPENDENT
assert_strictly_causal(my_mixer, x) # drop into a pytest
Why
A "blockwise causal" Walsh–Hadamard token mixer once produced a 7.21× lower BPB
than a matched transformer — a number that reached a provisional patent application
before it was found to be a within-block future-token leak. Standard sanity checks
passed because they probed across-block causality; the violation lived inside
blocks. This tool is the check that would have caught it in CI. (Case study &
full write-up: papers/causality_leaks/.)
What it catches (three leak classes)
| Class | Example | Caught by |
|---|---|---|
| Temporal (position) leak | block-WHT / FFT / butterfly mixing; off-by-one causal masks; KV/RoPE drift | exhaustive-cut temporal certificate |
| Pooled/block readout | a block statistic broadcast back to every position | temporal certificate |
| Batch/sequence-statistic coupling | batchnorm-style couplings across the batch | cross-batch certificate (per-example probes are blind to it) |
Genuinely-causal ops certify at exactly 0.0 (structural autograd zeros) — in fp32 as well as fp64 — so there is no per-model threshold tuning. Validated on external attention/conv models it never saw: causal MHA and causal conv → 0.0; an injected off-by-one mask and a batchnorm coupling → flagged.
Modes
certify(fn, x, cuts="all")— the certificate (exhaustive cuts, complete).certify(fn, x, cuts="rand", K=8)— a cheap always-on training monitor; a single-pair leak is caught with probability1 − (1 − 1/(T−1))^K.batch_check=True(default whenB>1) — adds the cross-batch certificate.
Scope & honest attribution
This is a numeric certificate on a given architecture/config (generic inputs and
random cotangents), not a symbolic proof; detection is almost-sure, not worst-case
adversarial; it assumes equal input/output sequence length. The method is not
novel — it packages known probes: Karpathy's 2019 backprop-from-t temporal
check, the per-cut VJP gradient energy of Effective Context in Neural Speech
Models (arXiv:2505.22487), and Krokotsch's 2020 batch-independence unit test. The
contribution is the packaging: exhaustive-cut completeness + the cross-batch
extension, as a single drop-in certificate for sequence-model CI.
Install & test
pip install -e . # editable install (src layout)
pytest # or: python tests/test_external_models.py
The generalization test certifies external causal attention / conv at exactly 0.0, and fires on an injected off-by-one mask and a batch-statistic coupling.
Project details
Release history Release notifications | RSS feed
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 causal_certificate-0.1.0.tar.gz.
File metadata
- Download URL: causal_certificate-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1917b92b95eb601083ebf9b303f249a84e21cbeb4d0a0b1067ed8082e263f25
|
|
| MD5 |
6b5a573859783c0f4b91b8bd1a06a49c
|
|
| BLAKE2b-256 |
e92d0ab1a5dc8fc1a1ea664a19d78b1de877c738e6cb62ef0b597c57fde6de2b
|
Provenance
The following attestation bundles were made for causal_certificate-0.1.0.tar.gz:
Publisher:
publish.yml on Akhilesh-Gogikar/causal-certificate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
causal_certificate-0.1.0.tar.gz -
Subject digest:
c1917b92b95eb601083ebf9b303f249a84e21cbeb4d0a0b1067ed8082e263f25 - Sigstore transparency entry: 2048492436
- Sigstore integration time:
-
Permalink:
Akhilesh-Gogikar/causal-certificate@ffd752a60840a196ce655722e6185c39d50693f1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Akhilesh-Gogikar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ffd752a60840a196ce655722e6185c39d50693f1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file causal_certificate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: causal_certificate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.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 |
eca0d0bde67dc0db21ad28001a2780a081caf74642f11655b14d29e797a02ae2
|
|
| MD5 |
848b65a3c9a4834da624893c59306b04
|
|
| BLAKE2b-256 |
c51f1a22ed033b29f73f5d834599cbd9d6dbea6792c0fa3d870f5e755a513c14
|
Provenance
The following attestation bundles were made for causal_certificate-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Akhilesh-Gogikar/causal-certificate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
causal_certificate-0.1.0-py3-none-any.whl -
Subject digest:
eca0d0bde67dc0db21ad28001a2780a081caf74642f11655b14d29e797a02ae2 - Sigstore transparency entry: 2048492463
- Sigstore integration time:
-
Permalink:
Akhilesh-Gogikar/causal-certificate@ffd752a60840a196ce655722e6185c39d50693f1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Akhilesh-Gogikar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ffd752a60840a196ce655722e6185c39d50693f1 -
Trigger Event:
release
-
Statement type: