amass-kv 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 (48) hide show
  1. amass_kv-0.1.0/LICENSE +201 -0
  2. amass_kv-0.1.0/MANIFEST.in +23 -0
  3. amass_kv-0.1.0/PKG-INFO +179 -0
  4. amass_kv-0.1.0/README.md +142 -0
  5. amass_kv-0.1.0/pyproject.toml +89 -0
  6. amass_kv-0.1.0/setup.cfg +4 -0
  7. amass_kv-0.1.0/src/amass/__init__.py +31 -0
  8. amass_kv-0.1.0/src/amass/attention/__init__.py +37 -0
  9. amass_kv-0.1.0/src/amass/attention/decode.py +304 -0
  10. amass_kv-0.1.0/src/amass/attention/decode_cuda.py +1378 -0
  11. amass_kv-0.1.0/src/amass/attention/merge.py +50 -0
  12. amass_kv-0.1.0/src/amass/backend/__init__.py +29 -0
  13. amass_kv-0.1.0/src/amass/backend/_runtime.py +281 -0
  14. amass_kv-0.1.0/src/amass/backend/_selection_bridge.py +133 -0
  15. amass_kv-0.1.0/src/amass/backend/attn.py +119 -0
  16. amass_kv-0.1.0/src/amass/backend/builder.py +479 -0
  17. amass_kv-0.1.0/src/amass/backend/register.py +101 -0
  18. amass_kv-0.1.0/src/amass/bench/__init__.py +50 -0
  19. amass_kv-0.1.0/src/amass/bench/__main__.py +7 -0
  20. amass_kv-0.1.0/src/amass/bench/cli.py +151 -0
  21. amass_kv-0.1.0/src/amass/bench/e2e.py +229 -0
  22. amass_kv-0.1.0/src/amass/bench/kernels.py +393 -0
  23. amass_kv-0.1.0/src/amass/bench/timing.py +131 -0
  24. amass_kv-0.1.0/src/amass/config.py +161 -0
  25. amass_kv-0.1.0/src/amass/selection/__init__.py +59 -0
  26. amass_kv-0.1.0/src/amass/selection/build.py +632 -0
  27. amass_kv-0.1.0/src/amass/selection/quad_build.py +198 -0
  28. amass_kv-0.1.0/src/amass/selection/quad_score.py +551 -0
  29. amass_kv-0.1.0/src/amass/selection/quad_score_cuda.py +1308 -0
  30. amass_kv-0.1.0/src/amass/selection/quad_state.py +151 -0
  31. amass_kv-0.1.0/src/amass/selection/score.py +148 -0
  32. amass_kv-0.1.0/src/amass/selection/score_cuda.py +913 -0
  33. amass_kv-0.1.0/src/amass/selection/select.py +130 -0
  34. amass_kv-0.1.0/src/amass/selection/select_cuda.py +391 -0
  35. amass_kv-0.1.0/src/amass/selection/state.py +112 -0
  36. amass_kv-0.1.0/src/amass/tier/__init__.py +41 -0
  37. amass_kv-0.1.0/src/amass/tier/decode_mem.py +264 -0
  38. amass_kv-0.1.0/src/amass/tier/dma.py +140 -0
  39. amass_kv-0.1.0/src/amass/tier/pool.py +151 -0
  40. amass_kv-0.1.0/src/amass/tier/residency.py +577 -0
  41. amass_kv-0.1.0/src/amass/tier/staging.py +507 -0
  42. amass_kv-0.1.0/src/amass/tier/tier.py +265 -0
  43. amass_kv-0.1.0/src/amass_kv.egg-info/PKG-INFO +179 -0
  44. amass_kv-0.1.0/src/amass_kv.egg-info/SOURCES.txt +46 -0
  45. amass_kv-0.1.0/src/amass_kv.egg-info/dependency_links.txt +1 -0
  46. amass_kv-0.1.0/src/amass_kv.egg-info/entry_points.txt +5 -0
  47. amass_kv-0.1.0/src/amass_kv.egg-info/requires.txt +16 -0
  48. amass_kv-0.1.0/src/amass_kv.egg-info/top_level.txt +1 -0
