vllm-knapsack-weight-replication 0.5.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 (67) hide show
  1. vllm_knapsack_weight_replication-0.5.0/LICENSE +202 -0
  2. vllm_knapsack_weight_replication-0.5.0/PKG-INFO +122 -0
  3. vllm_knapsack_weight_replication-0.5.0/README.md +98 -0
  4. vllm_knapsack_weight_replication-0.5.0/pyproject.toml +59 -0
  5. vllm_knapsack_weight_replication-0.5.0/setup.cfg +4 -0
  6. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/__init__.py +5 -0
  7. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/_envs.py +82 -0
  8. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/_patching.py +83 -0
  9. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/_transplant.py +224 -0
  10. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/autotune_patch.py +50 -0
  11. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/canonical_topk.py +247 -0
  12. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/__init__.py +0 -0
  13. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/deepseek_v41.py +20 -0
  14. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/dsa.py +20 -0
  15. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/dsa_auto.py +112 -0
  16. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/dsv41_auto.py +19 -0
  17. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/minimax_m3.py +20 -0
  18. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/qwen3_5.py +94 -0
  19. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/models/qwen3_5_replicate.py +47 -0
  20. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/plugin.py +122 -0
  21. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/topk_patch.py +168 -0
  22. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/tp_synced_autotune.py +190 -0
  23. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/__init__.py +0 -0
  24. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa/__init__.py +0 -0
  25. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa/manifest.py +24 -0
  26. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa/vllm/models/deepseek_v32/attention.py +801 -0
  27. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa/vllm/models/deepseek_v32/nvidia/model.py +514 -0
  28. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa/vllm/v1/attention/backends/mla/flashinfer_mla_sparse_sm120.py +257 -0
  29. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa_auto/__init__.py +0 -0
  30. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa_auto/manifest.py +27 -0
  31. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa_auto/vllm/model_executor/layers/tp_replication.py +75 -0
  32. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa_auto/vllm/model_executor/layers/tp_replication_planner.py +763 -0
  33. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa_auto/vllm/model_executor/layers/tp_replication_probe.py +484 -0
  34. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsa_auto/vllm/models/deepseek_v32/nvidia/model.py +646 -0
  35. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41/__init__.py +0 -0
  36. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41/manifest.py +24 -0
  37. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41/vllm/models/deepseek_v41/attention.py +1772 -0
  38. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41/vllm/models/deepseek_v41/nvidia/flash_mla_mega_attn.py +618 -0
  39. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41/vllm/models/deepseek_v41/nvidia/model.py +2088 -0
  40. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41/vllm/models/deepseek_v41/nvidia/specialized_decode/__init__.py +214 -0
  41. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41_auto/__init__.py +0 -0
  42. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41_auto/manifest.py +20 -0
  43. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41_auto/vllm/models/deepseek_v41/nvidia/flash_mla_mega_attn.py +621 -0
  44. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41_auto/vllm/models/deepseek_v41/nvidia/model.py +2181 -0
  45. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/dsv41_auto/vllm/models/deepseek_v41/nvidia/specialized_decode/__init__.py +218 -0
  46. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/minimax_m3/__init__.py +0 -0
  47. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/minimax_m3/manifest.py +27 -0
  48. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/minimax_m3/vllm/model_executor/layers/linear.py +1905 -0
  49. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/minimax_m3/vllm/models/minimax_m3/common/indexer.py +793 -0
  50. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/minimax_m3/vllm/models/minimax_m3/common/replicate.py +32 -0
  51. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/minimax_m3/vllm/models/minimax_m3/nvidia/model.py +2032 -0
  52. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication/upstream/minimax_m3/vllm/models/minimax_m3/nvidia/sparse_attention_msa.py +604 -0
  53. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication.egg-info/PKG-INFO +122 -0
  54. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication.egg-info/SOURCES.txt +65 -0
  55. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication.egg-info/dependency_links.txt +1 -0
  56. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication.egg-info/entry_points.txt +2 -0
  57. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication.egg-info/requires.txt +4 -0
  58. vllm_knapsack_weight_replication-0.5.0/src/vllm_knapsack_weight_replication.egg-info/top_level.txt +1 -0
  59. vllm_knapsack_weight_replication-0.5.0/tests/test_canonical_topk.py +187 -0
  60. vllm_knapsack_weight_replication-0.5.0/tests/test_dsa_replicate_routing.py +37 -0
  61. vllm_knapsack_weight_replication-0.5.0/tests/test_dsv41_auto.py +52 -0
  62. vllm_knapsack_weight_replication-0.5.0/tests/test_minimax_m3_replicate_attn.py +52 -0
  63. vllm_knapsack_weight_replication-0.5.0/tests/test_plugin.py +130 -0
  64. vllm_knapsack_weight_replication-0.5.0/tests/test_qwen3_5_replicate_ffn.py +65 -0
  65. vllm_knapsack_weight_replication-0.5.0/tests/test_tp_replication_planner.py +538 -0
  66. vllm_knapsack_weight_replication-0.5.0/tests/test_tp_synced_autotune.py +211 -0
  67. vllm_knapsack_weight_replication-0.5.0/tests/test_transplant.py +130 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.4
