Skip to main content

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 probability 1 − (1 − 1/(T−1))^K.
  • batch_check=True (default when B>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.

Metadata

Release files for causal-certificate 0.1.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 causal-certificate 0.1.0
File Size Uploaded Provenance
causal_certificate-0.1.0.tar.gz 9.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for causal-certificate 0.1.0
File Interpreter ABI Platform
causal_certificate-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / causal_certificate-0.1.0.tar.gz

Download URL causal_certificate-0.1.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c1917b92b95eb601083ebf9b303f249a84e21cbeb4d0a0b1067ed8082e263f25
BLAKE2b-256 checksum
How to use checksums
e92d0ab1a5dc8fc1a1ea664a19d78b1de877c738e6cb62ef0b597c57fde6de2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 2, 2026.

Transparency log

Release files / causal_certificate-0.1.0-py3-none-any.whl

Download URL causal_certificate-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eca0d0bde67dc0db21ad28001a2780a081caf74642f11655b14d29e797a02ae2
BLAKE2b-256 checksum
How to use checksums
c51f1a22ed033b29f73f5d834599cbd9d6dbea6792c0fa3d870f5e755a513c14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 2, 2026.

Transparency log

Security for causal-certificate 0.1.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for causal_certificate-0.1.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 Jul 2, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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