sparse-attention-fabric 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. sparse_attention_fabric-0.1.0/CHANGELOG.md +49 -0
  2. sparse_attention_fabric-0.1.0/CITATION.cff +20 -0
  3. sparse_attention_fabric-0.1.0/CODE_OF_CONDUCT.md +108 -0
  4. sparse_attention_fabric-0.1.0/CONTRIBUTING.md +71 -0
  5. sparse_attention_fabric-0.1.0/LICENSE +201 -0
  6. sparse_attention_fabric-0.1.0/MANIFEST.in +13 -0
  7. sparse_attention_fabric-0.1.0/NOTICE +5 -0
  8. sparse_attention_fabric-0.1.0/PKG-INFO +176 -0
  9. sparse_attention_fabric-0.1.0/README.md +138 -0
  10. sparse_attention_fabric-0.1.0/SECURITY.md +61 -0
  11. sparse_attention_fabric-0.1.0/docs/MODELED_VALIDATION.md +99 -0
  12. sparse_attention_fabric-0.1.0/docs/architecture.md +126 -0
  13. sparse_attention_fabric-0.1.0/docs/benchmarking.md +182 -0
  14. sparse_attention_fabric-0.1.0/docs/landscape.md +269 -0
  15. sparse_attention_fabric-0.1.0/docs/release-assurance.md +81 -0
  16. sparse_attention_fabric-0.1.0/docs/releasing.md +110 -0
  17. sparse_attention_fabric-0.1.0/docs/roadmap.md +54 -0
  18. sparse_attention_fabric-0.1.0/examples/transformer_attention.py +69 -0
  19. sparse_attention_fabric-0.1.0/m0/README.md +208 -0
  20. sparse_attention_fabric-0.1.0/m0/__init__.py +24 -0
  21. sparse_attention_fabric-0.1.0/m0/_analysis.py +285 -0
  22. sparse_attention_fabric-0.1.0/m0/_correctness.py +358 -0
  23. sparse_attention_fabric-0.1.0/m0/_environment.py +251 -0
  24. sparse_attention_fabric-0.1.0/m0/_errors.py +17 -0
  25. sparse_attention_fabric-0.1.0/m0/_execution.py +436 -0
  26. sparse_attention_fabric-0.1.0/m0/_measurement.py +233 -0
  27. sparse_attention_fabric-0.1.0/m0/_protocol.py +291 -0
  28. sparse_attention_fabric-0.1.0/m0/_records.py +275 -0
  29. sparse_attention_fabric-0.1.0/m0/_validation.py +749 -0
  30. sparse_attention_fabric-0.1.0/m0/_version.py +3 -0
  31. sparse_attention_fabric-0.1.0/m0/_worker.py +282 -0
  32. sparse_attention_fabric-0.1.0/m0/core_cases.json +289 -0
  33. sparse_attention_fabric-0.1.0/m0/fabric.py +544 -0
  34. sparse_attention_fabric-0.1.0/m0/feasibility.py +643 -0
  35. sparse_attention_fabric-0.1.0/m0/feasibility.schema.json +375 -0
  36. sparse_attention_fabric-0.1.0/m0/patterns.py +289 -0
  37. sparse_attention_fabric-0.1.0/m0/result.schema.json +684 -0
  38. sparse_attention_fabric-0.1.0/m0/run.py +434 -0
  39. sparse_attention_fabric-0.1.0/m0/validate.py +131 -0
  40. sparse_attention_fabric-0.1.0/pyproject.toml +85 -0
  41. sparse_attention_fabric-0.1.0/requirements/release-linux.in +4 -0
  42. sparse_attention_fabric-0.1.0/requirements/release-linux.lock +168 -0
  43. sparse_attention_fabric-0.1.0/requirements/release.in +13 -0
  44. sparse_attention_fabric-0.1.0/requirements/release.lock +494 -0
  45. sparse_attention_fabric-0.1.0/setup.cfg +4 -0
  46. sparse_attention_fabric-0.1.0/sparse_attention_fabric.egg-info/PKG-INFO +176 -0
  47. sparse_attention_fabric-0.1.0/sparse_attention_fabric.egg-info/SOURCES.txt +55 -0
  48. sparse_attention_fabric-0.1.0/sparse_attention_fabric.egg-info/dependency_links.txt +1 -0
  49. sparse_attention_fabric-0.1.0/sparse_attention_fabric.egg-info/entry_points.txt +4 -0
  50. sparse_attention_fabric-0.1.0/sparse_attention_fabric.egg-info/requires.txt +16 -0
  51. sparse_attention_fabric-0.1.0/sparse_attention_fabric.egg-info/top_level.txt +1 -0
  52. sparse_attention_fabric-0.1.0/tests/test_fabric.py +489 -0
  53. sparse_attention_fabric-0.1.0/tests/test_feasibility.py +332 -0
  54. sparse_attention_fabric-0.1.0/tests/test_patterns.py +196 -0
  55. sparse_attention_fabric-0.1.0/tests/test_release_matrix.py +295 -0
  56. sparse_attention_fabric-0.1.0/tests/test_run.py +692 -0
  57. sparse_attention_fabric-0.1.0/tests/test_torch_adapter.py +224 -0
