fast-attnres 1.0.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 (138) hide show
  1. fast_attnres-1.0.0/CITATION.cff +36 -0
  2. fast_attnres-1.0.0/EVALUATION.md +25 -0
  3. fast_attnres-1.0.0/LICENSE +21 -0
  4. fast_attnres-1.0.0/MANIFEST.in +17 -0
  5. fast_attnres-1.0.0/NOTICE +63 -0
  6. fast_attnres-1.0.0/PKG-INFO +493 -0
  7. fast_attnres-1.0.0/PROVENANCE.md +125 -0
  8. fast_attnres-1.0.0/README.md +447 -0
  9. fast_attnres-1.0.0/benchmarks/__init__.py +22 -0
  10. fast_attnres-1.0.0/benchmarks/audit_compiled_step.py +1537 -0
  11. fast_attnres-1.0.0/benchmarks/audit_current_24l.py +609 -0
  12. fast_attnres-1.0.0/benchmarks/baseline.py +155 -0
  13. fast_attnres-1.0.0/benchmarks/catswe.py +637 -0
  14. fast_attnres-1.0.0/benchmarks/comparator_registry.py +858 -0
  15. fast_attnres-1.0.0/benchmarks/comparator_runner.py +2703 -0
  16. fast_attnres-1.0.0/benchmarks/competitor_protocol.py +1464 -0
  17. fast_attnres-1.0.0/benchmarks/competitors.py +719 -0
  18. fast_attnres-1.0.0/benchmarks/compiled_step_campaign.py +832 -0
  19. fast_attnres-1.0.0/benchmarks/fla_checkout.py +473 -0
  20. fast_attnres-1.0.0/benchmarks/fla_compile.py +660 -0
  21. fast_attnres-1.0.0/benchmarks/gluon_compat.py +75 -0
  22. fast_attnres-1.0.0/benchmarks/hydra.py +1188 -0
  23. fast_attnres-1.0.0/benchmarks/liger.py +892 -0
  24. fast_attnres-1.0.0/benchmarks/modal_competitor_runner.py +798 -0
  25. fast_attnres-1.0.0/benchmarks/modal_fla_block_codegen_probe.py +337 -0
  26. fast_attnres-1.0.0/benchmarks/modal_runner.py +590 -0
  27. fast_attnres-1.0.0/benchmarks/model.py +531 -0
  28. fast_attnres-1.0.0/benchmarks/plot_compiled_step_hero.py +611 -0
  29. fast_attnres-1.0.0/benchmarks/plot_compiled_step_sweep.py +2011 -0
  30. fast_attnres-1.0.0/benchmarks/run.py +4192 -0
  31. fast_attnres-1.0.0/benchmarks/selected_fla_block_codegen_probe.py +1364 -0
  32. fast_attnres-1.0.0/benchmarks/source_profile.py +592 -0
  33. fast_attnres-1.0.0/benchmarks/statistics.py +257 -0
  34. fast_attnres-1.0.0/benchmarks/training_graph.py +258 -0
  35. fast_attnres-1.0.0/benchmarks/vendor_identity.py +450 -0
  36. fast_attnres-1.0.0/configs/compiled_step_campaign.json +144 -0
  37. fast_attnres-1.0.0/configs/compiled_step_campaign_manifest.json +129 -0
  38. fast_attnres-1.0.0/configs/fla_scalar_compact_gate_v1.json +32 -0
  39. fast_attnres-1.0.0/configs/matched_competitor_benchmark.json +749 -0
  40. fast_attnres-1.0.0/configs/matched_competitor_benchmark.schema.json +1333 -0
  41. fast_attnres-1.0.0/configs/matched_competitor_benchmark_d_gt_768.json +784 -0
  42. fast_attnres-1.0.0/configs/production_ladder_block.json +126 -0
  43. fast_attnres-1.0.0/configs/production_ladder_full.json +126 -0
  44. fast_attnres-1.0.0/configs/production_ladder_split_manifest.json +241 -0
  45. fast_attnres-1.0.0/docs/assets/compiled_step_hero.png +0 -0
  46. fast_attnres-1.0.0/docs/assets/compiled_step_hero.svg +299 -0
  47. fast_attnres-1.0.0/docs/assets/compiled_step_screen_b200.png +0 -0
  48. fast_attnres-1.0.0/docs/assets/compiled_step_screen_b200.svg +1132 -0
  49. fast_attnres-1.0.0/docs/assets/compiled_step_screen_h100.png +0 -0
  50. fast_attnres-1.0.0/docs/assets/compiled_step_screen_h100.svg +679 -0
  51. fast_attnres-1.0.0/docs/benchmark_results.md +16 -0
  52. fast_attnres-1.0.0/docs/compiled_step_results.md +162 -0
  53. fast_attnres-1.0.0/docs/current_24l_results.md +102 -0
  54. fast_attnres-1.0.0/docs/equation.md +125 -0
  55. fast_attnres-1.0.0/docs/matched_competitor_protocol.md +249 -0
  56. fast_attnres-1.0.0/docs/production_ladder.md +199 -0
  57. fast_attnres-1.0.0/docs/production_width_matrix.md +142 -0
  58. fast_attnres-1.0.0/docs/release.md +87 -0
  59. fast_attnres-1.0.0/docs/selected_fla_block_codegen_probe.md +72 -0
  60. fast_attnres-1.0.0/docs/validation.md +102 -0
  61. fast_attnres-1.0.0/examples/backward.py +71 -0
  62. fast_attnres-1.0.0/examples/block_schedules.py +62 -0
  63. fast_attnres-1.0.0/examples/lr_attnres.py +44 -0
  64. fast_attnres-1.0.0/examples/packed_and_list.py +59 -0
  65. fast_attnres-1.0.0/examples/standard_attnres.py +46 -0
  66. fast_attnres-1.0.0/examples/torch_compile.py +65 -0
  67. fast_attnres-1.0.0/examples/train.py +92 -0
  68. fast_attnres-1.0.0/pyproject.toml +68 -0
  69. fast_attnres-1.0.0/scripts/__init__.py +5 -0
  70. fast_attnres-1.0.0/scripts/build_release.py +1079 -0
  71. fast_attnres-1.0.0/scripts/compiled_step_sweep.py +2536 -0
  72. fast_attnres-1.0.0/scripts/verify_compiled_step_release.py +134 -0
  73. fast_attnres-1.0.0/setup.cfg +4 -0
  74. fast_attnres-1.0.0/src/attnres/__init__.py +17 -0
  75. fast_attnres-1.0.0/src/attnres/__init__.pyi +28 -0
  76. fast_attnres-1.0.0/src/attnres/_kernels/__init__.py +1 -0
  77. fast_attnres-1.0.0/src/attnres/_kernels/fixed_tail.py +995 -0
  78. fast_attnres-1.0.0/src/attnres/_kernels/fixed_tail_sources.py +442 -0
  79. fast_attnres-1.0.0/src/attnres/_kernels/fla_full_sources.py +1706 -0
  80. fast_attnres-1.0.0/src/attnres/_sources.py +100 -0
  81. fast_attnres-1.0.0/src/attnres/api.py +66 -0
  82. fast_attnres-1.0.0/src/attnres/info.py +109 -0
  83. fast_attnres-1.0.0/src/attnres/modules.py +41 -0
  84. fast_attnres-1.0.0/src/attnres/py.typed +1 -0
  85. fast_attnres-1.0.0/src/attnres/reference.py +15 -0
  86. fast_attnres-1.0.0/src/fast_attnres.egg-info/PKG-INFO +493 -0
  87. fast_attnres-1.0.0/src/fast_attnres.egg-info/SOURCES.txt +136 -0
  88. fast_attnres-1.0.0/src/fast_attnres.egg-info/dependency_links.txt +1 -0
  89. fast_attnres-1.0.0/src/fast_attnres.egg-info/entry_points.txt +2 -0
  90. fast_attnres-1.0.0/src/fast_attnres.egg-info/requires.txt +27 -0
  91. fast_attnres-1.0.0/src/fast_attnres.egg-info/top_level.txt +1 -0
  92. fast_attnres-1.0.0/tests/conftest.py +9 -0
  93. fast_attnres-1.0.0/tests/test_api.py +258 -0
  94. fast_attnres-1.0.0/tests/test_audit_compiled_step.py +461 -0
  95. fast_attnres-1.0.0/tests/test_audit_current_24l.py +104 -0
  96. fast_attnres-1.0.0/tests/test_baseline.py +62 -0
  97. fast_attnres-1.0.0/tests/test_benchmark.py +857 -0
  98. fast_attnres-1.0.0/tests/test_benchmark_compact.py +794 -0
  99. fast_attnres-1.0.0/tests/test_catswe_model_arm.py +105 -0
  100. fast_attnres-1.0.0/tests/test_comparator_runner.py +1230 -0
  101. fast_attnres-1.0.0/tests/test_competitor_registry.py +686 -0
  102. fast_attnres-1.0.0/tests/test_compiled_step_campaign.py +145 -0
  103. fast_attnres-1.0.0/tests/test_compiled_step_sweep.py +1053 -0
  104. fast_attnres-1.0.0/tests/test_cuda.py +393 -0
  105. fast_attnres-1.0.0/tests/test_fla_checkout.py +361 -0
  106. fast_attnres-1.0.0/tests/test_fla_compile.py +201 -0
  107. fast_attnres-1.0.0/tests/test_fla_production_autotune.py +142 -0
  108. fast_attnres-1.0.0/tests/test_fla_scalar_compact_gate.py +167 -0
  109. fast_attnres-1.0.0/tests/test_full_kernel.py +254 -0
  110. fast_attnres-1.0.0/tests/test_info.py +69 -0
  111. fast_attnres-1.0.0/tests/test_installation.py +165 -0
  112. fast_attnres-1.0.0/tests/test_liger_model_arm.py +211 -0
  113. fast_attnres-1.0.0/tests/test_modal_cache.py +112 -0
  114. fast_attnres-1.0.0/tests/test_modal_fla_block_codegen_probe.py +155 -0
  115. fast_attnres-1.0.0/tests/test_model_routes.py +114 -0
  116. fast_attnres-1.0.0/tests/test_offsets.py +59 -0
  117. fast_attnres-1.0.0/tests/test_packaging_metadata.py +64 -0
  118. fast_attnres-1.0.0/tests/test_plot_compiled_step_hero.py +207 -0
  119. fast_attnres-1.0.0/tests/test_plot_compiled_step_sweep.py +190 -0
  120. fast_attnres-1.0.0/tests/test_pre_timing_gate.py +267 -0
  121. fast_attnres-1.0.0/tests/test_production_ladder_configs.py +281 -0
  122. fast_attnres-1.0.0/tests/test_provenance_metadata.py +79 -0
  123. fast_attnres-1.0.0/tests/test_reference.py +28 -0
  124. fast_attnres-1.0.0/tests/test_release.py +508 -0
  125. fast_attnres-1.0.0/tests/test_selected_fla_block_codegen_probe.py +421 -0
  126. fast_attnres-1.0.0/tests/test_training.py +229 -0
  127. fast_attnres-1.0.0/tests/test_training_graph.py +199 -0
  128. fast_attnres-1.0.0/tests/test_vendor_adapters.py +477 -0
  129. fast_attnres-1.0.0/tests/test_verify_compiled_step_release.py +79 -0
  130. fast_attnres-1.0.0/validation/__init__.py +1 -0
  131. fast_attnres-1.0.0/validation/block_checks.py +113 -0
  132. fast_attnres-1.0.0/validation/frozen.json +63 -0
  133. fast_attnres-1.0.0/validation/gpu_checks.py +161 -0
  134. fast_attnres-1.0.0/validation/oracle.py +18 -0
  135. fast_attnres-1.0.0/validation/protocol.json +176 -0
  136. fast_attnres-1.0.0/validation/source_checks.py +168 -0
  137. fast_attnres-1.0.0/validation/training_checks.py +124 -0
  138. fast_attnres-1.0.0/validation/training_graph_checks.py +114 -0