amass_kv-0.1.0/LICENSE ADDED
@@ -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 Derivative
95
+ 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,23 @@
1
+ # MANIFEST.in -- controls what goes into the sdist (.tar.gz). The wheel's
2
+ # contents are governed by pyproject's package discovery (pure `.py` modules).
3
+
4
+ # Project metadata.
5
+ include README.md
6
+ include LICENSE
7
+ include MANIFEST.in
8
+ include pyproject.toml
9
+
10
+ # Ship every Python source under the package (the runtime CUDA kernels are
11
+ # `.py` files that `load_inline` at import time, so they MUST be included).
12
+ recursive-include src/amass *.py
13
+
14
+ # Keep dev-only notes and byte-compiled / scratch junk out of the release.
15
+ recursive-exclude src *.md
16
+ global-exclude *.pyc
17
+ global-exclude *.pyo
18
+ global-exclude *.so
19
+ global-exclude *~
20
+ global-exclude __pycache__/*
21
+ prune **/__pycache__
22
+ prune **/scratch_*
23
+ prune **/tmp_*
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: amass-kv
3
+ Version: 0.1.0
4
+ Summary: AMASS: decode-time sparse KV-cache attention for vLLM (quad page-score selector + DRAM value tier)
5
+ Author-email: Junsung Hwang <junsung.k.hwang@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Js-Hwang1/amass-kv
8
+ Project-URL: Repository, https://github.com/Js-Hwang1/amass-kv
9
+ Project-URL: Issues, https://github.com/Js-Hwang1/amass-kv/issues
10
+ Keywords: vllm,kv-cache,sparse-attention,llm-inference,decode,long-context,flash-attention,cuda
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Environment :: GPU :: NVIDIA CUDA
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: torch>=2.4
25
+ Requires-Dist: triton>=3.0
26
+ Provides-Extra: vllm
27
+ Requires-Dist: vllm>=0.8; extra == "vllm"
28
+ Provides-Extra: yaml
29
+ Requires-Dist: pyyaml>=6.0; extra == "yaml"
30
+ Provides-Extra: bench
31
+ Requires-Dist: transformers>=4.40; extra == "bench"
32
+ Provides-Extra: all
33
+ Requires-Dist: vllm>=0.8; extra == "all"
34
+ Requires-Dist: transformers>=4.40; extra == "all"
35
+ Requires-Dist: pyyaml>=6.0; extra == "all"
36
+ Dynamic: license-file
37
+
38
+ # AMASS
39
+
40
+ **Decode-time sparse KV-cache attention for vLLM.** AMASS keeps LLM decoding
41
+ fast and memory-light at long context by attending, at every decode step, to
42
+ only the pages that actually carry attention mass: a compact per-page score
43
+ selects a small working set (typically 5 to 10 percent of the KV cache), and a
44
+ sparse paged-attention kernel reads just those pages. Prefill is untouched, so
45
+ time-to-first-token is unchanged.
46
+
47
+ > **License note (provisional).** This release is distributed under Apache-2.0
48
+ > as a placeholder pending final confirmation by the authors. See `LICENSE`.
49
+
50
+ ## What is in the box
51
+
52
+ AMASS has two parts that share one selection core:
53
+
54
+ 1. **The quad selector (Stage A).** A quadratic, Gaussian-MGF page score built
55
+ from a tiny per-page summary. "quad" drops the per-key coordinates and stores
56
+ only `r'` eigenvalues per page, which shrinks the resident selector state by
57
+ **3.28x** (from 15.6 percent down to 4.7 percent of the KV cache; measured
58
+ 1201 MiB vs 3943 MiB) while remaining accurate enough to pick the right pages.
59
+ 2. **The DRAM value tier (Stage B).** A pinned, device-mapped host-DRAM pool for
60
+ the value cache, with a bounded resident hot buffer plus staging pool. Only
61
+ the ~5 percent quad summary and the pages actually called each step stay in
62
+ VRAM; the rest of V (or K+V) lives in host memory.
63
+
64
+ ### Two variants, one algorithm
65
+
66
+ | Variant | KV residency | The play |
67
+ | ------------- | --------------------------------------------- | ----------------- |
68
+ | **AMASS-fast** | K+V resident in VRAM | speed |
69
+ | **AMASS-mem** | V (mem-v) or K+V (mem-kv) offloaded to DRAM; only the quad summary + called pages resident | memory + speed |
70
+
71
+ ## Install
72
+
73
+ ```bash
74
+ pip install amass-kv
75
+ ```
76
+
77
+ The import name is `amass`:
78
+
79
+ ```python
80
+ import amass
81
+ print(amass.__version__)
82
+ ```
83
+
84
+ `amass-kv` declares `torch` and `triton` as its runtime dependencies. vLLM is an
85
+ **optional extra** (see [Dependencies](#dependencies)); install AMASS into your
86
+ existing vLLM environment, or pull a compatible engine with:
87
+
88
+ ```bash
89
+ pip install "amass-kv[vllm]" # engine + plugin
90
+ pip install "amass-kv[all]" # + transformers (bench) + pyyaml (yaml configs)
91
+ ```
92
+
93
+ Requires Python >= 3.10 and an NVIDIA GPU. The hot-path CUDA kernels are
94
+ compiled once at first use via `torch.utils.cpp_extension` (targeting Hopper,
95
+ `sm_90a`); the reference Triton kernels are the automatic fallback.
96
+
97
+ ## Quickstart
98
+
99
+ AMASS installs as a vLLM **general plugin**, so once the wheel is present vLLM
100
+ auto-registers it at engine startup with no code change: AMASS patches itself in
101
+ wherever vLLM would have chosen the FlashAttention backend. Configuration is a
102
+ single `AmassConfig`, sourced from the `AMASS_CONFIG` environment variable (an
103
+ inline JSON string, or a path to a JSON/YAML file):
104
+
105
+ ```bash
106
+ # Run any vLLM entry point (serve / offline) with AMASS active.
107
+ export AMASS_CONFIG='{"variant": "fast", "coverage": 0.95}'
108
+ vllm serve meta-llama/Llama-3.1-8B-Instruct
109
+
110
+ # The memory play: offload V to DRAM, keep K resident.
111
+ export AMASS_CONFIG='{"variant": "mem-v", "coverage": 0.95}'
112
+
113
+ # Turn AMASS off (stock FlashAttention / FullKV reference line):
114
+ export AMASS_DISABLE=1
115
+ ```
116
+
117
+ Key `AmassConfig` fields: `variant` (`fast` / `mem-v` / `mem-kv`), `coverage`
118
+ (adaptive per-head nucleus coverage over exact page masses; default 0.95) or
119
+ `budget` (a fixed selected-page fraction), `score` (`quad` default, or the `r8`
120
+ low-rank fallback), and `use_cuda` (hand-CUDA hot path vs Triton reference).
121
+
122
+ ## Headline results (measured)
123
+
124
+ - **3.28x smaller selector state.** The quad summary is 4.7 percent of the KV
125
+ cache vs 15.6 percent for the low-rank `r8` baseline (1201 vs 3943 MiB
126
+ measured), with a cheaper tail-free hot-path kernel.
127
+ - **Near-lossless on LongBench.** quad at a 5 percent per-step budget lands
128
+ within noise of FullKV (LongBench-v1 delta about -0.22 for quad vs -0.38 for
129
+ r8 at the same budget; about -0.29 at coverage 0.95 across 14 subsets).
130
+ - **Faster in the regime that matters.** AMASS-fast beats dense FlashAttention-3
131
+ in the **long-context, high-batch** decode regime by up to about **2x**, and
132
+ is at **parity at batch size 1** (the hot path is bandwidth-bound and only
133
+ pulls ahead once the dense KV read dominates). It does not claim >=2x
134
+ everywhere.
135
+ - **76 to 92 percent VRAM saved** in the mem variant, by holding only the quad
136
+ summary plus the called pages resident and serving the rest of V from DRAM.
137
+
138
+ Numbers are per-kernel and end-to-end reproducible with `amass-bench` (below).
139
+ See the paper for the full protocol, benchmarks (RULER, LongBench v1/v2,
140
+ SCBench, a reasoning suite), and ablations.
141
+
142
+ - Paper: see the project page linked in this repository.
143
+
144
+ ## Benchmarking: `amass-bench`
145
+
146
+ The wheel ships a benchmarker so the latency claims are reproducible on any
147
+ Hopper box with one command:
148
+
149
+ ```bash
150
+ amass-bench kernels --quick # per-kernel: r8_score / topb / decode, CUDA vs Triton vs dense-FA
151
+ amass-bench e2e --ctx 16384 # end-to-end decode-step TPOT in a real vLLM run
152
+ amass-bench all --json out.json
153
+ python -m amass.bench kernels # identical to the console entry point
154
+ ```
155
+
156
+ `amass-bench e2e` needs the `bench` + `vllm` extras (it tokenizes a real model
157
+ and spins up an engine). Timing is CUDA-event based with warmup and medians, and
158
+ reports both eager and CUDA-graph-replay speedups plus an HBM roofline for the
159
+ bandwidth-bound score kernel. Full flag reference: `amass-bench --help`.
160
+
161
+ ## Dependencies
162
+
163
+ | Dependency | Why | How it is declared |
164
+ | -------------- | ------------------------------------------------ | ------------------------- |
165
+ | `torch` | tensors + runtime CUDA (`load_inline`) kernels | hard (`>=2.4`) |
166
+ | `triton` | reference / fallback kernels | hard (`>=3.0`) |
167
+ | `vllm` | plugin host + attention backend | extra `[vllm]` (`>=0.8`) |
168
+ | `transformers` | `amass-bench e2e` tokenizer (lazy import) | extra `[bench]` |
169
+ | `pyyaml` | YAML `AMASS_CONFIG` files (JSON needs no dep) | extra `[yaml]` |
170
+
171
+ `numpy` is **not** a direct dependency: nothing under `amass/` imports it; it
172
+ arrives transitively through torch. vLLM is an extra rather than a hard floor
173
+ because it is a heavy, CUDA-ABI-sensitive wheel that production deployments pin
174
+ themselves, and a hard floor could silently upgrade a pinned engine.
175
+
176
+ ## License
177
+
178
+ Apache-2.0 (provisional; see the note at the top). See `LICENSE` for the full
179
+ text.
@@ -0,0 +1,142 @@
1
+ # AMASS
2
+
3
+ **Decode-time sparse KV-cache attention for vLLM.** AMASS keeps LLM decoding
4
+ fast and memory-light at long context by attending, at every decode step, to
5
+ only the pages that actually carry attention mass: a compact per-page score
6
+ selects a small working set (typically 5 to 10 percent of the KV cache), and a
7
+ sparse paged-attention kernel reads just those pages. Prefill is untouched, so
8
+ time-to-first-token is unchanged.
9
+
10
+ > **License note (provisional).** This release is distributed under Apache-2.0
11
+ > as a placeholder pending final confirmation by the authors. See `LICENSE`.
12
+
13
+ ## What is in the box
14
+
15
+ AMASS has two parts that share one selection core:
16
+
17
+ 1. **The quad selector (Stage A).** A quadratic, Gaussian-MGF page score built
18
+ from a tiny per-page summary. "quad" drops the per-key coordinates and stores
19
+ only `r'` eigenvalues per page, which shrinks the resident selector state by
20
+ **3.28x** (from 15.6 percent down to 4.7 percent of the KV cache; measured
21
+ 1201 MiB vs 3943 MiB) while remaining accurate enough to pick the right pages.
22
+ 2. **The DRAM value tier (Stage B).** A pinned, device-mapped host-DRAM pool for
23
+ the value cache, with a bounded resident hot buffer plus staging pool. Only
24
+ the ~5 percent quad summary and the pages actually called each step stay in
25
+ VRAM; the rest of V (or K+V) lives in host memory.
26
+
27
+ ### Two variants, one algorithm
28
+
29
+ | Variant | KV residency | The play |
30
+ | ------------- | --------------------------------------------- | ----------------- |
31
+ | **AMASS-fast** | K+V resident in VRAM | speed |
32
+ | **AMASS-mem** | V (mem-v) or K+V (mem-kv) offloaded to DRAM; only the quad summary + called pages resident | memory + speed |
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install amass-kv
38
+ ```
39
+
40
+ The import name is `amass`:
41
+
42
+ ```python
43
+ import amass
44
+ print(amass.__version__)
45
+ ```
46
+
47
+ `amass-kv` declares `torch` and `triton` as its runtime dependencies. vLLM is an
48
+ **optional extra** (see [Dependencies](#dependencies)); install AMASS into your
49
+ existing vLLM environment, or pull a compatible engine with:
50
+
51
+ ```bash
52
+ pip install "amass-kv[vllm]" # engine + plugin
53
+ pip install "amass-kv[all]" # + transformers (bench) + pyyaml (yaml configs)
54
+ ```
55
+
56
+ Requires Python >= 3.10 and an NVIDIA GPU. The hot-path CUDA kernels are
57
+ compiled once at first use via `torch.utils.cpp_extension` (targeting Hopper,
58
+ `sm_90a`); the reference Triton kernels are the automatic fallback.
59
+
60
+ ## Quickstart
61
+
62
+ AMASS installs as a vLLM **general plugin**, so once the wheel is present vLLM
63
+ auto-registers it at engine startup with no code change: AMASS patches itself in
64
+ wherever vLLM would have chosen the FlashAttention backend. Configuration is a
65
+ single `AmassConfig`, sourced from the `AMASS_CONFIG` environment variable (an
66
+ inline JSON string, or a path to a JSON/YAML file):
67
+
68
+ ```bash
69
+ # Run any vLLM entry point (serve / offline) with AMASS active.
70
+ export AMASS_CONFIG='{"variant": "fast", "coverage": 0.95}'
71
+ vllm serve meta-llama/Llama-3.1-8B-Instruct
72
+
73
+ # The memory play: offload V to DRAM, keep K resident.
74
+ export AMASS_CONFIG='{"variant": "mem-v", "coverage": 0.95}'
75
+
76
+ # Turn AMASS off (stock FlashAttention / FullKV reference line):
77
+ export AMASS_DISABLE=1
78
+ ```
79
+
80
+ Key `AmassConfig` fields: `variant` (`fast` / `mem-v` / `mem-kv`), `coverage`
81
+ (adaptive per-head nucleus coverage over exact page masses; default 0.95) or
82
+ `budget` (a fixed selected-page fraction), `score` (`quad` default, or the `r8`
83
+ low-rank fallback), and `use_cuda` (hand-CUDA hot path vs Triton reference).
84
+
85
+ ## Headline results (measured)
86
+
87
+ - **3.28x smaller selector state.** The quad summary is 4.7 percent of the KV
88
+ cache vs 15.6 percent for the low-rank `r8` baseline (1201 vs 3943 MiB
89
+ measured), with a cheaper tail-free hot-path kernel.
90
+ - **Near-lossless on LongBench.** quad at a 5 percent per-step budget lands
91
+ within noise of FullKV (LongBench-v1 delta about -0.22 for quad vs -0.38 for
92
+ r8 at the same budget; about -0.29 at coverage 0.95 across 14 subsets).
93
+ - **Faster in the regime that matters.** AMASS-fast beats dense FlashAttention-3
94
+ in the **long-context, high-batch** decode regime by up to about **2x**, and
95
+ is at **parity at batch size 1** (the hot path is bandwidth-bound and only
96
+ pulls ahead once the dense KV read dominates). It does not claim >=2x
97
+ everywhere.
98
+ - **76 to 92 percent VRAM saved** in the mem variant, by holding only the quad
99
+ summary plus the called pages resident and serving the rest of V from DRAM.
100
+
101
+ Numbers are per-kernel and end-to-end reproducible with `amass-bench` (below).
102
+ See the paper for the full protocol, benchmarks (RULER, LongBench v1/v2,
103
+ SCBench, a reasoning suite), and ablations.
104
+
105
+ - Paper: see the project page linked in this repository.
106
+
107
+ ## Benchmarking: `amass-bench`
108
+
109
+ The wheel ships a benchmarker so the latency claims are reproducible on any
110
+ Hopper box with one command:
111
+
112
+ ```bash
113
+ amass-bench kernels --quick # per-kernel: r8_score / topb / decode, CUDA vs Triton vs dense-FA
114
+ amass-bench e2e --ctx 16384 # end-to-end decode-step TPOT in a real vLLM run
115
+ amass-bench all --json out.json
116
+ python -m amass.bench kernels # identical to the console entry point
117
+ ```
118
+
119
+ `amass-bench e2e` needs the `bench` + `vllm` extras (it tokenizes a real model
120
+ and spins up an engine). Timing is CUDA-event based with warmup and medians, and
121
+ reports both eager and CUDA-graph-replay speedups plus an HBM roofline for the
122
+ bandwidth-bound score kernel. Full flag reference: `amass-bench --help`.
123
+
124
+ ## Dependencies
125
+
126
+ | Dependency | Why | How it is declared |
127
+ | -------------- | ------------------------------------------------ | ------------------------- |
128
+ | `torch` | tensors + runtime CUDA (`load_inline`) kernels | hard (`>=2.4`) |
129
+ | `triton` | reference / fallback kernels | hard (`>=3.0`) |
130
+ | `vllm` | plugin host + attention backend | extra `[vllm]` (`>=0.8`) |
131
+ | `transformers` | `amass-bench e2e` tokenizer (lazy import) | extra `[bench]` |
132
+ | `pyyaml` | YAML `AMASS_CONFIG` files (JSON needs no dep) | extra `[yaml]` |
133
+
134
+ `numpy` is **not** a direct dependency: nothing under `amass/` imports it; it
135
+ arrives transitively through torch. vLLM is an extra rather than a hard floor
136
+ because it is a heavy, CUDA-ABI-sensitive wheel that production deployments pin
137
+ themselves, and a hard floor could silently upgrade a pinned engine.
138
+
139
+ ## License
140
+
141
+ Apache-2.0 (provisional; see the note at the top). See `LICENSE` for the full
142
+ text.
@@ -0,0 +1,89 @@
1
+ # pyproject.toml -- standalone release metadata for the AMASS pip package.
2
+ #
3
+ # This tree is SELF-CONTAINED: it is not the research-repo root pyproject (that
4
+ # one builds the separate `kvcomp` harness). `packaging/build.sh` stages a
5
+ # snapshot of the live `src/amass` into `src/amass` next to this file, then
6
+ # builds the sdist + wheel from here.
7
+ #
8
+ # Distribution name = `amass-kv` (PyPI). Import name = `amass` (`import amass`).
9
+
10
+ [build-system]
11
+ requires = ["setuptools>=77", "wheel"]
12
+ build-backend = "setuptools.build_meta"
13
+
14
+ [project]
15
+ name = "amass-kv"
16
+ version = "0.1.0"
17
+ description = "AMASS: decode-time sparse KV-cache attention for vLLM (quad page-score selector + DRAM value tier)"
18
+ readme = "README.md"
19
+ requires-python = ">=3.10"
20
+ license = "Apache-2.0"
21
+ license-files = ["LICENSE"]
22
+ authors = [
23
+ { name = "Junsung Hwang", email = "junsung.k.hwang@gmail.com" },
24
+ ]
25
+ keywords = [
26
+ "vllm", "kv-cache", "sparse-attention", "llm-inference",
27
+ "decode", "long-context", "flash-attention", "cuda",
28
+ ]
29
+ classifiers = [
30
+ "Development Status :: 4 - Beta",
31
+ "Intended Audience :: Developers",
32
+ "Intended Audience :: Science/Research",
33
+ "Operating System :: POSIX :: Linux",
34
+ "Programming Language :: Python :: 3",
35
+ "Programming Language :: Python :: 3.10",
36
+ "Programming Language :: Python :: 3.11",
37
+ "Programming Language :: Python :: 3.12",
38
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
39
+ "Environment :: GPU :: NVIDIA CUDA",
40
+ ]
41
+
42
+ # Runtime deps that are ALWAYS needed once you touch a kernel (the whole point
43
+ # of the package). Kept minimal + floors-only so AMASS drops into an existing
44
+ # CUDA/torch deployment without fighting the resolver. `numpy` is intentionally
45
+ # absent: nothing under `amass/` imports it directly (it arrives transitively
46
+ # via torch). See README "Dependencies".
47
+ dependencies = [
48
+ "torch>=2.4",
49
+ "triton>=3.0",
50
+ ]
51
+
52
+ [project.optional-dependencies]
53
+ # vLLM is the plugin host. It is REQUIRED for the backend/plugin path but is a
54
+ # heavy, CUDA-ABI-sensitive wheel that real deployments pin themselves, so we
55
+ # ship it as an extra rather than a hard floor that could upgrade a pinned
56
+ # engine out from under the user. Install AMASS into your existing vLLM env, or
57
+ # `pip install amass-kv[vllm]` to pull a compatible engine.
58
+ vllm = ["vllm>=0.8"]
59
+ # YAML `AMASS_CONFIG` files (JSON configs work with no extra dep).
60
+ yaml = ["pyyaml>=6.0"]
61
+ # `amass-bench e2e` tokenizes a real model (lazy `transformers` import); it also
62
+ # needs the `vllm` extra to spin up an engine.
63
+ bench = ["transformers>=4.40"]
64
+ # Everything for the full plugin + bench + yaml experience.
65
+ all = ["vllm>=0.8", "transformers>=4.40", "pyyaml>=6.0"]
66
+
67
+ [project.urls]
68
+ Homepage = "https://github.com/Js-Hwang1/amass-kv"
69
+ Repository = "https://github.com/Js-Hwang1/amass-kv"
70
+ Issues = "https://github.com/Js-Hwang1/amass-kv/issues"
71
+
72
+ # Console script: `amass-bench <kernels|e2e|all>`.
73
+ [project.scripts]
74
+ amass-bench = "amass.bench.cli:main"
75
+
76
+ # vLLM general-plugin auto-registration: with the wheel installed, vLLM calls
77
+ # this at engine startup with NO import needed in user code, and AMASS patches
78
+ # itself in as the attention backend.
79
+ [project.entry-points."vllm.general_plugins"]
80
+ amass = "amass.backend.register:register"
81
+
82
+ [tool.setuptools.packages.find]
83
+ where = ["src"]
84
+ include = ["amass*"]
85
+
86
+ [tool.setuptools.package-data]
87
+ # The CUDA kernels are `.py` sources compiled at runtime via `load_inline`, so
88
+ # they ship as ordinary modules (no data files). Nothing extra to include.
89
+ amass = []
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,31 @@
1
+ """AMASS — decode-time certified page selection for KV-cache attention, with an
2
+ optional DRAM offload tier. Two build targets share one algorithm core:
3
+
4
+ * AMASS-fast — K+V resident (the speed play).
5
+ * AMASS-mem — V (or K+V) offloaded to DRAM (default; the memory play).
6
+
7
+ Public API:
8
+ from amass import AmassConfig, register # register() = vLLM plugin hook
9
+
10
+ Architecture (ours_doc/AMASS_DESIGN.md):
11
+ config.py AmassConfig — single source of truth (no scattered env vars)
12
+ selection/ Stage A: decode-time page selection (SHARED by both variants)
13
+ attention/ Stage B: sparse paged attention (V source injected as a seam)
14
+ tier/ DRAM offload state machine (mem variants only)
15
+ backend/ vLLM integration: attention impl, metadata builder, register()
16
+ """
17
+ from __future__ import annotations
18
+
19
+ from .config import AmassConfig # noqa: F401
20
+
21
+ __all__ = ["AmassConfig", "register"]
22
+
23
+ __version__ = "0.1.0"
24
+
25
+
26
+ def register() -> None:
27
+ """vLLM general-plugin entry point. Thin re-export of
28
+ :func:`amass.backend.register.register` so the entry point is stable while
29
+ the backend is ported."""
30
+ from .backend.register import register as _register
31
+ _register()