@@ -0,0 +1,49 @@
1
+ # Changelog
2
+
3
+ All notable changes are recorded here. This project follows
4
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the structure of
5
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Planned
10
+
11
+ - Publish controlled A100 evidence after the complete release validator passes.
12
+
13
+ ## [0.1.0] - 2026-08-29
14
+
15
+ ### Added
16
+
17
+ - Exact immutable causal-window pattern and analytic block-row lowering.
18
+ - Cached, inspectable execution planning across SDPA and FlexAttention.
19
+ - PyTorch autograd-preserving public execution API with fail-closed validation.
20
+ - Locked M0 benchmark matrix, fresh-process harness, raw JSONL schema, and strict
21
+ cross-record release validator.
22
+ - Stock PyTorch 2.13 `varlen_attn` baseline with exact inclusive-window
23
+ translation, a static fullgraph compiled BHLD↔THD adapter, forward/backward
24
+ correctness gates, and explicit modeled conversion accounting.
25
+ - Independent numerical and mask-membership correctness checks.
26
+ - Deterministic, schema-validated A100 feasibility modeling that is explicitly
27
+ barred from measured-performance claims.
28
+ - CPU contract CI, manual controlled-CUDA evidence workflow, packaging metadata,
29
+ and open-source governance files.
30
+
31
+ ### Security and reliability
32
+
33
+ - Bounded all runtime caches and untrusted protocol inputs.
34
+ - Made explicit overwrite atomic and safe against destination symlinks.
35
+ - Pinned privileged Actions and release dependencies to immutable identities,
36
+ added provenance attestations, and separated semantic validation from origin
37
+ authentication.
38
+ - Made CUDA mask-cache publication safe across producer and consumer streams
39
+ without adding synchronization to hot cache hits.
40
+ - Staged release assets before immutable publication, upgraded maintained
41
+ Actions to Node 24, and excluded tests from the runtime wheel.
42
+
43
+ ### Known limitations
44
+
45
+ - No controlled GPU measurement is included in this release.
46
+ - CUDA execution is limited to the M0 support matrix documented in
47
+ `m0/README.md`.
48
+ - ROCm, MPS, CPU execution, arbitrary sparsity, decode/KV cache, GQA/MQA, and
49
+ distributed attention are outside this release.
@@ -0,0 +1,20 @@
1
+ cff-version: 1.2.0
2
+ message: "If this software helps your work, please cite this release and its exact evidence artifact."
3
+ title: "Sparse Attention Fabric"
4
+ type: software
5
+ version: 0.1.0
6
+ date-released: 2026-08-29
7
+ license: Apache-2.0
8
+ repository-code: "https://github.com/pocket20/sparse-attention-fabric"
9
+ url: "https://github.com/pocket20/sparse-attention-fabric/releases/tag/v0.1.0"
10
+ authors:
11
+ - name: "Sparse Attention Fabric contributors"
12
+ abstract: >-
13
+ An evidence-first PyTorch execution planner and reproducible benchmark harness
14
+ for exact causal-window attention.
15
+ keywords:
16
+ - sparse attention
17
+ - PyTorch
18
+ - CUDA
19
+ - benchmarking
20
+ - execution planning
@@ -0,0 +1,108 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our standards
16
+
17
+ Examples of behavior that contributes to a positive environment include:
18
+
19
+ - Demonstrating empathy and kindness toward other people.
20
+ - Respecting differing opinions, viewpoints, and experiences.
21
+ - Giving and gracefully accepting constructive feedback.
22
+ - Accepting responsibility and apologizing to those affected by our mistakes.
23
+ - Focusing on what is best for the overall community.
24
+
25
+ Examples of unacceptable behavior include:
26
+
27
+ - Sexualized language or imagery and unwelcome sexual attention or advances.
28
+ - Trolling, insulting or derogatory comments, and personal or political attacks.
29
+ - Public or private harassment.
30
+ - Publishing others' private information without explicit permission.
31
+ - Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting.
33
+
34
+ ## Enforcement responsibilities
35
+
36
+ Community leaders are responsible for clarifying and enforcing standards of
37
+ acceptable behavior and will take appropriate and fair corrective action in
38
+ response to behavior they deem inappropriate, threatening, offensive, or
39
+ harmful.
40
+
41
+ Community leaders have the right and responsibility to remove, edit, or reject
42
+ comments, commits, code, wiki edits, issues, and other contributions that are not
43
+ aligned with this Code of Conduct, and will communicate reasons for moderation
44
+ decisions when appropriate.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all community spaces and when an individual
49
+ officially represents the community in public spaces.
50
+
51
+ ## Enforcement
52
+
53
+ Report abusive, harassing, or otherwise unacceptable behavior privately using
54
+ the repository's channel described in [SECURITY.md](SECURITY.md). All complaints
55
+ will be reviewed and investigated promptly and fairly. Community leaders must
56
+ respect the privacy and security of the reporter.
57
+
58
+ ## Enforcement guidelines
59
+
60
+ Community leaders will follow these Community Impact Guidelines in determining
61
+ the consequences for any action they deem in violation of this Code of Conduct:
62
+
63
+ ### 1. Correction
64
+
65
+ **Community impact:** Use of inappropriate language or other behavior deemed
66
+ unprofessional or unwelcome in the community.
67
+
68
+ **Consequence:** A private, written warning providing clarity around the nature
69
+ of the violation and an explanation of why the behavior was inappropriate. A
70
+ public apology may be requested.
71
+
72
+ ### 2. Warning
73
+
74
+ **Community impact:** A violation through a single incident or series of actions.
75
+
76
+ **Consequence:** A warning with consequences for continued behavior. No
77
+ interaction with the people involved, including unsolicited interaction with
78
+ those enforcing the Code of Conduct, for a specified period. This includes
79
+ avoiding interactions in community spaces and external channels such as social
80
+ media. Violating these terms may lead to a temporary or permanent ban.
81
+
82
+ ### 3. Temporary ban
83
+
84
+ **Community impact:** A serious violation of community standards, including
85
+ sustained inappropriate behavior.
86
+
87
+ **Consequence:** A temporary ban from any interaction or public communication
88
+ with the community for a specified period. No public or private interaction with
89
+ the people involved, including unsolicited interaction with those enforcing the
90
+ Code of Conduct, is allowed during this period. Violating these terms may lead
91
+ to a permanent ban.
92
+
93
+ ### 4. Permanent ban
94
+
95
+ **Community impact:** A pattern of violating community standards, including
96
+ sustained inappropriate behavior, harassment of an individual, or aggression
97
+ toward or disparagement of classes of individuals.
98
+
99
+ **Consequence:** A permanent ban from any public interaction within the
100
+ community.
101
+
102
+ ## Attribution
103
+
104
+ This Code of Conduct is adapted from the
105
+ [Contributor Covenant, version 2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html).
106
+
107
+ Community Impact Guidelines were inspired by
108
+ [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
@@ -0,0 +1,71 @@
1
+ # Contributing
2
+
3
+ Thanks for helping make sparse-attention execution easier to measure and use.
4
+ Changes should make the implementation smaller, clearer, more correct, or more
5
+ reproducible. A benchmark improvement without matched semantics is a regression.
6
+
7
+ ## Development setup
8
+
9
+ Sparse Attention Fabric supports CPython 3.11 and 3.12. CPU contract work does
10
+ not require PyTorch:
11
+
12
+ ```bash
13
+ python -m venv .venv
14
+ source .venv/bin/activate
15
+ python -m pip install --upgrade pip
16
+ python -m pip install -e '.[dev]'
17
+ python -m unittest discover -s tests -p 'test_*.py' -v
18
+ ```
19
+
20
+ For CUDA work, first install the official PyTorch 2.13 build matched to the host,
21
+ then use `python -m pip install --no-deps -e .` so environment setup does not
22
+ silently replace the selected wheel.
23
+
24
+ ## Change rules
25
+
26
+ - Keep the public pattern and planner API typed, narrow, and fail-closed.
27
+ - Add a focused regression test for every behavior change.
28
+ - Do not add a backend fallback unless its choice and costs are observable.
29
+ - Do not reuse production mask construction in an independent correctness oracle.
30
+ - Treat host synchronization, layout conversion, compilation, autotuning, and
31
+ mask construction as costs that must be assigned to an explicit timing scope.
32
+ - Preserve failure rows and raw samples. Never trim data to improve a result.
33
+ - Keep optional dependencies lazily imported so CPU planning remains usable.
34
+
35
+ The M0 protocol is immutable. Any change to a case, threshold, implementation
36
+ arm, timing rule, correctness rule, or canonical configuration requires a new
37
+ suite ID, schema review, and changelog entry. Never update the locked fingerprint
38
+ in isolation.
39
+
40
+ ## Pull requests
41
+
42
+ Before opening a pull request:
43
+
44
+ ```bash
45
+ python -m unittest discover -s tests -p 'test_*.py' -v
46
+ python -m json.tool m0/core_cases.json >/dev/null
47
+ python -m json.tool m0/result.schema.json >/dev/null
48
+ python -m build
49
+ python -m twine check dist/*
50
+ ```
51
+
52
+ Describe user-visible behavior, compatibility, tests, and benchmark impact.
53
+ Performance pull requests must attach machine-readable evidence or explicitly
54
+ state that the proposed gain is unmeasured. Modeled estimates must be labeled as
55
+ models and must include their assumptions.
56
+
57
+ Small, single-purpose commits are preferred. Contributors certify the
58
+ [Developer Certificate of Origin](https://developercertificate.org/) by adding
59
+ `Signed-off-by` to commits (`git commit -s`).
60
+
61
+ ## Benchmark evidence
62
+
63
+ Do not use pull-request runners for release performance claims. Use the manual,
64
+ exclusive-GPU workflow described in [docs/benchmarking.md](docs/benchmarking.md),
65
+ then attach its JSONL and summary without editing them. A negative or unsupported
66
+ result is useful evidence and must remain visible.
67
+
68
+ ## Reporting vulnerabilities
69
+
70
+ Do not disclose a suspected vulnerability in a public issue. Follow
71
+ [SECURITY.md](SECURITY.md).
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+ include CHANGELOG.md
2
+ include CITATION.cff
3
+ include CODE_OF_CONDUCT.md
4
+ include CONTRIBUTING.md
5
+ include LICENSE
6
+ include NOTICE
7
+ include README.md
8
+ include SECURITY.md
9
+ recursive-include docs *.md
10
+ recursive-include examples *.py
11
+ recursive-include m0 *.json *.md
12
+ recursive-include requirements *.in *.lock
13
+ recursive-include tests *.py
@@ -0,0 +1,5 @@
1
+ Sparse Attention Fabric
2
+ Copyright 2026 Sparse Attention Fabric contributors
3
+
4
+ This product includes software developed by the Sparse Attention Fabric
5
+ contributors.
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: sparse-attention-fabric
3
+ Version: 0.1.0
4
+ Summary: Evidence-first execution planning for exact causal-window attention
5
+ Author: Sparse Attention Fabric contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/pocket20/sparse-attention-fabric
8
+ Project-URL: Documentation, https://github.com/pocket20/sparse-attention-fabric/tree/main/docs
9
+ Project-URL: Repository, https://github.com/pocket20/sparse-attention-fabric.git
10
+ Project-URL: Issues, https://github.com/pocket20/sparse-attention-fabric/issues
11
+ Project-URL: Changelog, https://github.com/pocket20/sparse-attention-fabric/blob/main/CHANGELOG.md
12
+ Keywords: attention,benchmarking,cuda,pytorch,sparse-attention
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Requires-Python: <3.13,>=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ License-File: NOTICE
25
+ Provides-Extra: validation
26
+ Requires-Dist: jsonschema<5,>=4.23; extra == "validation"
27
+ Provides-Extra: cuda
28
+ Requires-Dist: torch<2.14,>=2.13; extra == "cuda"
29
+ Provides-Extra: benchmark
30
+ Requires-Dist: jsonschema<5,>=4.23; extra == "benchmark"
31
+ Requires-Dist: torch<2.14,>=2.13; extra == "benchmark"
32
+ Provides-Extra: dev
33
+ Requires-Dist: build==1.3.0; extra == "dev"
34
+ Requires-Dist: jsonschema==4.26.0; extra == "dev"
35
+ Requires-Dist: ruff==0.16.5; extra == "dev"
36
+ Requires-Dist: twine==6.2.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # Sparse Attention Fabric
40
+
41
+ [![CI](https://github.com/pocket20/sparse-attention-fabric/actions/workflows/ci.yml/badge.svg)](https://github.com/pocket20/sparse-attention-fabric/actions/workflows/ci.yml)
42
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/pocket20/sparse-attention-fabric/blob/main/LICENSE)
43
+
44
+ Sparse Attention Fabric is an evidence-first PyTorch execution planner for exact
45
+ causal-window attention. The initial `0.1.0` release is intentionally narrow: it
46
+ chooses among causal SDPA, masked SDPA, and compiled FlexAttention while exposing
47
+ its decision and preserving PyTorch autograd.
48
+
49
+ This release is an executable hypothesis, not a performance claim. No controlled
50
+ GPU result is bundled yet. Numeric thresholds in the M0 protocol are
51
+ pre-registered targets. `saf-m0-validate --release` checks a supplied matrix's
52
+ structure and semantics but does not authenticate its origin; a result becomes
53
+ publishable only after validation and independent GitHub-attestation verification
54
+ against the exact controlled workflow, default-branch ref, and candidate commit.
55
+
56
+ ## What ships in 0.1.0
57
+
58
+ - An immutable `CausalWindow` pattern with exact token and block semantics.
59
+ - A small, inspectable, cached `ExecutionFabric` policy.
60
+ - Fail-closed CUDA execution through public PyTorch APIs.
61
+ - A locked 19-case, four-implementation benchmark matrix with 380 fresh-process rows.
62
+ - Raw-sample JSONL evidence, a JSON Schema, correctness checks, and release gates.
63
+ - A deterministic, explicitly non-release A100 feasibility model for hardware-free auditing.
64
+ - CPU contract tests plus a manually dispatched A100 evidence workflow.
65
+
66
+ M0 is not a general sparse tensor compiler, a custom CUDA kernel library, or an
67
+ MoE runtime. See [the architecture](https://github.com/pocket20/sparse-attention-fabric/blob/main/docs/architecture.md) for the deliberate
68
+ boundaries and the [competitive landscape](https://github.com/pocket20/sparse-attention-fabric/blob/main/docs/landscape.md) for the primary-source
69
+ decision record. The [evidence-gated roadmap](https://github.com/pocket20/sparse-attention-fabric/blob/main/docs/roadmap.md) states what can follow a
70
+ positive, negative, or invalid controlled run.
71
+
72
+ ## Install
73
+
74
+ Planning and contract tests have no runtime dependency:
75
+
76
+ ```bash
77
+ python -m pip install .
78
+ ```
79
+
80
+ Evidence validation adds JSON Schema support:
81
+
82
+ ```bash
83
+ python -m pip install '.[validation]'
84
+ ```
85
+
86
+ CUDA execution requires the PyTorch 2.13 build appropriate for the machine. In
87
+ controlled environments, install PyTorch from the official channel selected for
88
+ the CUDA driver, then install this project without allowing pip to replace it:
89
+
90
+ ```bash
91
+ python -m pip install --no-deps .
92
+ python -c 'import torch; print(torch.__version__, torch.version.cuda)'
93
+ ```
94
+
95
+ The `cuda` and `benchmark` extras express compatible version constraints, but
96
+ they cannot choose the correct CUDA wheel index for a particular host.
97
+
98
+ ## Use
99
+
100
+ ```python
101
+ from m0 import CausalWindow, ExecutionFabric
102
+
103
+ fabric = ExecutionFabric(max_cache_entries=32)
104
+ pattern = CausalWindow(window=512)
105
+ output = fabric(query, key, value, pattern)
106
+ plan = fabric.plan(
107
+ pattern,
108
+ sequence_length=query.shape[-2],
109
+ dtype=str(query.dtype).removeprefix("torch."),
110
+ )
111
+ print(plan.backend, plan.rationale)
112
+
113
+ # Optional for a tight loop: validates once and retains metadata, not tensors.
114
+ prepared = fabric.prepare(query, key, value, pattern)
115
+ next_output = prepared(next_query, next_key, next_value)
116
+ ```
117
+
118
+ Inputs must be contiguous CUDA `BHLD` tensors with FP16 or BF16 dtype, equal
119
+ query/KV head counts and lengths, and head/value dimensions of 64 or 128.
120
+ Unsupported inputs raise an error instead of silently changing semantics.
121
+ Prepared calls reject a changed shape, stride, device, dtype, pattern, or
122
+ autograd context; call `prepare` again when any execution metadata changes.
123
+ The entry limit applies independently to plans, masks, compiled Flex functions,
124
+ prepared executors, and device capabilities. Slow-path insertions evict the
125
+ oldest entry; hot prepared-cache hits remain lock-free. Inspect the configured
126
+ limit and current occupancy with `fabric.cache_info()`.
127
+
128
+ For a complete projection-to-attention-to-output module, see the
129
+ [Transformer-style integration example](https://github.com/pocket20/sparse-attention-fabric/blob/main/examples/transformer_attention.py).
130
+
131
+ ## Validate locally
132
+
133
+ ```bash
134
+ python -m unittest discover -s tests -p 'test_*.py' -v
135
+ python -m json.tool m0/core_cases.json >/dev/null
136
+ python -m json.tool m0/result.schema.json >/dev/null
137
+ python -m json.tool m0/feasibility.schema.json >/dev/null
138
+ saf-m0 --help
139
+ saf-m0-model --help
140
+ saf-m0-validate --help
141
+ ```
142
+
143
+ Run the full benchmark only on a controlled Linux CUDA host. The canonical
144
+ protocol, operator attestations, commands, interpretation rules, and known
145
+ limitations are in the [M0 evidence guide](https://github.com/pocket20/sparse-attention-fabric/blob/main/m0/README.md) and
146
+ [benchmark operations guide](https://github.com/pocket20/sparse-attention-fabric/blob/main/docs/benchmarking.md).
147
+
148
+ When the target GPU is unavailable, run `saf-m0-model` to audit exact pair
149
+ counts, block rounding, visible storage, and peak-rate sensitivity envelopes. The
150
+ [modeled-validation guide](https://github.com/pocket20/sparse-attention-fabric/blob/main/docs/MODELED_VALIDATION.md) states what the model can
151
+ and cannot establish. Its output is structurally barred from release validation.
152
+
153
+ ## Evidence and claims
154
+
155
+ Every release-quality performance statement must link to the immutable JSONL,
156
+ validated summary, verified GitHub attestations, exact commit, hardware/software
157
+ environment, and timing scope. A detached artifact or checksum is not proof of a
158
+ controlled run. Unsupported, OOM, correctness-failure, and negative-performance
159
+ rows are part of the result and must not be removed. Modeled hardware results
160
+ may guide engineering but may never be reported as measured CUDA performance.
161
+ The direct baselines are SDPA, generic FlexAttention, and native PyTorch
162
+ `varlen_attn`; the latter compiles its complete BHLD-to-THD-to-native-call-to-BHLD
163
+ adapter and keeps all required layout work inside every timed sample. NATTEN is an external head-to-head
164
+ prerequisite for any future ecosystem-wide or best-in-class claim, not a
165
+ package dependency.
166
+
167
+ ## Contributing and security
168
+
169
+ See [CONTRIBUTING.md](https://github.com/pocket20/sparse-attention-fabric/blob/main/CONTRIBUTING.md) for development and benchmark rules,
170
+ [SECURITY.md](https://github.com/pocket20/sparse-attention-fabric/blob/main/SECURITY.md) for private vulnerability reporting, and
171
+ [docs/releasing.md](https://github.com/pocket20/sparse-attention-fabric/blob/main/docs/releasing.md) for the release process. The
172
+ [0.1.0 assurance record](https://github.com/pocket20/sparse-attention-fabric/blob/main/docs/release-assurance.md) documents the pre-release
173
+ security and red-team disposition. Participation is governed by the
174
+ [Contributor Covenant](https://github.com/pocket20/sparse-attention-fabric/blob/main/CODE_OF_CONDUCT.md).
175
+
176
+ Licensed under Apache-2.0. See [LICENSE](https://github.com/pocket20/sparse-attention-fabric/blob/main/LICENSE) and [NOTICE](https://github.com/pocket20/sparse-attention-fabric/blob/main/NOTICE).