@@ -0,0 +1,36 @@
1
+ cff-version: 1.2.0
2
+ title: Fast Attention Residuals
3
+ message: "If you use Fast-AttnRes in your work, please cite this software."
4
+ type: software
5
+ authors:
6
+ - family-names: Su
7
+ given-names: Jonathan
8
+ repository-code: "https://github.com/jon123boss/fast-attnres"
9
+ url: "https://github.com/jon123boss/fast-attnres"
10
+ license: MIT
11
+ version: 1.0.0
12
+ date-released: "2026-08-31"
13
+ keywords:
14
+ - Attention Residuals
15
+ - LR-AttnRes
16
+ - PyTorch
17
+ - Triton
18
+ references:
19
+ - type: article
20
+ title: Low-Rank Attention Residuals
21
+ authors:
22
+ - family-names: Su
23
+ given-names: Jonathan
24
+ identifiers:
25
+ - type: url
26
+ value: "https://arxiv.org/abs/2607.09694"
27
+ - type: article
28
+ title: Attention Residuals
29
+ authors:
30
+ - name: Kimi Team
31
+ year: 2026
32
+ status: preprint
33
+ url: "https://arxiv.org/abs/2603.15031"
34
+ identifiers:
35
+ - type: url
36
+ value: "https://arxiv.org/abs/2603.15031"
@@ -0,0 +1,25 @@
1
+ # Frozen evaluation contract
2
+
3
+ Candidate authors must not modify this document, validation/oracle.py, validation/protocol.json, validation/frozen.json, reference.py, or root-owned tests. Root verifies their hashes.
4
+
5
+ ## Equations
6
+
7
+ values [S,...,D] or a sequence of S tensors [...,D], query [R]. Keys are the implicit tail values[...,D-R:]. R=D is standard AttnRes. Parameter-free RMS key norm, query dot, scale, source softmax, full-width value mixture. eps=2^-23; scale=1. FP32 compute, BF16/FP32 storage and queries; FP64 reference for gradcheck. S=1..129,D=1..8192,R=1..D. Support packed inputs and strided source views; include source assembly and any required copies in training timing. Separate projected-key and carrier APIs are outside the active scope.
8
+
9
+ Block passes completed values and the sequential current partial as ordinary sources to the same `attnres` primitive used by Full. Block values are sums, not averages; their keys are the implicit tail. There is no separate Block attention kernel or prepared-state API. No private GraphTask APIs, mutable tickets, alpha/beta/count priors, dynamic queries, output norm, or split-block extensions.
10
+
11
+ ## Correctness
12
+
13
+ Independent FP32 equation oracle. Strict output and all value/query gradient gates: BF16 rtol=atol=.05; FP32 rtol=.001,atol=.0001; require finite outputs/gradients. No normwise rescue. Test FP64 gradcheck, aliases, repeated reads and backward, checkpointing, noncontiguous upstreams, nonzero queries, changed-input CUDA Graph replay and compiled model all-parameter gradients. Compare identical architectures/weights/data for parity.
14
+
15
+ ## Timing
16
+
17
+ Primary metric is complete compiled training: projection, source assembly, loss, backward, accumulation, zero_grad, optimizer and any scheduler. Exclude compilation/warmup/profiling; record them separately. Same-device balanced paired runs; fixed model/batch/sequence/optimizer/checkpoint settings across ranks. Preserve every raw sample and source/software/hardware hash. The active native baseline is FLA Triton checkpoint 1 from the exact clean checkout pinned in the production config. Same-R LR comparisons are separate from architectural LR-versus-standard comparisons.
18
+
19
+ Primary: layers24,D1024,heads16,MLP2816,B2,T2048,vocab32768,Block count8,AdamW,BF16 autocast,static queries. R=1,2,4,8,16,32,64,128,256,512,1024. Accumulation1 primary; accumulation2/checkpointing separate integration checks. Three seeds for final confirmation; incomplete budget-limited subsets are not promotion.
20
+
21
+ Gain: simultaneous paired95% CI for smaller/larger latency entirely below1. Plateau: CI contains1 and lies wholly in[.99,1.01]. Entirely above1 is slowdown; other outcomes inconclusive. All adjacent ranks must pass gain/plateau and show gains over larger ranks. No dropped failures or hold-out tuning.
22
+
23
+ ## Budget
24
+
25
+ Root alone submits Modal jobs; exact H100! and B200. User-authorized total US$400. The root budget ledger accounts for prior jobs; this rebuild does not reset spending. Workspace limits remain hard stops. Bounded resumable jobs; no paid retries of unchanged compiler/correctness failures.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jonnester
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ include README.md LICENSE NOTICE PROVENANCE.md EVALUATION.md CITATION.cff pyproject.toml MANIFEST.in
2
+ recursive-include src/attnres *.py
3
+ recursive-include src/attnres *.pyi
4
+ include src/attnres/py.typed
5
+ recursive-include examples *.py
6
+ recursive-include scripts *.py
7
+ recursive-include benchmarks *.py
8
+ recursive-include validation *.py *.json
9
+ recursive-include configs *.json
10
+ recursive-include docs *.md *.svg *.png
11
+ recursive-include tests *.py
12
+ prune outputs
13
+ prune snapshots
14
+ prune tmp
15
+ prune work
16
+
17
+ prune results
@@ -0,0 +1,63 @@
1
+ Third-party notice
2
+ ==================
3
+
4
+ Portions of Fast-AttnRes are adapted from the LR-AttnRes project by
5
+ Jonnester. Those portions are available under the MIT License. The copyright
6
+ notice and license text are included in LICENSE.
7
+
8
+ FLA-derived source-list kernel
9
+ ------------------------------
10
+
11
+ The source-list Full kernel in
12
+ `src/attnres/_kernels/fla_full_sources.py` is adapted from
13
+ `fla/ops/attnres/fused.py` in flash-linear-attention at pinned commit
14
+ `5e02dd3a7651f5f2797eb8b12bbec401826031e1`:
15
+
16
+ https://github.com/fla-org/flash-linear-attention/blob/5e02dd3a7651f5f2797eb8b12bbec401826031e1/fla/ops/attnres/fused.py
17
+
18
+ The adapted source retains this copyright and MIT license notice from the
19
+ pinned source:
20
+
21
+ MIT License
22
+
23
+ Copyright (c) 2023-2026 Songlin Yang, Yu Zhang, Zhiyuan Li
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining a copy
26
+ of this software and associated documentation files (the "Software"), to deal
27
+ in the Software without restriction, including without limitation the rights
28
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
+ copies of the Software, and to permit persons to whom the Software is
30
+ furnished to do so, subject to the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be included in all
33
+ copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41
+ SOFTWARE.
42
+
43
+ Optional external benchmark adapters
44
+ ------------------------------------
45
+
46
+ The `benchmarks/` directory contains interoperability adapters for matched
47
+ comparison against separately installed, pinned external packages. Flash-
48
+ AttnRes does not redistribute those packages or copy their kernel sources into
49
+ the wheel or source distribution. Their identities and licenses are:
50
+
51
+ - Liger-Kernel at `000be60929938fd1358e03524c6ab398b6d421bd`,
52
+ BSD-2-Clause, with its upstream `NOTICE` retained by that distribution:
53
+ https://github.com/linkedin/Liger-Kernel
54
+ - flash-attention-residuals at
55
+ `ff92865e4e1b18809da7a8f0c0c5252039cded7c`, Apache-2.0:
56
+ https://github.com/catswe/flash-attention-residuals
57
+ - attnres-kernel-lab at
58
+ `ea1f63eda8e31b0f10456b3b49cacd8fb66091dc`, MIT:
59
+ https://github.com/manishklach/attnres-kernel-lab
60
+
61
+ Users who install, benchmark, or redistribute an external comparator must
62
+ follow that project's own license and notice requirements. Adapter metadata is
63
+ not a substitute for the external package's license files.
@@ -0,0 +1,493 @@
1
+ Metadata-Version: 2.4
2
+ Name: fast-attnres
3
+ Version: 1.0.0
4
+ Summary: Fast PyTorch training operators for standard and sliced low-rank Attention Residuals
5
+ Author: Jonathan Su
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/jon123boss/fast-attnres
8
+ Project-URL: Repository, https://github.com/jon123boss/fast-attnres
9
+ Project-URL: Issues, https://github.com/jon123boss/fast-attnres/issues
10
+ Project-URL: Documentation, https://github.com/jon123boss/fast-attnres#readme
11
+ Project-URL: Citation, https://github.com/jon123boss/fast-attnres/blob/v1.0.0/CITATION.cff
12
+ Project-URL: Paper, https://arxiv.org/abs/2603.15031
13
+ Project-URL: LR-AttnRes Paper, https://arxiv.org/abs/2607.09694
14
+ Keywords: pytorch,attention,residuals,triton,cuda,bfloat16
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Typing :: Typed
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ License-File: NOTICE
27
+ Requires-Dist: torch>=2.9
28
+ Provides-Extra: cuda
29
+ Requires-Dist: torch==2.13.0; (platform_system == "Linux" and platform_machine == "x86_64") and extra == "cuda"
30
+ Requires-Dist: triton==3.7.1; (platform_system == "Linux" and platform_machine == "x86_64") and extra == "cuda"
31
+ Provides-Extra: test
32
+ Requires-Dist: pytest>=7; extra == "test"
33
+ Requires-Dist: numpy<3,>=1.24; extra == "test"
34
+ Requires-Dist: tomli>=2; python_version < "3.11" and extra == "test"
35
+ Provides-Extra: dev
36
+ Requires-Dist: build>=1; extra == "dev"
37
+ Requires-Dist: ruff>=0.8; extra == "dev"
38
+ Provides-Extra: benchmark
39
+ Requires-Dist: numpy<3,>=1.24; extra == "benchmark"
40
+ Requires-Dist: einops>=0.8; extra == "benchmark"
41
+ Requires-Dist: modal==1.5.4; extra == "benchmark"
42
+ Provides-Extra: plot
43
+ Requires-Dist: matplotlib<4,>=3.8; extra == "plot"
44
+ Requires-Dist: numpy<3,>=1.24; extra == "plot"
45
+ Dynamic: license-file
46
+
47
+ # Fast Attention Residuals
48
+
49
+ [![CI](https://github.com/jon123boss/fast-attnres/actions/workflows/ci.yml/badge.svg)](https://github.com/jon123boss/fast-attnres/actions/workflows/ci.yml)
50
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-3776AB.svg)](https://www.python.org/)
51
+ [![Tested PyTorch 2.13](https://img.shields.io/badge/tested-PyTorch_2.13-EE4C2C.svg)](https://pytorch.org/)
52
+ [![Tested Triton 3.7.1](https://img.shields.io/badge/tested-Triton_3.7.1-654FF0.svg)](https://github.com/triton-lang/triton/releases/tag/v3.7.1)
53
+ [![License: MIT](https://img.shields.io/badge/license-MIT-2E7D32.svg)](https://github.com/jon123boss/fast-attnres/blob/main/LICENSE)
54
+
55
+ [![Current large-model Full AttnRes complete-training-step comparison](https://raw.githubusercontent.com/jon123boss/fast-attnres/main/docs/assets/compiled_step_hero.png)](https://github.com/jon123boss/fast-attnres/blob/main/docs/assets/compiled_step_hero.png)
56
+
57
+ **Fast Attention Residuals** (`Fast-AttnRes`) makes [Attention Residuals](https://arxiv.org/abs/2603.15031) a small, ordinary PyTorch operation: pass an ordered set of full-width residual sources and one learned query, get one full-width residual back. The same `attnres(values, query)` call handles standard AttnRes in Full and per-read Block schedules with either packed tensors or ordered source lists.
58
+
59
+ Start with the [standard quickstart](#quickstart-standard-attnres), then choose a
60
+ [Full or Block schedule](#full-and-block-schedules), and try [sliced
61
+ LR-AttnRes](#sliced-lr-attnres) when you want a smaller routing query.
62
+
63
+ ## Why use Fast-AttnRes
64
+
65
+ - **One PyTorch call:** `attnres(values, query)` returns a full-width residual
66
+ and participates in ordinary first-order autograd.
67
+ - **One schedule primitive:** Full and per-read Block call the same public
68
+ operator; the caller controls source order, block sums, and learned queries.
69
+ - **BF16-ready training path:** the optimized target is BF16 storage/autocast in
70
+ compiled CUDA training graphs, with FP32 equation math.
71
+
72
+ ## Large-model Full AttnRes: the advantage expands with scale
73
+
74
+ The current release was verified through Modal on a 24-layer model, `batch 2 x
75
+ sequence 1024`, and a Full ordered source-list schedule with 48 AttnRes reads
76
+ growing from `S=2` to `S=49`. Across three separately analyzed seeds,
77
+ Fast-AttnRes measured **5.20% lower complete-step latency on H100 SXM** and
78
+ **15.52% lower on B200** than pinned native FLA Triton checkpoint 1. Each seed
79
+ used 10 warmups and 120 paired CUDA Graph rounds.
80
+
81
+ Each captured step contains optimizer zeroing, model forward, cross-entropy, backward,
82
+ gradient accumulation, and fused capturable AdamW. Input copies, hashing,
83
+ compilation, qualification, warmup, graph capture, and report serialization are
84
+ outside the timed CUDA events.
85
+
86
+ The measured advantage is materially wider on this larger Full workload than
87
+ on the smaller eight-layer coverage screen below. That is the observed scaling
88
+ result for these two named configurations; their samples are never pooled
89
+ because model depth, token count, source schedule, and campaign size differ.
90
+
91
+ | Evidence | Configuration | H100 vs FLA | B200 vs FLA |
92
+ | --- | --- | ---: | ---: |
93
+ | Small adoption screen | 8 layers, `B2 x T512`, Full `S=2..17`, 1 seed x 40 rounds | **1.12% lower** | **1.74% lower** |
94
+ | Current large-model Full | 24 layers, `B2 x T1024`, Full `S=2..49`, 3 seeds x 120 rounds | **5.20% lower** | **15.52% lower** |
95
+
96
+ See the [per-seed ratios, confidence intervals, and complete configuration](https://github.com/jon123boss/fast-attnres/blob/main/docs/current_24l_results.md)
97
+ and the [exact current raw reports](https://github.com/jon123boss/fast-attnres/blob/main/results/current_24l/README.md). The
98
+ [earlier campaign](https://github.com/jon123boss/fast-attnres/blob/main/docs/compiled_step_results.md) remains archived against its
99
+ own historical source identity and is not used by this headline.
100
+
101
+ ## Compiled BF16 complete-training-step screen
102
+
103
+ [![H100 BF16 compiled complete-training-step adoption screen](https://raw.githubusercontent.com/jon123boss/fast-attnres/main/docs/assets/compiled_step_screen_h100.png)](https://github.com/jon123boss/fast-attnres/blob/main/docs/assets/compiled_step_screen_h100.png)
104
+
105
+ [![B200 BF16 compiled complete-training-step adoption screen](https://raw.githubusercontent.com/jon123boss/fast-attnres/main/docs/assets/compiled_step_screen_b200.png)](https://github.com/jon123boss/fast-attnres/blob/main/docs/assets/compiled_step_screen_b200.png)
106
+
107
+ This screen times the work people actually train with: a captured, compiled
108
+ BF16 step containing optimizer zeroing, model forward, cross-entropy, backward,
109
+ gradient accumulation, and fused AdamW. Input copies, compilation,
110
+ qualification, warmup, graph capture, hashing, and report serialization are
111
+ outside the CUDA-event interval.
112
+
113
+ Each numeric comparator arm below is a completed, independently audited row
114
+ from one predeclared seed, with 5 warmups, 40 paired rounds, and a 20,000-resample simultaneous
115
+ paired bootstrap. The ratio is `Fast-AttnRes / comparator`; lower is faster.
116
+ The 95% intervals are simultaneous within each cell's comparator family. GPUs,
117
+ shapes, and seeds are not pooled. This is an adoption screen, not a universal
118
+ fastest claim.
119
+
120
+ ### Standard AttnRes (`R=D`, same equation)
121
+
122
+ Values are mean complete-step latency in milliseconds; the percentage in each
123
+ comparator column is the Fast-AttnRes advantage.
124
+
125
+ | GPU | Schedule | `D` | Read sources | Fast-AttnRes | FLA ckpt-1 | Liger 0.8.2 | Catswe phase 1 |
126
+ | --- | --- | ---: | --- | ---: | ---: | ---: | ---: |
127
+ | H100 SXM | Full | 1024 | `S=2..17` | **5.686 ms** | 5.750 ms (**+1.12%**) | 6.511 ms (**+12.67%**) | 6.452 ms (**+11.88%**) |
128
+ | H100 SXM | Block, event block size 2 | 1536 | `S=2..9` | **9.455 ms** | 9.483 ms (**+0.30%**) | 10.236 ms (**+7.63%**) | NA: `D` is not a power of two |
129
+ | B200 | Full | 1024 | `S=2..17` | **3.683 ms** | 3.749 ms (**+1.74%**) | 4.366 ms (**+15.64%**) | 4.229 ms (**+12.91%**) |
130
+ | B200 | Block, event block size 8 | 1536 | `S=2..3` | 5.304 ms | **5.235 ms (-1.32%)** | 5.677 ms (**+6.57%**) | NA: `D` is not a power of two |
131
+ | B200 | Block, event block size 2 | 1536 | `S=2..9` | **5.430 ms** | 5.456 ms (**+0.48%**) | 6.101 ms (**+11.00%**) | NA: `D` is not a power of two |
132
+ | B200 | Block, event block size 2 | 2048 | `S=2..9` | **7.844 ms** | 7.844 ms (parity) | FAIL: strict numerical gate | 8.298 ms (**+5.48%**) |
133
+
134
+ ### Sliced LR-AttnRes (`R=D/4`, architectural comparison)
135
+
136
+ | GPU | Schedule | `D / R` | Read sources | LR Fast-AttnRes | standard FLA `R=D` |
137
+ | --- | --- | ---: | --- | ---: | ---: |
138
+ | H100 SXM | Block, event block size 2 | `1536 / 384` | `S=2..9` | **9.655 ms** | 9.681 ms (**+0.26%**) |
139
+ | B200 | Block, event block size 2 | `1536 / 384` | `S=2..9` | **5.417 ms** | 5.452 ms (**+0.66%**) |
140
+
141
+ All displayed models use 8 layers, BF16 autocast, and `N=1024` flattened token
142
+ rows per source (`batch 2 x sequence 512`) on PyTorch 2.13.0+cu130 and Triton
143
+ 3.7.1. `S` is the number of residual sources visible to each AttnRes read. Full
144
+ exposes the growing `2..17` history; Block source count is controlled by the
145
+ event block size, so event block size 2 produces two reads at each count
146
+ `2..9`.
147
+
148
+ Only arms that pass native discovery, independent output/value-gradient/query-
149
+ gradient qualification, fullgraph compilation, changed-input CUDA Graph checks,
150
+ and all paired samples receive a ratio. Unsupported, failed, and missing arms
151
+ stay visible without a number. See the [exact long-form table](https://github.com/jon123boss/fast-attnres/blob/main/results/adoption/compiled_step_screen/results.md),
152
+ [machine-readable CSV](https://github.com/jon123boss/fast-attnres/blob/main/results/adoption/compiled_step_screen/results.csv), and
153
+ [evidence manifest](https://github.com/jon123boss/fast-attnres/blob/main/results/adoption/compiled_step_screen/manifest.json) for the
154
+ unrounded paired ratios and simultaneous 95% intervals.
155
+
156
+ ## Product target and dtype roles
157
+
158
+ I treat BF16 training as the optimized product target. CUDA implementation
159
+ and qualification work prioritize BF16 storage/autocast in complete training
160
+ graphs, under the named hardware, runtime, and shape gates. The existing
161
+ performance evidence is a BF16 training measurement, and the bounded adoption
162
+ matrix is the current qualification surface for that target.
163
+
164
+ FP32 remains supported for the explicit equation/reference path, correctness
165
+ oracles, and debugging. FP32 support is not an FP32 performance target: I do
166
+ not infer FP32 timing, ranking, or speedup from API support or from passing an
167
+ FP32 oracle check.
168
+
169
+ ## Install
170
+
171
+ The distribution is named `fast-attnres` and the Python import is the concise
172
+ `attnres`. For the CPU/reference path, install the stable release from PyPI:
173
+
174
+ ```bash
175
+ python -m pip install "fast-attnres==1.0.0"
176
+ ```
177
+
178
+ For the qualified Linux x86-64 CUDA profile, install PyTorch's CUDA 13.0 wheel
179
+ first, then the package's exact CUDA dependency set:
180
+
181
+ ```bash
182
+ python -m pip install --index-url https://download.pytorch.org/whl/cu130 \
183
+ torch==2.13.0
184
+ python -m pip install "fast-attnres[cuda]==1.0.0"
185
+ ```
186
+
187
+ The CPU/reference path only needs PyTorch and does not import Triton. Contributors
188
+ can instead install a checkout with development and test dependencies:
189
+
190
+ ```bash
191
+ git clone https://github.com/jon123boss/fast-attnres.git
192
+ cd fast-attnres
193
+ python -m pip install -e ".[cuda,dev,test]"
194
+ ```
195
+
196
+ This installs the repository-qualified CUDA profile: PyTorch 2.13.0+cu130 with the Triton 3.7.1 dependency used by that release. The compiled-step screen above was measured on this exact pair.
197
+
198
+ The wheel contains ordinary Python and Triton source. There is no compiled
199
+ CUDA extension in the distribution: Triton JIT-compiles the selected kernel
200
+ for the local GPU at runtime. Confirm an installation without importing
201
+ Triton or requiring a GPU:
202
+
203
+ ```bash
204
+ fast-attnres-info
205
+ # or: python -m attnres.info
206
+ ```
207
+
208
+ **Why Triton 3.7.1 rather than the standalone 3.8.0 release?** At the v1.0.0
209
+ release cutoff (2026-08-31), PyTorch 2.13.0 was the newest stable PyTorch
210
+ release and its Linux wheel declared
211
+ `triton==3.7.1`. Triton 3.8.0 is newer in isolation, but installing it beside
212
+ stable PyTorch 2.13.0 creates a dependency conflict. Fast-AttnRes therefore
213
+ uses that cutoff's newest mutually compatible stable PyTorch/Triton pair instead of
214
+ advertising an unqualified combination.
215
+
216
+ ## Quickstart: standard AttnRes
217
+
218
+ Standard AttnRes uses a full-width query (`R == D`). The source axis is reduced
219
+ with a softmax, and the output retains the full value width:
220
+
221
+ ```python
222
+ import torch
223
+
224
+ from attnres import attnres
225
+
226
+ device = "cuda" if torch.cuda.is_available() else "cpu"
227
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
228
+ D = 1024
229
+
230
+ sources = tuple(
231
+ torch.randn(2, D, device=device, dtype=dtype, requires_grad=True)
232
+ for _ in range(8)
233
+ )
234
+ query = torch.nn.Parameter(torch.randn(D, device=device, dtype=torch.float32))
235
+
236
+ output = attnres(sources, query) # [2, D]
237
+ loss = output.float().square().mean()
238
+ loss.backward()
239
+ ```
240
+
241
+ Verify the installed package directly, without relying on repository-only examples:
242
+
243
+ ```bash
244
+ fast-attnres-info
245
+ python -c "import torch; from attnres import attnres; print(attnres(torch.randn(3,2,8), torch.randn(4)).shape)"
246
+ ```
247
+
248
+ ## API
249
+
250
+ `values` can also be one packed tensor with shape `[S, ..., D]`. The public
251
+ signature is:
252
+
253
+ ```python
254
+ attnres(values, query, *, eps=2**-23, scale=1.0)
255
+ ```
256
+
257
+ For source `s`, the operator takes the final `R` value coordinates as its
258
+ implicit key and computes, in FP32,
259
+
260
+ ```text
261
+ t_s = v_s[..., D-R:D]
262
+ k_s = t_s / sqrt(mean(t_s ** 2) + eps)
263
+ p_s = softmax(scale * dot(k_s, query), over sources)
264
+ output = sum_s p_s * v_s
265
+ ```
266
+
267
+ There is no output normalization or source-count prior. BF16 and FP32 values
268
+ and queries are supported; the result is returned in the values' storage dtype.
269
+ BF16 is the optimized training storage target. FP32 storage remains available
270
+ for equation checks and debugging, not as a separate performance target.
271
+
272
+ ## Full and Block schedules
273
+
274
+ Full AttnRes gives each read all preceding residual sources. In the sequential
275
+ Block schedule, the caller sums each completed block and passes that block
276
+ output, plus the current partial block output when one exists, as ordinary
277
+ sources to the same public operator:
278
+
279
+ ```python
280
+ completed = (embedding, first_block, second_block)
281
+ partial = current_partial
282
+ read_sources = completed if partial is None else completed + (partial,)
283
+ block_output = attnres(read_sources, query)
284
+ ```
285
+
286
+ Full and per-read Block therefore share one `attnres` primitive. The caller
287
+ owns block boundaries, partial sums, and learned queries. Block values are
288
+ sums, not averages. There is no separate Block kernel, prepared-state API, or
289
+ cached Block API in the public release surface.
290
+
291
+ ### Multi-read BF16 diagnostics
292
+
293
+ A multi-read Full or Block model can compose an intermediate source before a
294
+ later read. When that intermediate is stored in BF16, the runtime's sequence
295
+ of partial sums can round at different points or associate additions in a
296
+ different order from a flattened equation reference. These paths are
297
+ mathematically equivalent over real numbers, but BF16 storage can expose a
298
+ small strict elementwise difference.
299
+
300
+ I treat such a difference as a composition-order diagnostic, not a relaxed
301
+ correctness criterion. A strict elementwise mismatch remains a test failure:
302
+ the protocol does not change tolerances, delete the case, or convert the row
303
+ into a passing qualification result.
304
+
305
+ [`examples/block_schedules.py`](https://github.com/jon123boss/fast-attnres/blob/main/examples/block_schedules.py) runs the Full
306
+ reduction and the same per-read schedule on small CPU or CUDA inputs:
307
+
308
+ ```bash
309
+ python examples/block_schedules.py
310
+ ```
311
+
312
+ ## Sliced LR-AttnRes
313
+
314
+ Once standard AttnRes is working, choose a shorter query (`R < D`) to use
315
+ sliced LR-AttnRes, the extension developed in the
316
+ [Low-Rank Attention Residuals paper](https://arxiv.org/abs/2607.09694). The
317
+ big idea is to keep the residual stream at full width while learning the
318
+ source-selection query in a smaller routing space. Its implicit key is the
319
+ final `R` coordinates of each full-width value, so routing shrinks while the
320
+ output remains full width:
321
+
322
+ ```python
323
+ rank = 64
324
+ query = torch.nn.Parameter(torch.randn(rank, device=device, dtype=torch.float32))
325
+ output = attnres(sources, query) # still [2, D]
326
+ ```
327
+
328
+ The [`examples/lr_attnres.py`](https://github.com/jon123boss/fast-attnres/blob/main/examples/lr_attnres.py) script uses the
329
+ `LearnedQuery` helper and checks the full-width output:
330
+
331
+ ```bash
332
+ python examples/lr_attnres.py
333
+ ```
334
+
335
+ `R == D` is standard AttnRes; `R < D` is sliced LR-AttnRes. The small
336
+ `attnres.modules.LearnedQuery(rank)` module is available when a trainable
337
+ static query parameter is convenient. Explicit projected-key and carrier APIs
338
+ are outside this release.
339
+
340
+ ## Support and API boundaries
341
+
342
+ | Area | Supported contract |
343
+ | --- | --- |
344
+ | Sources | Packed `[S, ..., D]` tensor or nonempty ordered `list`/`tuple` of `[..., D]` tensors |
345
+ | Dimensions | `1 <= S <= 129`, `1 <= D <= 8192`, `1 <= R <= D` |
346
+ | Storage | BF16 or FP32 values and queries; FP32 equation math; output in the values' dtype |
347
+ | Devices | CPU equation reference; CUDA Triton kernels |
348
+ | CUDA source lists | Bounded BF16 lists (`D <= 2048`) use the FLA-derived source-list route; FP32 and wider BF16 lists use the fixed-tail fallback |
349
+ | Autograd | Ordinary first-order gradients for values and queries, including repeated sources and shared views |
350
+
351
+ These dimensions and dtypes describe the equation and API domain. CUDA
352
+ qualification is narrower: only the bounded adoption matrix has passed under
353
+ PyTorch 2.13/Triton 3.7.1, so the entire `S <= 129`, `D <= 8192` API envelope
354
+ must not be treated as CUDA-qualified.
355
+
356
+ The [`examples/packed_and_list.py`](https://github.com/jon123boss/fast-attnres/blob/main/examples/packed_and_list.py) script compares
357
+ packed tensors with ordered lists and tuples for both standard and sliced
358
+ calls:
359
+
360
+ ```bash
361
+ python examples/packed_and_list.py
362
+ ```
363
+
364
+ CUDA source-list calls keep individual producer tensors when their layout is
365
+ usable. A non-affine producer or incoming gradient may receive its own
366
+ contiguous copy, so source lists do not promise universal zero-copy behavior.
367
+ Second-order behavior is not part of the public contract.
368
+
369
+ The package exports `attnres` for the runtime route, `reference_attnres` for
370
+ the explicit equation reference, `LearnedQuery`, and `__version__`.
371
+
372
+ For a compact equation and detailed layout/gradient rules, see the
373
+ [equation and API contract](https://github.com/jon123boss/fast-attnres/blob/main/docs/equation.md). For support, please open a
374
+ [GitHub issue](https://github.com/jon123boss/fast-attnres/issues) with your
375
+ OS, GPU, PyTorch/Triton/CUDA versions, source container, shapes, dtypes, and a
376
+ minimal reproducer.
377
+
378
+ ## PyTorch integration
379
+
380
+ The public operator is an ordinary PyTorch call, so it can be wrapped by
381
+ `torch.compile` or checkpointing:
382
+
383
+ ```python
384
+ import torch
385
+
386
+ from attnres import attnres
387
+ from torch.utils.checkpoint import checkpoint
388
+
389
+ sources = tuple(
390
+ torch.randn(2, 1024, device="cuda", dtype=torch.bfloat16, requires_grad=True)
391
+ for _ in range(4)
392
+ )
393
+ query = torch.nn.Parameter(torch.randn(1024, device="cuda", dtype=torch.float32))
394
+
395
+ def residual(values, query):
396
+ return attnres(values, query)
397
+
398
+ compiled_residual = torch.compile(residual)
399
+ compiled_output = compiled_residual(sources, query)
400
+ checkpointed = checkpoint(residual, sources, query, use_reentrant=False)
401
+ ```
402
+
403
+ The [`examples/backward.py`](https://github.com/jon123boss/fast-attnres/blob/main/examples/backward.py) script checks first-order
404
+ value and query gradients. The [`examples/torch_compile.py`](https://github.com/jon123boss/fast-attnres/blob/main/examples/torch_compile.py)
405
+ script compares eager and compiled outputs; it uses the lightweight `eager`
406
+ compile backend by default and accepts `--backend inductor` for an optimized
407
+ backend smoke test:
408
+
409
+ ```bash
410
+ python examples/backward.py
411
+ python examples/torch_compile.py
412
+ python examples/torch_compile.py --backend inductor
413
+ ```
414
+
415
+ ## Competitor eligibility and interpretation
416
+
417
+ The measured rows above are complete training-step comparisons at the stated
418
+ shape. The same public AttnRes schedule, model state, inputs, optimizer, warmup,
419
+ and paired order are used for every eligible arm. Adapter staging is not hidden
420
+ outside the captured step.
421
+
422
+ | Route | What the comparison means | Stipulations |
423
+ | --- | --- | --- |
424
+ | [FLA Triton checkpoint 1](https://github.com/fla-org/flash-linear-attention) | Same-equation standard AttnRes | Native source-list route; `R=D`; checkpoint 1 only. |
425
+ | [Liger-Kernel 0.8.2](https://github.com/linkedin/Liger-Kernel) | Same-equation standard AttnRes | `R=D`, every read `S<=32`; required `torch.stack(...).contiguous()` is inside the timed captured step. |
426
+ | [Catswe phase 1](https://github.com/catswe/flash-attention-residuals) | Same-equation standard AttnRes where eligible | BF16 values, `R=D`, power-of-two `D`, and `nextpow2(S)*D <= 2^20`; stack/contiguous is timed. Phase 1 only: no phase-2, prepare/merge, or cached Block path. |
427
+ | Hydra 2P | Not applicable to this width screen | Native timing envelope is `D<=256`, so Hydra is `not_applicable` for every displayed `D>768` row. Its external panel is not presented as the public per-read Block equation. |
428
+ | Sliced LR-AttnRes (`R<D`) vs FLA | Architectural comparison, when shown | LR-AttnRes changes the routing equation while retaining full-width values/output; FLA remains standard `R=D`. It is never labelled a same-equation kernel speedup. |
429
+
430
+ The public API envelope is broader than this measured screen. FP32 remains an
431
+ equation/reference and debugging path, but no FP32 performance claim is made.
432
+ See the [matched competitor protocol](https://github.com/jon123boss/fast-attnres/blob/main/docs/matched_competitor_protocol.md) for
433
+ capability gates, adapter costs, provenance, licenses, and explicit
434
+ `not_applicable` handling.
435
+
436
+ ## Verify locally
437
+
438
+ Run the CPU and static checks from the repository root:
439
+
440
+ ```bash
441
+ PYTHONDONTWRITEBYTECODE=1 python -m pytest -m "not cuda" -q
442
+ ```
443
+
444
+ On a configured CUDA device, run the GPU-marked checks separately:
445
+
446
+ ```bash
447
+ PYTHONDONTWRITEBYTECODE=1 python -m pytest -m cuda -q
448
+ ```
449
+
450
+ The headline 24-layer campaign is independently auditable on CPU from the
451
+ checked-in raw reports and exact measured-source archive:
452
+
453
+ ```bash
454
+ python -m benchmarks.audit_current_24l \
455
+ --evidence-dir results/current_24l --repo .
456
+ ```
457
+
458
+ To regenerate the hero after installing `.[plot]`:
459
+
460
+ ```bash
461
+ python -m benchmarks.plot_compiled_step_hero \
462
+ --projection results/current_24l/hero_projection.json \
463
+ --output-dir docs/assets
464
+ ```
465
+
466
+ The small training harness exercises standard/sliced and Full/Block routes:
467
+
468
+ ```bash
469
+ PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src:. \
470
+ python examples/train.py --backend reference --device cpu \
471
+ --mode full --variant standard --steps 2
472
+ ```
473
+
474
+ Use `--backend kernel --device cuda` on a configured CUDA environment. The
475
+ example trains on random next-token data and is a smoke test, not a benchmark.
476
+
477
+ ## Citation and license
478
+
479
+ Please cite [Attention Residuals](https://arxiv.org/abs/2603.15031) for the
480
+ base method and [Low-Rank Attention Residuals](https://arxiv.org/abs/2607.09694)
481
+ for the low-rank extension. For the implementation itself:
482
+
483
+ ```bibtex
484
+ @misc{su2026attnreskernels,
485
+ author = {Jonathan Su},
486
+ title = {Fast Attention Residuals},
487
+ year = {2026},
488
+ url = {https://github.com/jon123boss/fast-attnres}
489
+ }
490
+ ```
491
+
492
+ The package is released under the [MIT License](https://github.com/jon123boss/fast-attnres/blob/main/LICENSE). The FLA-derived
493
+ source-list kernel attribution and license notice are recorded in [NOTICE](https://github.com/jon123boss/fast-attnres/blob/main/NOTICE).