2
+ Name: vllm-knapsack-weight-replication
3
+ Version: 0.5.0
4
+ Summary: TP block replication for vLLM: keep chosen blocks whole on every TP rank to skip their all-reduce on slow links
5
+ Author: Alberto Massidda
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/aijanai/vllm-knapsack-weight-replication
8
+ Project-URL: Issues, https://github.com/aijanai/vllm-knapsack-weight-replication/issues
9
+ Project-URL: RFC, https://github.com/vllm-project/vllm/issues/66873
10
+ Keywords: vllm,tensor-parallelism,inference,llm,plugin
11
+ Classifier: Development Status :: 3 - Alpha
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: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Provides-Extra: test
21
+ Requires-Dist: pytest; extra == "test"
22
+ Requires-Dist: tblib; extra == "test"
23
+ Dynamic: license-file
24
+
25
+ # vllm-knapsack-weight-replication
26
+
27
+ TP block replication for vLLM. Under tensor parallelism every attention or MLP block ends with an all-reduce. On slow links between GPUs (PCIe, Ethernet between nodes) those all-reduces dominate the step. Replication keeps chosen blocks whole on every TP rank: each rank computes the block's full output, so the all-reduce after it disappears, at the cost of the block's weights on every rank. The method, the measurements and where it does not help are in the RFC, vllm-project/vllm#66873.
28
+
29
+ This package carries the code of the vLLM pull requests as a vLLM general plugin, so it runs on an upstream vLLM without waiting for the reviews. Each feature keeps the switch name of its pull request, and the plugin steps aside for any feature the installed vLLM already ships.
30
+
31
+ ## Use
32
+
33
+ ```bash
34
+ pip install vllm-knapsack-weight-replication # inside the vLLM environment or image
35
+ export VLLM_KNAPSACK_QWEN3_5_FFN=1 # pick a replication switch (table below)
36
+ vllm serve Qwen/Qwen3.5-27B --tensor-parallel-size 4 # unchanged command
37
+ ```
38
+
39
+ With no switch set the plugin does nothing.
40
+
41
+ Formerly `vllm-tp-replication`: the module is now `vllm_knapsack_weight_replication`, and the replication switches and planner knobs moved from `VLLM_TP_REPLICATION_*` and `VLLM_<MODEL>_REPLICATE_*` to `VLLM_KNAPSACK_*`, the same names as in the pull requests. `VLLM_TRITON_SYNC_AUTOTUNE_TP` and `VLLM_DETERMINISTIC_SPARSE_TOPK` keep their names.
42
+
43
+ ## Where it fits
44
+
45
+ Replication pays off where tensor parallelism has to cross a slow link, and that is the setup it is built for:
46
+
47
+ - Several DGX Stations (one GB300 each) serving one model with TP across the machines, over their network links.
48
+ - Several multi-GPU nodes, for example 4 GPUs per node, with TP spanning the nodes: the all-reduces cross the node boundary on every layer, and replicating the blocks the planner picks removes them.
49
+ - GPUs in one box without a fast interconnect (PCIe only).
50
+
51
+ On NVLink-connected GPUs inside one node the all-reduce is cheap and replication rarely helps; the online planner returns an empty plan whenever replication does not beat plain TP.
52
+
53
+ ## What is in it
54
+
55
+ | Switch | Pull request | Status |
56
+ | --- | --- | --- |
57
+ | `VLLM_TRITON_SYNC_AUTOTUNE_TP` | vllm-project/vllm#66526: every TP rank adopts rank 0's Triton autotune choice | ported |
58
+ | `VLLM_DETERMINISTIC_SPARSE_TOPK` | vllm-project/vllm#67044: canonical sparse-indexer top-k, the same set and order on every rank | ported |
59
+ | `VLLM_KNAPSACK_QWEN3_5_FFN` | vllm-project/vllm#67285: dense Qwen3.5 keeps every MLP whole | ported |
60
+ | `VLLM_KNAPSACK_MINIMAX_M3_ATTN` | vllm-project/vllm#66378: MiniMax-M3 keeps every attention layer whole | ported |
61
+ | `VLLM_KNAPSACK_DSA_ATTN` (+ `VLLM_KNAPSACK_DSA_ATTN_MIN_TOKENS`) | vllm-project/vllm#66867: DSA (DeepSeek-V3.2, GLM-5.x) keeps every sparse-MLA layer whole; small steps can run head-sharded | ported |
62
+ | GLM-5.x-Next KDA and MLA mixers | vllm-project/vllm#66868 | to do |
63
+ | `VLLM_KNAPSACK_DSV41_MIXER` | vllm-project/vllm#66869: DeepSeek-V4.1 keeps every attention layer whole | ported |
64
+ | Qwen4Exp GDN and QSA mixers | vllm-project/vllm#66870 | to do |
65
+ | Muse Spark attention | vllm-project/vllm#66871 | to do |
66
+ | NemotronH Mamba2 and attention mixers | vllm-project/vllm#66872 | to do |
67
+ | `VLLM_KNAPSACK_PLAN` | Online planner (this package, not a pull request): per-layer plans, picked at startup from a probe and a memory budget | DSA models, DeepSeek-V4.1 |
68
+
69
+ A replication switch installs what it needs underneath: the synced autotune for every model, and the canonical top-k for the sparse-attention models. Without them the ranks of a replicated block drift apart in the last bits, and nothing re-syncs them.
70
+
71
+ ## Online planner
72
+
73
+ Instead of replicating every layer, `VLLM_KNAPSACK_PLAN` picks which ones:
74
+
75
+ ```bash
76
+ export VLLM_KNAPSACK_PLAN=auto VLLM_KNAPSACK_PROBE=1
77
+ export VLLM_KNAPSACK_SESSIONS=4 VLLM_KNAPSACK_ISL=2048 VLLM_KNAPSACK_OSL=256
78
+ vllm serve <model> --tensor-parallel-size 2 # unchanged command
79
+ ```
80
+
81
+ - With `VLLM_KNAPSACK_PROBE=1`, `vllm serve` first runs a probe on small copies of the same server, with the decoder cut to a few layers and the real weights of those layers. It starts the server twice to measure memory, then times decode and prefill steps with `vllm bench forward` in five variants: plain TP, TP without ShardQ, TP with the canonical top-k, both, and every layer replicated. The result is cached per server command (`VLLM_KNAPSACK_PROBE_RESULT`).
82
+ - The plan spends the memory left after the plain-TP weights, the KV of `VLLM_KNAPSACK_SESSIONS` x `VLLM_KNAPSACK_SESSION_TOKENS` (default `max_model_len`), activations and the drafter. It replicates layers only if the gain per request (`ISL` prefill chunks plus `OSL / (1 + VLLM_KNAPSACK_SPEC_ACCEPT)` decode steps at `VLLM_KNAPSACK_DECODE_BS`) beats the fixed cost of replicating at all, measured against the better of TP with and without ShardQ. Otherwise the plan is empty.
83
+ - With `VLLM_KNAPSACK_KV_OFFLOAD_GIB` (host RAM per rank for KV, as given to the server's KV offloading), the plan may also push the KV of idle sessions (all but `DECODE_BS` of the `SESSIONS`) to host RAM to replicate more. Each byte is charged its reload: a resumed request finds its KV on the host with probability spilled / idle KV, and reloads it at the measured host-to-device bandwidth. So the plan weighs replication against plain TP with every session's KV on the GPU.
84
+ - An explicit plan names the layers instead: `VLLM_KNAPSACK_PLAN="dsa_attn:0-77"` (DSA attention) or `"dsv41_mixer:0-60"` (the DeepSeek-V4.1 attention mixer); `*` matches either. With the variable unset, the per-model switches apply unchanged.
85
+ - Startup logs the budget, the plan and the replicated GiB per rank (`TP replication budget/plan:`).
86
+ - DSA models (DeepSeek-V3.2, GLM-5.x) and DeepSeek-V4.1 read the plan; the probe runs on a single node. Under a DeepSeek-V4.1 plan the attention class is the one that serves the sharded layers, and the specialized decode (`decode_backend=latency_specialized`) is off.
87
+ - MiniMax-M3 does not read the plan yet: its indexer and KV layout are set for the whole model by the switch, so a per-layer plan needs changes beyond the model file.
88
+
89
+ ## Offline planner
90
+
91
+ `tools/offline_planner/` holds the roofline planner used to choose the per-model switches before the online planner existed: safetensors headers plus measured all-reduce tables (`tar/`) give the expected step time of each plan. It is a research tool, kept in the repository but not shipped in the package; see its README.
92
+
93
+ ## How it works
94
+
95
+ - The files the pull requests add (`tp_synced_autotune.py`, `canonical_topk.py`, `qwen3_5_replicate.py`) are copied unchanged and exposed under their upstream module names, so code written against the pull requests imports them as is. One local change: `canonical_topk.py` skips the blocks past each row's end, so its CUDA-graph grid sized by `max_model_len` costs little at short contexts (72 to 14 us for 32 rows of 2K in a 200K buffer, output unchanged).
96
+ - Where a pull request edits vLLM, the plugin wraps the function or class at that point instead. For example, it wraps the sparse-indexer top-k entry points rather than each caller, and the model's MLP class rather than the line that builds it.
97
+ - The model pull requests edit constructors and forward passes deep inside the model files, where a wrapper cannot reach. For those the package carries the PR's files unchanged (`upstream/<feature>/`) and a manifest of the symbols each PR changes, with the hash of their source at the PR base. When vLLM imports the module, each listed symbol is checked against the installed source and replaced in memory by the PR's version, compiled in the module's own namespace. `tools/sync_pr.py` regenerates the copies and the manifest from the PR branches.
98
+ - Every patch checks that its hook point exists, and the transplanted symbols must match the PR base exactly. On a vLLM where one moved, the plugin stops with an error naming it and patches nothing, never silently. Files on disk are never modified.
99
+ - The DSA PR's one-line change to `SparseMLACommonImpl` (the masked-MHA head count) is not carried: the PR's own attention layer recomputes that gate for replicated layers, which is the only case where it differs.
100
+
101
+ ## Compatibility
102
+
103
+ Tested against vLLM main at 85a084c38c (2026-11-25), the base of the pull requests. Newer vLLM builds work while the hook points stay and, for the model pull requests, while the patched symbols keep their source; the error above names the one that moved.
104
+
105
+ ## Tests
106
+
107
+ The pull requests' own tests run unchanged against an upstream vLLM with the plugin applied, plus the plugin's own tests:
108
+
109
+ ```bash
110
+ pip install -e '.[test]'
111
+ pytest tests
112
+ ```
113
+
114
+ Validated so far: the tests above on an RTX 4090 (86 passed; 2 skipped, which need SM90+), including the DSA and MiniMax-M3 pull requests' own tests and the transplant checks, and a serve smoke test with Qwen3.5-0.8B. Without the patches, the top-k tests fail (negative control). Measurements of the method on multi-node setups are in the RFC; end-to-end runs of the plugin itself on them are in progress.
115
+
116
+ ## License
117
+
118
+ Apache-2.0, like vLLM.
119
+
120
+ ## Releases
121
+
122
+ Pushing a GitHub release whose tag is `v<version>` (the `__version__` in `src/vllm_knapsack_weight_replication/__init__.py`) publishes the wheel and sdist to PyPI through trusted publishing: no PyPI token is stored in the repository. The workflow refuses a tag that does not match the version, and checks that the wheel carries every file the plugin loads.
@@ -0,0 +1,98 @@
1
+ # vllm-knapsack-weight-replication
2
+
3
+ TP block replication for vLLM. Under tensor parallelism every attention or MLP block ends with an all-reduce. On slow links between GPUs (PCIe, Ethernet between nodes) those all-reduces dominate the step. Replication keeps chosen blocks whole on every TP rank: each rank computes the block's full output, so the all-reduce after it disappears, at the cost of the block's weights on every rank. The method, the measurements and where it does not help are in the RFC, vllm-project/vllm#66873.
4
+
5
+ This package carries the code of the vLLM pull requests as a vLLM general plugin, so it runs on an upstream vLLM without waiting for the reviews. Each feature keeps the switch name of its pull request, and the plugin steps aside for any feature the installed vLLM already ships.
6
+
7
+ ## Use
8
+
9
+ ```bash
10
+ pip install vllm-knapsack-weight-replication # inside the vLLM environment or image
11
+ export VLLM_KNAPSACK_QWEN3_5_FFN=1 # pick a replication switch (table below)
12
+ vllm serve Qwen/Qwen3.5-27B --tensor-parallel-size 4 # unchanged command
13
+ ```
14
+
15
+ With no switch set the plugin does nothing.
16
+
17
+ Formerly `vllm-tp-replication`: the module is now `vllm_knapsack_weight_replication`, and the replication switches and planner knobs moved from `VLLM_TP_REPLICATION_*` and `VLLM_<MODEL>_REPLICATE_*` to `VLLM_KNAPSACK_*`, the same names as in the pull requests. `VLLM_TRITON_SYNC_AUTOTUNE_TP` and `VLLM_DETERMINISTIC_SPARSE_TOPK` keep their names.
18
+
19
+ ## Where it fits
20
+
21
+ Replication pays off where tensor parallelism has to cross a slow link, and that is the setup it is built for:
22
+
23
+ - Several DGX Stations (one GB300 each) serving one model with TP across the machines, over their network links.
24
+ - Several multi-GPU nodes, for example 4 GPUs per node, with TP spanning the nodes: the all-reduces cross the node boundary on every layer, and replicating the blocks the planner picks removes them.
25
+ - GPUs in one box without a fast interconnect (PCIe only).
26
+
27
+ On NVLink-connected GPUs inside one node the all-reduce is cheap and replication rarely helps; the online planner returns an empty plan whenever replication does not beat plain TP.
28
+
29
+ ## What is in it
30
+
31
+ | Switch | Pull request | Status |
32
+ | --- | --- | --- |
33
+ | `VLLM_TRITON_SYNC_AUTOTUNE_TP` | vllm-project/vllm#66526: every TP rank adopts rank 0's Triton autotune choice | ported |
34
+ | `VLLM_DETERMINISTIC_SPARSE_TOPK` | vllm-project/vllm#67044: canonical sparse-indexer top-k, the same set and order on every rank | ported |
35
+ | `VLLM_KNAPSACK_QWEN3_5_FFN` | vllm-project/vllm#67285: dense Qwen3.5 keeps every MLP whole | ported |
36
+ | `VLLM_KNAPSACK_MINIMAX_M3_ATTN` | vllm-project/vllm#66378: MiniMax-M3 keeps every attention layer whole | ported |
37
+ | `VLLM_KNAPSACK_DSA_ATTN` (+ `VLLM_KNAPSACK_DSA_ATTN_MIN_TOKENS`) | vllm-project/vllm#66867: DSA (DeepSeek-V3.2, GLM-5.x) keeps every sparse-MLA layer whole; small steps can run head-sharded | ported |
38
+ | GLM-5.x-Next KDA and MLA mixers | vllm-project/vllm#66868 | to do |
39
+ | `VLLM_KNAPSACK_DSV41_MIXER` | vllm-project/vllm#66869: DeepSeek-V4.1 keeps every attention layer whole | ported |
40
+ | Qwen4Exp GDN and QSA mixers | vllm-project/vllm#66870 | to do |
41
+ | Muse Spark attention | vllm-project/vllm#66871 | to do |
42
+ | NemotronH Mamba2 and attention mixers | vllm-project/vllm#66872 | to do |
43
+ | `VLLM_KNAPSACK_PLAN` | Online planner (this package, not a pull request): per-layer plans, picked at startup from a probe and a memory budget | DSA models, DeepSeek-V4.1 |
44
+
45
+ A replication switch installs what it needs underneath: the synced autotune for every model, and the canonical top-k for the sparse-attention models. Without them the ranks of a replicated block drift apart in the last bits, and nothing re-syncs them.
46
+
47
+ ## Online planner
48
+
49
+ Instead of replicating every layer, `VLLM_KNAPSACK_PLAN` picks which ones:
50
+
51
+ ```bash
52
+ export VLLM_KNAPSACK_PLAN=auto VLLM_KNAPSACK_PROBE=1
53
+ export VLLM_KNAPSACK_SESSIONS=4 VLLM_KNAPSACK_ISL=2048 VLLM_KNAPSACK_OSL=256
54
+ vllm serve <model> --tensor-parallel-size 2 # unchanged command
55
+ ```
56
+
57
+ - With `VLLM_KNAPSACK_PROBE=1`, `vllm serve` first runs a probe on small copies of the same server, with the decoder cut to a few layers and the real weights of those layers. It starts the server twice to measure memory, then times decode and prefill steps with `vllm bench forward` in five variants: plain TP, TP without ShardQ, TP with the canonical top-k, both, and every layer replicated. The result is cached per server command (`VLLM_KNAPSACK_PROBE_RESULT`).
58
+ - The plan spends the memory left after the plain-TP weights, the KV of `VLLM_KNAPSACK_SESSIONS` x `VLLM_KNAPSACK_SESSION_TOKENS` (default `max_model_len`), activations and the drafter. It replicates layers only if the gain per request (`ISL` prefill chunks plus `OSL / (1 + VLLM_KNAPSACK_SPEC_ACCEPT)` decode steps at `VLLM_KNAPSACK_DECODE_BS`) beats the fixed cost of replicating at all, measured against the better of TP with and without ShardQ. Otherwise the plan is empty.
59
+ - With `VLLM_KNAPSACK_KV_OFFLOAD_GIB` (host RAM per rank for KV, as given to the server's KV offloading), the plan may also push the KV of idle sessions (all but `DECODE_BS` of the `SESSIONS`) to host RAM to replicate more. Each byte is charged its reload: a resumed request finds its KV on the host with probability spilled / idle KV, and reloads it at the measured host-to-device bandwidth. So the plan weighs replication against plain TP with every session's KV on the GPU.
60
+ - An explicit plan names the layers instead: `VLLM_KNAPSACK_PLAN="dsa_attn:0-77"` (DSA attention) or `"dsv41_mixer:0-60"` (the DeepSeek-V4.1 attention mixer); `*` matches either. With the variable unset, the per-model switches apply unchanged.
61
+ - Startup logs the budget, the plan and the replicated GiB per rank (`TP replication budget/plan:`).
62
+ - DSA models (DeepSeek-V3.2, GLM-5.x) and DeepSeek-V4.1 read the plan; the probe runs on a single node. Under a DeepSeek-V4.1 plan the attention class is the one that serves the sharded layers, and the specialized decode (`decode_backend=latency_specialized`) is off.
63
+ - MiniMax-M3 does not read the plan yet: its indexer and KV layout are set for the whole model by the switch, so a per-layer plan needs changes beyond the model file.
64
+
65
+ ## Offline planner
66
+
67
+ `tools/offline_planner/` holds the roofline planner used to choose the per-model switches before the online planner existed: safetensors headers plus measured all-reduce tables (`tar/`) give the expected step time of each plan. It is a research tool, kept in the repository but not shipped in the package; see its README.
68
+
69
+ ## How it works
70
+
71
+ - The files the pull requests add (`tp_synced_autotune.py`, `canonical_topk.py`, `qwen3_5_replicate.py`) are copied unchanged and exposed under their upstream module names, so code written against the pull requests imports them as is. One local change: `canonical_topk.py` skips the blocks past each row's end, so its CUDA-graph grid sized by `max_model_len` costs little at short contexts (72 to 14 us for 32 rows of 2K in a 200K buffer, output unchanged).
72
+ - Where a pull request edits vLLM, the plugin wraps the function or class at that point instead. For example, it wraps the sparse-indexer top-k entry points rather than each caller, and the model's MLP class rather than the line that builds it.
73
+ - The model pull requests edit constructors and forward passes deep inside the model files, where a wrapper cannot reach. For those the package carries the PR's files unchanged (`upstream/<feature>/`) and a manifest of the symbols each PR changes, with the hash of their source at the PR base. When vLLM imports the module, each listed symbol is checked against the installed source and replaced in memory by the PR's version, compiled in the module's own namespace. `tools/sync_pr.py` regenerates the copies and the manifest from the PR branches.
74
+ - Every patch checks that its hook point exists, and the transplanted symbols must match the PR base exactly. On a vLLM where one moved, the plugin stops with an error naming it and patches nothing, never silently. Files on disk are never modified.
75
+ - The DSA PR's one-line change to `SparseMLACommonImpl` (the masked-MHA head count) is not carried: the PR's own attention layer recomputes that gate for replicated layers, which is the only case where it differs.
76
+
77
+ ## Compatibility
78
+
79
+ Tested against vLLM main at 85a084c38c (2026-11-25), the base of the pull requests. Newer vLLM builds work while the hook points stay and, for the model pull requests, while the patched symbols keep their source; the error above names the one that moved.
80
+
81
+ ## Tests
82
+
83
+ The pull requests' own tests run unchanged against an upstream vLLM with the plugin applied, plus the plugin's own tests:
84
+
85
+ ```bash
86
+ pip install -e '.[test]'
87
+ pytest tests
88
+ ```
89
+
90
+ Validated so far: the tests above on an RTX 4090 (86 passed; 2 skipped, which need SM90+), including the DSA and MiniMax-M3 pull requests' own tests and the transplant checks, and a serve smoke test with Qwen3.5-0.8B. Without the patches, the top-k tests fail (negative control). Measurements of the method on multi-node setups are in the RFC; end-to-end runs of the plugin itself on them are in progress.
91
+
92
+ ## License
93
+
94
+ Apache-2.0, like vLLM.
95
+
96
+ ## Releases
97
+
98
+ Pushing a GitHub release whose tag is `v<version>` (the `__version__` in `src/vllm_knapsack_weight_replication/__init__.py`) publishes the wheel and sdist to PyPI through trusted publishing: no PyPI token is stored in the repository. The workflow refuses a tag that does not match the version, and checks that the wheel carries every file the plugin loads.
@@ -0,0 +1,59 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "vllm-knapsack-weight-replication"
7
+ dynamic = ["version"]
8
+ description = "TP block replication for vLLM: keep chosen blocks whole on every TP rank to skip their all-reduce on slow links"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "Alberto Massidda" }]
13
+ keywords = ["vllm", "tensor-parallelism", "inference", "llm", "plugin"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Intended Audience :: Science/Research",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
21
+ ]
22
+ dependencies = [] # torch, triton and vllm come from the serving environment
23
+
24
+ [project.optional-dependencies]
25
+ test = ["pytest", "tblib"]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/aijanai/vllm-knapsack-weight-replication"
29
+ Issues = "https://github.com/aijanai/vllm-knapsack-weight-replication/issues"
30
+ RFC = "https://github.com/vllm-project/vllm/issues/66873"
31
+
32
+ [project.entry-points."vllm.general_plugins"]
33
+ knapsack_weight_replication = "vllm_knapsack_weight_replication.plugin:register"
34
+
35
+ [tool.setuptools.dynamic]
36
+ version = { attr = "vllm_knapsack_weight_replication.__version__" }
37
+
38
+ [tool.setuptools.packages.find]
39
+ where = ["src"]
40
+
41
+ [tool.ruff]
42
+ line-length = 88
43
+ # Copied unchanged from the vLLM pull requests (vLLM's own ruff settings).
44
+ extend-exclude = [
45
+ "src/vllm_knapsack_weight_replication/tp_synced_autotune.py",
46
+ "src/vllm_knapsack_weight_replication/canonical_topk.py",
47
+ "src/vllm_knapsack_weight_replication/models/qwen3_5_replicate.py",
48
+ "tests/test_tp_synced_autotune.py",
49
+ "tests/test_canonical_topk.py",
50
+ "tests/test_qwen3_5_replicate_ffn.py",
51
+ "tests/test_dsa_replicate_routing.py",
52
+ "tests/test_minimax_m3_replicate_attn.py",
53
+ "src/vllm_knapsack_weight_replication/upstream",
54
+ # Research scripts copied from the benchmark kit (not shipped in the wheel).
55
+ "tools/offline_planner",
56
+ ]
57
+
58
+ [tool.ruff.lint]
59
+ select = ["E", "F", "I", "UP"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+ """TP block replication for vLLM, packaged as a general plugin."""
4
+
5
+ __version__ = "0.5.0"
@@ -0,0 +1,82 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+ """The switches, under the same names as the vLLM pull requests.
4
+
5
+ They are added to `vllm.envs.environment_variables`, so `vllm.envs.<NAME>` works in
6
+ the patched code and moving to a vLLM that ships them needs no configuration change.
7
+ """
8
+
9
+ import os
10
+ from collections.abc import Callable
11
+ from typing import Any
12
+
13
+
14
+ def _flag(name: str) -> Callable[[], bool]:
15
+ return lambda: os.getenv(name, "0").strip().lower() in ("1", "true")
16
+
17
+
18
+ FLAGS: dict[str, Callable[[], Any]] = {
19
+ # vllm-project/vllm#66526: every TP rank adopts rank 0's Triton autotune choice.
20
+ "VLLM_TRITON_SYNC_AUTOTUNE_TP": _flag("VLLM_TRITON_SYNC_AUTOTUNE_TP"),
21
+ # vllm-project/vllm#67044: canonical (deterministic) sparse-indexer top-k.
22
+ "VLLM_DETERMINISTIC_SPARSE_TOPK": _flag("VLLM_DETERMINISTIC_SPARSE_TOPK"),
23
+ # vllm-project/vllm#67285: dense Qwen3.5 keeps every MLP whole on each TP rank.
24
+ "VLLM_KNAPSACK_QWEN3_5_FFN": _flag("VLLM_KNAPSACK_QWEN3_5_FFN"),
25
+ # vllm-project/vllm#66867: DSA models (DeepSeek-V3.2, GLM-5.x) keep every
26
+ # sparse-MLA layer whole on each TP rank; MoE/MLP stay tensor-parallel.
27
+ "VLLM_KNAPSACK_DSA_ATTN": _flag("VLLM_KNAPSACK_DSA_ATTN"),
28
+ # With VLLM_KNAPSACK_DSA_ATTN, steps with fewer tokens than this run the
29
+ # attention head-sharded on slices of the replicated weights, then all-reduce.
30
+ "VLLM_KNAPSACK_DSA_ATTN_MIN_TOKENS": lambda: int(
31
+ os.getenv("VLLM_KNAPSACK_DSA_ATTN_MIN_TOKENS", "0")
32
+ ),
33
+ # vllm-project/vllm#66869: DeepSeek-V4.1 keeps every attention layer whole on
34
+ # each TP rank; MoE stays tensor-parallel.
35
+ "VLLM_KNAPSACK_DSV41_MIXER": _flag("VLLM_KNAPSACK_DSV41_MIXER"),
36
+ # vllm-project/vllm#66378: MiniMax-M3 keeps every attention layer whole on each
37
+ # TP rank; MoE stays tensor-parallel.
38
+ "VLLM_KNAPSACK_MINIMAX_M3_ATTN": _flag("VLLM_KNAPSACK_MINIMAX_M3_ATTN"),
39
+ # Per-layer replication (online planner, DSA models so far): "auto" picks the
40
+ # layers from the probe and the memory budget; "kind:0-3,7;..." names them.
41
+ # Unset: the per-model switches above apply.
42
+ "VLLM_KNAPSACK_PLAN": lambda: os.getenv("VLLM_KNAPSACK_PLAN", ""),
43
+ # `vllm serve` first runs the probe unless a result for the same arguments
44
+ # exists (single node). The result is the JSON the "auto" plan reads.
45
+ "VLLM_KNAPSACK_PROBE": lambda: bool(int(os.getenv("VLLM_KNAPSACK_PROBE", "0"))),
46
+ "VLLM_KNAPSACK_PROBE_RESULT": lambda: os.getenv("VLLM_KNAPSACK_PROBE_RESULT", ""),
47
+ # Load the "auto" plan sizes memory and weighs gains for: sessions whose KV
48
+ # stays resident, tokens per session (0: max_model_len), decode batch, a
49
+ # typical request's new prompt and output tokens, and the mean accepted
50
+ # draft tokens per verify step. Without sessions, a fixed budget in GiB.
51
+ "VLLM_KNAPSACK_SESSIONS": lambda: int(os.getenv("VLLM_KNAPSACK_SESSIONS", "0")),
52
+ "VLLM_KNAPSACK_SESSION_TOKENS": lambda: int(
53
+ os.getenv("VLLM_KNAPSACK_SESSION_TOKENS", "0")
54
+ ),
55
+ "VLLM_KNAPSACK_DECODE_BS": lambda: int(os.getenv("VLLM_KNAPSACK_DECODE_BS", "1")),
56
+ "VLLM_KNAPSACK_ISL": lambda: int(os.getenv("VLLM_KNAPSACK_ISL", "0")),
57
+ "VLLM_KNAPSACK_OSL": lambda: int(os.getenv("VLLM_KNAPSACK_OSL", "0")),
58
+ "VLLM_KNAPSACK_SPEC_ACCEPT": lambda: float(
59
+ os.getenv("VLLM_KNAPSACK_SPEC_ACCEPT", "0")
60
+ ),
61
+ "VLLM_KNAPSACK_BUDGET_GIB": lambda: float(
62
+ os.getenv("VLLM_KNAPSACK_BUDGET_GIB", "0")
63
+ ),
64
+ # Host RAM per rank for idle sessions' KV (e.g. vLLM's KV offloading).
65
+ "VLLM_KNAPSACK_KV_OFFLOAD_GIB": lambda: float(
66
+ os.getenv("VLLM_KNAPSACK_KV_OFFLOAD_GIB", "0")
67
+ ),
68
+ }
69
+
70
+
71
+ def get(name: str) -> Any:
72
+ return FLAGS[name]()
73
+
74
+
75
+ def register() -> list[str]:
76
+ """Add the flags vLLM does not define yet; return the names vLLM already had."""
77
+ import vllm.envs as envs
78
+
79
+ shipped = [n for n in FLAGS if n in envs.environment_variables]
80
+ for name, read in FLAGS.items():
81
+ envs.environment_variables.setdefault(name, read)
82
+ return shipped