Skip to main content

Sparse Attention Fabric

CI License

Sparse Attention Fabric is an evidence-first PyTorch execution planner for exact causal-window attention. The initial 0.1.0 release is intentionally narrow: it chooses among causal SDPA, masked SDPA, and compiled FlexAttention while exposing its decision and preserving PyTorch autograd.

This release is an executable hypothesis, not a performance claim. No controlled GPU result is bundled yet. Numeric thresholds in the M0 protocol are pre-registered targets. saf-m0-validate --release checks a supplied matrix's structure and semantics but does not authenticate its origin; a result becomes publishable only after validation and independent GitHub-attestation verification against the exact controlled workflow, default-branch ref, and candidate commit.

What ships in 0.1.0

  • An immutable CausalWindow pattern with exact token and block semantics.
  • A small, inspectable, cached ExecutionFabric policy.
  • Fail-closed CUDA execution through public PyTorch APIs.
  • A locked 19-case, four-implementation benchmark matrix with 380 fresh-process rows.
  • Raw-sample JSONL evidence, a JSON Schema, correctness checks, and release gates.
  • A deterministic, explicitly non-release A100 feasibility model for hardware-free auditing.
  • CPU contract tests plus a manually dispatched A100 evidence workflow.

M0 is not a general sparse tensor compiler, a custom CUDA kernel library, or an MoE runtime. See the architecture for the deliberate boundaries and the competitive landscape for the primary-source decision record. The evidence-gated roadmap states what can follow a positive, negative, or invalid controlled run.

Install

Planning and contract tests have no runtime dependency:

python -m pip install .

Evidence validation adds JSON Schema support:

python -m pip install '.[validation]'

CUDA execution requires the PyTorch 2.13 build appropriate for the machine. In controlled environments, install PyTorch from the official channel selected for the CUDA driver, then install this project without allowing pip to replace it:

python -m pip install --no-deps .
python -c 'import torch; print(torch.__version__, torch.version.cuda)'

The cuda and benchmark extras express compatible version constraints, but they cannot choose the correct CUDA wheel index for a particular host.

Use

from m0 import CausalWindow, ExecutionFabric

fabric = ExecutionFabric(max_cache_entries=32)
pattern = CausalWindow(window=512)
output = fabric(query, key, value, pattern)
plan = fabric.plan(
    pattern,
    sequence_length=query.shape[-2],
    dtype=str(query.dtype).removeprefix("torch."),
)
print(plan.backend, plan.rationale)

# Optional for a tight loop: validates once and retains metadata, not tensors.
prepared = fabric.prepare(query, key, value, pattern)
next_output = prepared(next_query, next_key, next_value)

Inputs must be contiguous CUDA BHLD tensors with FP16 or BF16 dtype, equal query/KV head counts and lengths, and head/value dimensions of 64 or 128. Unsupported inputs raise an error instead of silently changing semantics. Prepared calls reject a changed shape, stride, device, dtype, pattern, or autograd context; call prepare again when any execution metadata changes. The entry limit applies independently to plans, masks, compiled Flex functions, prepared executors, and device capabilities. Slow-path insertions evict the oldest entry; hot prepared-cache hits remain lock-free. Inspect the configured limit and current occupancy with fabric.cache_info().

For a complete projection-to-attention-to-output module, see the Transformer-style integration example.

Validate locally

python -m unittest discover -s tests -p 'test_*.py' -v
python -m json.tool m0/core_cases.json >/dev/null
python -m json.tool m0/result.schema.json >/dev/null
python -m json.tool m0/feasibility.schema.json >/dev/null
saf-m0 --help
saf-m0-model --help
saf-m0-validate --help

Run the full benchmark only on a controlled Linux CUDA host. The canonical protocol, operator attestations, commands, interpretation rules, and known limitations are in the M0 evidence guide and benchmark operations guide.

When the target GPU is unavailable, run saf-m0-model to audit exact pair counts, block rounding, visible storage, and peak-rate sensitivity envelopes. The modeled-validation guide states what the model can and cannot establish. Its output is structurally barred from release validation.

Evidence and claims

Every release-quality performance statement must link to the immutable JSONL, validated summary, verified GitHub attestations, exact commit, hardware/software environment, and timing scope. A detached artifact or checksum is not proof of a controlled run. Unsupported, OOM, correctness-failure, and negative-performance rows are part of the result and must not be removed. Modeled hardware results may guide engineering but may never be reported as measured CUDA performance. The direct baselines are SDPA, generic FlexAttention, and native PyTorch varlen_attn; the latter compiles its complete BHLD-to-THD-to-native-call-to-BHLD adapter and keeps all required layout work inside every timed sample. NATTEN is an external head-to-head prerequisite for any future ecosystem-wide or best-in-class claim, not a package dependency.

Contributing and security

See CONTRIBUTING.md for development and benchmark rules, SECURITY.md for private vulnerability reporting, and docs/releasing.md for the release process. The 0.1.0 assurance record documents the pre-release security and red-team disposition. Participation is governed by the Contributor Covenant.

Licensed under Apache-2.0. See LICENSE and NOTICE.

Download files

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

Source Distribution

sparse_attention_fabric-0.1.0.tar.gz (143.9 kB view details)

Uploaded Source

Built Distribution

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

sparse_attention_fabric-0.1.0-py3-none-any.whl (85.7 kB view details)

Uploaded Python 3

File details

Details for the file sparse_attention_fabric-0.1.0.tar.gz.

File metadata

  • Download URL: sparse_attention_fabric-0.1.0.tar.gz
  • Upload date:
  • Size: 143.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for sparse_attention_fabric-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71625118e98366b268eb6f42f83dfb08fbade0aef0b16fd5342f9657274f9194
MD5 52b7771a9ca9260340796439dcb5f6f7
BLAKE2b-256 2d3008e9796ac4ba095b4571c4f9d465a189a80d82d8ecf186dc7d11b92d3e1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sparse_attention_fabric-0.1.0.tar.gz:

Publisher: release.yml on pocket20/sparse-attention-fabric

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

File details

Details for the file sparse_attention_fabric-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sparse_attention_fabric-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 991eea90fed989f30f8067ebbd637f0efe77d2177988a679093b9f2528565369
MD5 b2533862ec16dcfb26492f4b3a3b3e30
BLAKE2b-256 df1318a2cd9770e7fafe70257402bfe5006c81a3a8e206d23d387ff1df259569

See more details on using hashes here.

Provenance

The following attestation bundles were made for sparse_attention_fabric-0.1.0-py3-none-any.whl:

Publisher: release.yml on pocket20/sparse-attention-fabric

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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