vllm-cpu-amxbf16 0.9.1__cp312-cp312-manylinux_2_17_x86_64.whl

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 (1197) hide show
  1. vllm/_C.abi3.so +0 -0
  2. vllm/__init__.py +53 -0
  3. vllm/_custom_ops.py +1828 -0
  4. vllm/_ipex_ops.py +244 -0
  5. vllm/_version.py +34 -0
  6. vllm/adapter_commons/__init__.py +0 -0
  7. vllm/adapter_commons/layers.py +16 -0
  8. vllm/adapter_commons/models.py +106 -0
  9. vllm/adapter_commons/request.py +26 -0
  10. vllm/adapter_commons/utils.py +93 -0
  11. vllm/adapter_commons/worker_manager.py +39 -0
  12. vllm/assets/__init__.py +0 -0
  13. vllm/assets/audio.py +45 -0
  14. vllm/assets/base.py +41 -0
  15. vllm/assets/image.py +34 -0
  16. vllm/assets/video.py +115 -0
  17. vllm/attention/__init__.py +20 -0
  18. vllm/attention/backends/__init__.py +0 -0
  19. vllm/attention/backends/abstract.py +308 -0
  20. vllm/attention/backends/blocksparse_attn.py +461 -0
  21. vllm/attention/backends/cpu_mla.py +307 -0
  22. vllm/attention/backends/dual_chunk_flash_attn.py +1498 -0
  23. vllm/attention/backends/flash_attn.py +1003 -0
  24. vllm/attention/backends/flashinfer.py +1104 -0
  25. vllm/attention/backends/flashmla.py +244 -0
  26. vllm/attention/backends/hpu_attn.py +313 -0
  27. vllm/attention/backends/ipex_attn.py +398 -0
  28. vllm/attention/backends/mla/__init__.py +0 -0
  29. vllm/attention/backends/mla/common.py +1385 -0
  30. vllm/attention/backends/pallas.py +351 -0
  31. vllm/attention/backends/placeholder_attn.py +400 -0
  32. vllm/attention/backends/rocm_aiter_mla.py +435 -0
  33. vllm/attention/backends/rocm_flash_attn.py +975 -0
  34. vllm/attention/backends/torch_sdpa.py +703 -0
  35. vllm/attention/backends/triton_mla.py +115 -0
  36. vllm/attention/backends/utils.py +610 -0
  37. vllm/attention/backends/xformers.py +802 -0
  38. vllm/attention/layer.py +468 -0
  39. vllm/attention/ops/__init__.py +0 -0
  40. vllm/attention/ops/blocksparse_attention/__init__.py +0 -0
  41. vllm/attention/ops/blocksparse_attention/blocksparse_attention_kernel.py +433 -0
  42. vllm/attention/ops/blocksparse_attention/interface.py +239 -0
  43. vllm/attention/ops/blocksparse_attention/utils.py +246 -0
  44. vllm/attention/ops/chunked_prefill_paged_decode.py +368 -0
  45. vllm/attention/ops/flashmla.py +116 -0
  46. vllm/attention/ops/hpu_paged_attn.py +88 -0
  47. vllm/attention/ops/ipex_attn.py +195 -0
  48. vllm/attention/ops/merge_attn_states.py +43 -0
  49. vllm/attention/ops/nki_flash_attn.py +906 -0
  50. vllm/attention/ops/paged_attn.py +256 -0
  51. vllm/attention/ops/prefix_prefill.py +902 -0
  52. vllm/attention/ops/rocm_aiter_mla.py +100 -0
  53. vllm/attention/ops/rocm_aiter_paged_attn.py +102 -0
  54. vllm/attention/ops/triton_decode_attention.py +674 -0
  55. vllm/attention/ops/triton_flash_attention.py +979 -0
  56. vllm/attention/ops/triton_merge_attn_states.py +97 -0
  57. vllm/attention/ops/triton_unified_attention.py +334 -0
  58. vllm/attention/selector.py +187 -0
  59. vllm/attention/utils/fa_utils.py +55 -0
  60. vllm/beam_search.py +87 -0
  61. vllm/benchmarks/__init__.py +0 -0
  62. vllm/benchmarks/datasets.py +1185 -0
  63. vllm/benchmarks/endpoint_request_func.py +381 -0
  64. vllm/benchmarks/latency.py +168 -0
  65. vllm/benchmarks/serve.py +1135 -0
  66. vllm/benchmarks/throughput.py +609 -0
  67. vllm/benchmarks/utils.py +70 -0
  68. vllm/collect_env.py +820 -0
  69. vllm/compilation/__init__.py +0 -0
  70. vllm/compilation/activation_quant_fusion.py +89 -0
  71. vllm/compilation/backends.py +563 -0
  72. vllm/compilation/base_piecewise_backend.py +72 -0
  73. vllm/compilation/collective_fusion.py +127 -0
  74. vllm/compilation/compiler_interface.py +544 -0
  75. vllm/compilation/counter.py +38 -0
  76. vllm/compilation/cuda_piecewise_backend.py +214 -0
  77. vllm/compilation/decorators.py +250 -0
  78. vllm/compilation/fix_functionalization.py +191 -0
  79. vllm/compilation/fusion.py +618 -0
  80. vllm/compilation/fx_utils.py +62 -0
  81. vllm/compilation/inductor_pass.py +115 -0
  82. vllm/compilation/monitor.py +39 -0
  83. vllm/compilation/multi_output_match.py +109 -0
  84. vllm/compilation/noop_elimination.py +137 -0
  85. vllm/compilation/pass_manager.py +78 -0
  86. vllm/compilation/sequence_parallelism.py +268 -0
  87. vllm/compilation/torch25_custom_graph_pass.py +42 -0
  88. vllm/compilation/vllm_inductor_pass.py +67 -0
  89. vllm/compilation/wrapper.py +135 -0
  90. vllm/config.py +4746 -0
  91. vllm/connections.py +174 -0
  92. vllm/core/__init__.py +0 -0
  93. vllm/core/block/__init__.py +0 -0
  94. vllm/core/block/block_table.py +399 -0
  95. vllm/core/block/common.py +371 -0
  96. vllm/core/block/cpu_gpu_block_allocator.py +441 -0
  97. vllm/core/block/interfaces.py +319 -0
  98. vllm/core/block/naive_block.py +466 -0
  99. vllm/core/block/prefix_caching_block.py +1135 -0
  100. vllm/core/block/utils.py +28 -0
  101. vllm/core/block_manager.py +521 -0
  102. vllm/core/evictor.py +157 -0
  103. vllm/core/interfaces.py +135 -0
  104. vllm/core/placeholder_block_space_manager.py +100 -0
  105. vllm/core/scheduler.py +2093 -0
  106. vllm/device_allocator/__init__.py +0 -0
  107. vllm/device_allocator/cumem.py +281 -0
  108. vllm/distributed/__init__.py +6 -0
  109. vllm/distributed/communication_op.py +41 -0
  110. vllm/distributed/device_communicators/__init__.py +0 -0
  111. vllm/distributed/device_communicators/all2all.py +264 -0
  112. vllm/distributed/device_communicators/base_device_communicator.py +260 -0
  113. vllm/distributed/device_communicators/cpu_communicator.py +145 -0
  114. vllm/distributed/device_communicators/cuda_communicator.py +176 -0
  115. vllm/distributed/device_communicators/cuda_wrapper.py +180 -0
  116. vllm/distributed/device_communicators/custom_all_reduce.py +304 -0
  117. vllm/distributed/device_communicators/custom_all_reduce_utils.py +259 -0
  118. vllm/distributed/device_communicators/hpu_communicator.py +46 -0
  119. vllm/distributed/device_communicators/neuron_communicator.py +20 -0
  120. vllm/distributed/device_communicators/pynccl.py +218 -0
  121. vllm/distributed/device_communicators/pynccl_wrapper.py +341 -0
  122. vllm/distributed/device_communicators/shm_broadcast.py +585 -0
  123. vllm/distributed/device_communicators/tpu_communicator.py +103 -0
  124. vllm/distributed/device_communicators/xpu_communicator.py +55 -0
  125. vllm/distributed/kv_events.py +356 -0
  126. vllm/distributed/kv_transfer/README.md +29 -0
  127. vllm/distributed/kv_transfer/__init__.py +12 -0
  128. vllm/distributed/kv_transfer/disagg_prefill_workflow.jpg +0 -0
  129. vllm/distributed/kv_transfer/kv_connector/__init__.py +0 -0
  130. vllm/distributed/kv_transfer/kv_connector/base.py +128 -0
  131. vllm/distributed/kv_transfer/kv_connector/factory.py +128 -0
  132. vllm/distributed/kv_transfer/kv_connector/lmcache_connector.py +99 -0
  133. vllm/distributed/kv_transfer/kv_connector/mooncake_store_connector.py +203 -0
  134. vllm/distributed/kv_transfer/kv_connector/simple_connector.py +329 -0
  135. vllm/distributed/kv_transfer/kv_connector/utils.py +108 -0
  136. vllm/distributed/kv_transfer/kv_connector/v1/__init__.py +6 -0
  137. vllm/distributed/kv_transfer/kv_connector/v1/base.py +283 -0
  138. vllm/distributed/kv_transfer/kv_connector/v1/lmcache_connector.py +134 -0
  139. vllm/distributed/kv_transfer/kv_connector/v1/multi_connector.py +201 -0
  140. vllm/distributed/kv_transfer/kv_connector/v1/nixl_connector.py +1030 -0
  141. vllm/distributed/kv_transfer/kv_connector/v1/shared_storage_connector.py +384 -0
  142. vllm/distributed/kv_transfer/kv_connector_agent.py +77 -0
  143. vllm/distributed/kv_transfer/kv_lookup_buffer/__init__.py +0 -0
  144. vllm/distributed/kv_transfer/kv_lookup_buffer/base.py +175 -0
  145. vllm/distributed/kv_transfer/kv_lookup_buffer/mooncake_store.py +161 -0
  146. vllm/distributed/kv_transfer/kv_lookup_buffer/simple_buffer.py +237 -0
  147. vllm/distributed/kv_transfer/kv_pipe/__init__.py +0 -0
  148. vllm/distributed/kv_transfer/kv_pipe/base.py +67 -0
  149. vllm/distributed/kv_transfer/kv_pipe/mooncake_pipe.py +280 -0
  150. vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py +280 -0
  151. vllm/distributed/kv_transfer/kv_transfer_state.py +71 -0
  152. vllm/distributed/parallel_state.py +1296 -0
  153. vllm/distributed/tpu_distributed_utils.py +177 -0
  154. vllm/distributed/utils.py +536 -0
  155. vllm/engine/__init__.py +0 -0
  156. vllm/engine/arg_utils.py +1708 -0
  157. vllm/engine/async_llm_engine.py +1200 -0
  158. vllm/engine/async_timeout.py +173 -0
  159. vllm/engine/llm_engine.py +2097 -0
  160. vllm/engine/metrics.py +629 -0
  161. vllm/engine/metrics_types.py +94 -0
  162. vllm/engine/multiprocessing/__init__.py +148 -0
  163. vllm/engine/multiprocessing/client.py +681 -0
  164. vllm/engine/multiprocessing/engine.py +460 -0
  165. vllm/engine/output_processor/__init__.py +0 -0
  166. vllm/engine/output_processor/interfaces.py +75 -0
  167. vllm/engine/output_processor/multi_step.py +216 -0
  168. vllm/engine/output_processor/single_step.py +145 -0
  169. vllm/engine/output_processor/stop_checker.py +131 -0
  170. vllm/engine/output_processor/util.py +28 -0
  171. vllm/engine/protocol.py +317 -0
  172. vllm/entrypoints/__init__.py +0 -0
  173. vllm/entrypoints/api_server.py +178 -0
  174. vllm/entrypoints/chat_utils.py +1299 -0
  175. vllm/entrypoints/cli/__init__.py +0 -0
  176. vllm/entrypoints/cli/benchmark/__init__.py +0 -0
  177. vllm/entrypoints/cli/benchmark/base.py +39 -0
  178. vllm/entrypoints/cli/benchmark/latency.py +30 -0
  179. vllm/entrypoints/cli/benchmark/main.py +54 -0
  180. vllm/entrypoints/cli/benchmark/serve.py +30 -0
  181. vllm/entrypoints/cli/benchmark/throughput.py +30 -0
  182. vllm/entrypoints/cli/collect_env.py +35 -0
  183. vllm/entrypoints/cli/main.py +65 -0
  184. vllm/entrypoints/cli/openai.py +205 -0
  185. vllm/entrypoints/cli/run_batch.py +62 -0
  186. vllm/entrypoints/cli/serve.py +328 -0
  187. vllm/entrypoints/cli/types.py +25 -0
  188. vllm/entrypoints/launcher.py +147 -0
  189. vllm/entrypoints/llm.py +1544 -0
  190. vllm/entrypoints/logger.py +50 -0
  191. vllm/entrypoints/openai/__init__.py +0 -0
  192. vllm/entrypoints/openai/api_server.py +1387 -0
  193. vllm/entrypoints/openai/cli_args.py +315 -0
  194. vllm/entrypoints/openai/logits_processors.py +90 -0
  195. vllm/entrypoints/openai/protocol.py +1913 -0
  196. vllm/entrypoints/openai/run_batch.py +463 -0
  197. vllm/entrypoints/openai/serving_chat.py +1221 -0
  198. vllm/entrypoints/openai/serving_classification.py +160 -0
  199. vllm/entrypoints/openai/serving_completion.py +592 -0
  200. vllm/entrypoints/openai/serving_embedding.py +201 -0
  201. vllm/entrypoints/openai/serving_engine.py +986 -0
  202. vllm/entrypoints/openai/serving_models.py +315 -0
  203. vllm/entrypoints/openai/serving_pooling.py +232 -0
  204. vllm/entrypoints/openai/serving_score.py +433 -0
  205. vllm/entrypoints/openai/serving_tokenization.py +157 -0
  206. vllm/entrypoints/openai/serving_transcription.py +424 -0
  207. vllm/entrypoints/openai/tool_parsers/__init__.py +23 -0
  208. vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py +164 -0
  209. vllm/entrypoints/openai/tool_parsers/deepseekv3_tool_parser.py +370 -0
  210. vllm/entrypoints/openai/tool_parsers/granite_20b_fc_tool_parser.py +259 -0
  211. vllm/entrypoints/openai/tool_parsers/granite_tool_parser.py +237 -0
  212. vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py +371 -0
  213. vllm/entrypoints/openai/tool_parsers/internlm2_tool_parser.py +216 -0
  214. vllm/entrypoints/openai/tool_parsers/jamba_tool_parser.py +308 -0
  215. vllm/entrypoints/openai/tool_parsers/llama4_pythonic_tool_parser.py +316 -0
  216. vllm/entrypoints/openai/tool_parsers/llama_tool_parser.py +267 -0
  217. vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py +369 -0
  218. vllm/entrypoints/openai/tool_parsers/phi4mini_tool_parser.py +112 -0
  219. vllm/entrypoints/openai/tool_parsers/pythonic_tool_parser.py +308 -0
  220. vllm/entrypoints/openai/tool_parsers/utils.py +124 -0
  221. vllm/entrypoints/score_utils.py +50 -0
  222. vllm/entrypoints/ssl.py +75 -0
  223. vllm/entrypoints/utils.py +233 -0
  224. vllm/env_override.py +41 -0
  225. vllm/envs.py +944 -0
  226. vllm/executor/__init__.py +0 -0
  227. vllm/executor/executor_base.py +401 -0
  228. vllm/executor/mp_distributed_executor.py +244 -0
  229. vllm/executor/msgspec_utils.py +30 -0
  230. vllm/executor/multiproc_worker_utils.py +313 -0
  231. vllm/executor/ray_distributed_executor.py +701 -0
  232. vllm/executor/ray_utils.py +399 -0
  233. vllm/executor/uniproc_executor.py +139 -0
  234. vllm/forward_context.py +179 -0
  235. vllm/inputs/__init__.py +41 -0
  236. vllm/inputs/data.py +331 -0
  237. vllm/inputs/parse.py +151 -0
  238. vllm/inputs/preprocess.py +909 -0
  239. vllm/inputs/registry.py +237 -0
  240. vllm/jsontree.py +80 -0
  241. vllm/logger.py +212 -0
  242. vllm/logging_utils/__init__.py +8 -0
  243. vllm/logging_utils/dump_input.py +85 -0
  244. vllm/logging_utils/formatter.py +18 -0
  245. vllm/logits_process.py +119 -0
  246. vllm/lora/__init__.py +0 -0
  247. vllm/lora/fully_sharded_layers.py +355 -0
  248. vllm/lora/layers.py +1285 -0
  249. vllm/lora/lora.py +199 -0
  250. vllm/lora/models.py +818 -0
  251. vllm/lora/ops/__init__.py +0 -0
  252. vllm/lora/ops/torch_ops/__init__.py +16 -0
  253. vllm/lora/ops/torch_ops/lora_ops.py +119 -0
  254. vllm/lora/ops/triton_ops/__init__.py +12 -0
  255. vllm/lora/ops/triton_ops/kernel_utils.py +243 -0
  256. vllm/lora/ops/triton_ops/lora_expand_op.py +290 -0
  257. vllm/lora/ops/triton_ops/lora_kernel_metadata.py +148 -0
  258. vllm/lora/ops/triton_ops/lora_shrink_op.py +244 -0
  259. vllm/lora/ops/triton_ops/utils.py +120 -0
  260. vllm/lora/ops/xla_ops/__init__.py +7 -0
  261. vllm/lora/ops/xla_ops/lora_ops.py +145 -0
  262. vllm/lora/peft_helper.py +136 -0
  263. vllm/lora/punica_wrapper/__init__.py +10 -0
  264. vllm/lora/punica_wrapper/punica_base.py +485 -0
  265. vllm/lora/punica_wrapper/punica_cpu.py +349 -0
  266. vllm/lora/punica_wrapper/punica_gpu.py +290 -0
  267. vllm/lora/punica_wrapper/punica_hpu.py +145 -0
  268. vllm/lora/punica_wrapper/punica_selector.py +20 -0
  269. vllm/lora/punica_wrapper/punica_tpu.py +405 -0
  270. vllm/lora/punica_wrapper/utils.py +164 -0
  271. vllm/lora/request.py +99 -0
  272. vllm/lora/resolver.py +85 -0
  273. vllm/lora/utils.py +240 -0
  274. vllm/lora/worker_manager.py +259 -0
  275. vllm/model_executor/__init__.py +16 -0
  276. vllm/model_executor/custom_op.py +152 -0
  277. vllm/model_executor/guided_decoding/__init__.py +181 -0
  278. vllm/model_executor/guided_decoding/guidance_decoding.py +63 -0
  279. vllm/model_executor/guided_decoding/guidance_logits_processors.py +104 -0
  280. vllm/model_executor/guided_decoding/guided_fields.py +41 -0
  281. vllm/model_executor/guided_decoding/lm_format_enforcer_decoding.py +67 -0
  282. vllm/model_executor/guided_decoding/outlines_decoding.py +155 -0
  283. vllm/model_executor/guided_decoding/outlines_logits_processors.py +284 -0
  284. vllm/model_executor/guided_decoding/utils.py +242 -0
  285. vllm/model_executor/guided_decoding/xgrammar_decoding.py +426 -0
  286. vllm/model_executor/layers/__init__.py +0 -0
  287. vllm/model_executor/layers/activation.py +369 -0
  288. vllm/model_executor/layers/fused_moe/__init__.py +54 -0
  289. vllm/model_executor/layers/fused_moe/batched_deep_gemm_moe.py +125 -0
  290. vllm/model_executor/layers/fused_moe/batched_triton_or_deep_gemm_moe.py +117 -0
  291. vllm/model_executor/layers/fused_moe/configs/E=1,N=14336,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  292. vllm/model_executor/layers/fused_moe/configs/E=1,N=14336,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  293. vllm/model_executor/layers/fused_moe/configs/E=1,N=1792,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  294. vllm/model_executor/layers/fused_moe/configs/E=1,N=1792,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  295. vllm/model_executor/layers/fused_moe/configs/E=1,N=3072,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  296. vllm/model_executor/layers/fused_moe/configs/E=1,N=3072,device_name=NVIDIA_H100_80GB_HBM3,dtype=int8_w8a16.json +218 -0
  297. vllm/model_executor/layers/fused_moe/configs/E=1,N=3072,device_name=NVIDIA_H100_80GB_HBM3.json +218 -0
  298. vllm/model_executor/layers/fused_moe/configs/E=1,N=3584,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  299. vllm/model_executor/layers/fused_moe/configs/E=1,N=3584,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  300. vllm/model_executor/layers/fused_moe/configs/E=1,N=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  301. vllm/model_executor/layers/fused_moe/configs/E=1,N=7168,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  302. vllm/model_executor/layers/fused_moe/configs/E=128,N=1024,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  303. vllm/model_executor/layers/fused_moe/configs/E=128,N=1024,device_name=AMD_Instinct_MI300X.json +200 -0
  304. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  305. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  306. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_H20-3e.json +146 -0
  307. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_H20.json +146 -0
  308. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_H200.json +146 -0
  309. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  310. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  311. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=NVIDIA_H20-3e.json +146 -0
  312. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=NVIDIA_H20.json +146 -0
  313. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  314. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=NVIDIA_H200.json +146 -0
  315. vllm/model_executor/layers/fused_moe/configs/E=128,N=512,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  316. vllm/model_executor/layers/fused_moe/configs/E=128,N=768,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  317. vllm/model_executor/layers/fused_moe/configs/E=128,N=768,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  318. vllm/model_executor/layers/fused_moe/configs/E=128,N=768,device_name=NVIDIA_H20.json +146 -0
  319. vllm/model_executor/layers/fused_moe/configs/E=128,N=768,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  320. vllm/model_executor/layers/fused_moe/configs/E=128,N=768,device_name=NVIDIA_H200.json +146 -0
  321. vllm/model_executor/layers/fused_moe/configs/E=128,N=96,device_name=NVIDIA_H20.json +146 -0
  322. vllm/model_executor/layers/fused_moe/configs/E=16,N=1024,device_name=AMD_Instinct_MI300X.json +200 -0
  323. vllm/model_executor/layers/fused_moe/configs/E=16,N=1024,device_name=NVIDIA_H100.json +146 -0
  324. vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
  325. vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  326. vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  327. vllm/model_executor/layers/fused_moe/configs/E=16,N=14336,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  328. vllm/model_executor/layers/fused_moe/configs/E=16,N=14336,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  329. vllm/model_executor/layers/fused_moe/configs/E=16,N=1792,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  330. vllm/model_executor/layers/fused_moe/configs/E=16,N=1792,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  331. vllm/model_executor/layers/fused_moe/configs/E=16,N=2688,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  332. vllm/model_executor/layers/fused_moe/configs/E=16,N=2688,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  333. vllm/model_executor/layers/fused_moe/configs/E=16,N=3072,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  334. vllm/model_executor/layers/fused_moe/configs/E=16,N=3072,device_name=NVIDIA_H100_80GB_HBM3,dtype=int8_w8a16.json +146 -0
  335. vllm/model_executor/layers/fused_moe/configs/E=16,N=3200,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +130 -0
  336. vllm/model_executor/layers/fused_moe/configs/E=16,N=3584,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  337. vllm/model_executor/layers/fused_moe/configs/E=16,N=3584,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  338. vllm/model_executor/layers/fused_moe/configs/E=16,N=6400,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +130 -0
  339. vllm/model_executor/layers/fused_moe/configs/E=16,N=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  340. vllm/model_executor/layers/fused_moe/configs/E=16,N=7168,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  341. vllm/model_executor/layers/fused_moe/configs/E=16,N=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=int8_w8a16.json +146 -0
  342. vllm/model_executor/layers/fused_moe/configs/E=16,N=800,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +130 -0
  343. vllm/model_executor/layers/fused_moe/configs/E=160,N=192,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  344. vllm/model_executor/layers/fused_moe/configs/E=256,N=1024,device_name=AMD_Instinct_MI325X,block_shape=[128,128].json +200 -0
  345. vllm/model_executor/layers/fused_moe/configs/E=256,N=1024,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +200 -0
  346. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  347. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8.json +146 -0
  348. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  349. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8.json +146 -0
  350. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  351. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  352. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  353. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  354. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +200 -0
  355. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +200 -0
  356. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  357. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  358. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  359. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=NVIDIA_H20-3e,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  360. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  361. vllm/model_executor/layers/fused_moe/configs/E=256,N=256,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  362. vllm/model_executor/layers/fused_moe/configs/E=256,N=512,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +200 -0
  363. vllm/model_executor/layers/fused_moe/configs/E=256,N=64,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  364. vllm/model_executor/layers/fused_moe/configs/E=60,N=1408,device_name=AMD_Instinct_MI300X.json +200 -0
  365. vllm/model_executor/layers/fused_moe/configs/E=60,N=176,device_name=AMD_Instinct_MI300X.json +200 -0
  366. vllm/model_executor/layers/fused_moe/configs/E=60,N=352,device_name=AMD_Instinct_MI300X.json +200 -0
  367. vllm/model_executor/layers/fused_moe/configs/E=60,N=704,device_name=AMD_Instinct_MI300X.json +200 -0
  368. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  369. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  370. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  371. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  372. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  373. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H200.json +146 -0
  374. vllm/model_executor/layers/fused_moe/configs/E=64,N=2560,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  375. vllm/model_executor/layers/fused_moe/configs/E=64,N=2560,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  376. vllm/model_executor/layers/fused_moe/configs/E=64,N=2560,device_name=NVIDIA_H200.json +146 -0
  377. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  378. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  379. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  380. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H200.json +146 -0
  381. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  382. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  383. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_GeForce_RTX_4090,dtype=fp8_w8a8.json +146 -0
  384. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  385. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  386. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  387. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H200.json +146 -0
  388. vllm/model_executor/layers/fused_moe/configs/E=64,N=896,device_name=NVIDIA_H20.json +146 -0
  389. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  390. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI300X.json +200 -0
  391. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  392. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI325X.json +200 -0
  393. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +138 -0
  394. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  395. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=NVIDIA_H200.json +146 -0
  396. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  397. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI300X.json +200 -0
  398. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  399. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI325X.json +200 -0
  400. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  401. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI300X.json +200 -0
  402. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  403. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI325X.json +200 -0
  404. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
  405. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  406. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  407. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  408. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_H200.json +146 -0
  409. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  410. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI300X.json +200 -0
  411. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  412. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI325X.json +200 -0
  413. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  414. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  415. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  416. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  417. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H200.json +146 -0
  418. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  419. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI300X.json +200 -0
  420. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  421. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI325X.json +200 -0
  422. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
  423. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  424. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_GeForce_RTX_4090,dtype=fp8_w8a8.json +146 -0
  425. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  426. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  427. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  428. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H200.json +146 -0
  429. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_L40S.json +173 -0
  430. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  431. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI300X.json +200 -0
  432. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  433. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI325X.json +200 -0
  434. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  435. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  436. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  437. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  438. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H200.json +146 -0
  439. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  440. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI300X.json +200 -0
  441. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  442. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI325X.json +200 -0
  443. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  444. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  445. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  446. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  447. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H200.json +146 -0
  448. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  449. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI300X.json +200 -0
  450. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  451. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI325X.json +200 -0
  452. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  453. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  454. vllm/model_executor/layers/fused_moe/configs/README +12 -0
  455. vllm/model_executor/layers/fused_moe/cutlass_moe.py +461 -0
  456. vllm/model_executor/layers/fused_moe/deep_gemm_moe.py +240 -0
  457. vllm/model_executor/layers/fused_moe/deepep_ht_prepare_finalize.py +240 -0
  458. vllm/model_executor/layers/fused_moe/deepep_ll_prepare_finalize.py +186 -0
  459. vllm/model_executor/layers/fused_moe/fused_batched_moe.py +775 -0
  460. vllm/model_executor/layers/fused_moe/fused_marlin_moe.py +232 -0
  461. vllm/model_executor/layers/fused_moe/fused_moe.py +1724 -0
  462. vllm/model_executor/layers/fused_moe/layer.py +1535 -0
  463. vllm/model_executor/layers/fused_moe/modular_kernel.py +446 -0
  464. vllm/model_executor/layers/fused_moe/moe_align_block_size.py +243 -0
  465. vllm/model_executor/layers/fused_moe/moe_pallas.py +80 -0
  466. vllm/model_executor/layers/fused_moe/moe_permute_unpermute.py +190 -0
  467. vllm/model_executor/layers/fused_moe/moe_torch_iterative.py +60 -0
  468. vllm/model_executor/layers/fused_moe/pplx_prepare_finalize.py +159 -0
  469. vllm/model_executor/layers/fused_moe/prepare_finalize.py +69 -0
  470. vllm/model_executor/layers/fused_moe/rocm_aiter_fused_moe.py +421 -0
  471. vllm/model_executor/layers/fused_moe/triton_deep_gemm_moe.py +117 -0
  472. vllm/model_executor/layers/fused_moe/utils.py +98 -0
  473. vllm/model_executor/layers/layernorm.py +288 -0
  474. vllm/model_executor/layers/lightning_attn.py +652 -0
  475. vllm/model_executor/layers/linear.py +1524 -0
  476. vllm/model_executor/layers/logits_processor.py +197 -0
  477. vllm/model_executor/layers/mamba/__init__.py +0 -0
  478. vllm/model_executor/layers/mamba/mamba2_metadata.py +125 -0
  479. vllm/model_executor/layers/mamba/mamba_mixer.py +245 -0
  480. vllm/model_executor/layers/mamba/mamba_mixer2.py +616 -0
  481. vllm/model_executor/layers/mamba/ops/__init__.py +0 -0
  482. vllm/model_executor/layers/mamba/ops/causal_conv1d.py +105 -0
  483. vllm/model_executor/layers/mamba/ops/mamba_ssm.py +414 -0
  484. vllm/model_executor/layers/mamba/ops/ssd_bmm.py +262 -0
  485. vllm/model_executor/layers/mamba/ops/ssd_chunk_scan.py +589 -0
  486. vllm/model_executor/layers/mamba/ops/ssd_chunk_state.py +751 -0
  487. vllm/model_executor/layers/mamba/ops/ssd_combined.py +232 -0
  488. vllm/model_executor/layers/mamba/ops/ssd_state_passing.py +206 -0
  489. vllm/model_executor/layers/pooler.py +350 -0
  490. vllm/model_executor/layers/quantization/__init__.py +157 -0
  491. vllm/model_executor/layers/quantization/aqlm.py +376 -0
  492. vllm/model_executor/layers/quantization/auto_round.py +310 -0
  493. vllm/model_executor/layers/quantization/awq.py +194 -0
  494. vllm/model_executor/layers/quantization/awq_marlin.py +519 -0
  495. vllm/model_executor/layers/quantization/awq_triton.py +320 -0
  496. vllm/model_executor/layers/quantization/base_config.py +151 -0
  497. vllm/model_executor/layers/quantization/bitblas.py +461 -0
  498. vllm/model_executor/layers/quantization/bitsandbytes.py +396 -0
  499. vllm/model_executor/layers/quantization/compressed_tensors/__init__.py +0 -0
  500. vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py +668 -0
  501. vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors_moe.py +1260 -0
  502. vllm/model_executor/layers/quantization/compressed_tensors/schemes/__init__.py +24 -0
  503. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_24.py +358 -0
  504. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_scheme.py +55 -0
  505. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w4a16_24.py +160 -0
  506. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w4a16_nvfp4.py +93 -0
  507. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w4a4_nvfp4.py +178 -0
  508. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a16_fp8.py +121 -0
  509. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a8_fp8.py +150 -0
  510. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a8_int8.py +111 -0
  511. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa16.py +201 -0
  512. vllm/model_executor/layers/quantization/compressed_tensors/triton_scaled_mm.py +206 -0
  513. vllm/model_executor/layers/quantization/compressed_tensors/utils.py +216 -0
  514. vllm/model_executor/layers/quantization/deepspeedfp.py +195 -0
  515. vllm/model_executor/layers/quantization/experts_int8.py +196 -0
  516. vllm/model_executor/layers/quantization/fbgemm_fp8.py +172 -0
  517. vllm/model_executor/layers/quantization/fp8.py +906 -0
  518. vllm/model_executor/layers/quantization/gguf.py +565 -0
  519. vllm/model_executor/layers/quantization/gptq.py +278 -0
  520. vllm/model_executor/layers/quantization/gptq_bitblas.py +445 -0
  521. vllm/model_executor/layers/quantization/gptq_marlin.py +648 -0
  522. vllm/model_executor/layers/quantization/gptq_marlin_24.py +297 -0
  523. vllm/model_executor/layers/quantization/hqq_marlin.py +332 -0
  524. vllm/model_executor/layers/quantization/ipex_quant.py +250 -0
  525. vllm/model_executor/layers/quantization/kernels/__init__.py +0 -0
  526. vllm/model_executor/layers/quantization/kernels/mixed_precision/MPLinearKernel.py +90 -0
  527. vllm/model_executor/layers/quantization/kernels/mixed_precision/__init__.py +83 -0
  528. vllm/model_executor/layers/quantization/kernels/mixed_precision/allspark.py +116 -0
  529. vllm/model_executor/layers/quantization/kernels/mixed_precision/bitblas.py +300 -0
  530. vllm/model_executor/layers/quantization/kernels/mixed_precision/exllama.py +143 -0
  531. vllm/model_executor/layers/quantization/kernels/mixed_precision/machete.py +120 -0
  532. vllm/model_executor/layers/quantization/kernels/mixed_precision/marlin.py +131 -0
  533. vllm/model_executor/layers/quantization/kernels/scaled_mm/ScaledMMLinearKernel.py +67 -0
  534. vllm/model_executor/layers/quantization/kernels/scaled_mm/__init__.py +87 -0
  535. vllm/model_executor/layers/quantization/kernels/scaled_mm/aiter.py +120 -0
  536. vllm/model_executor/layers/quantization/kernels/scaled_mm/cutlass.py +137 -0
  537. vllm/model_executor/layers/quantization/kernels/scaled_mm/triton.py +41 -0
  538. vllm/model_executor/layers/quantization/kernels/scaled_mm/xla.py +105 -0
  539. vllm/model_executor/layers/quantization/kv_cache.py +139 -0
  540. vllm/model_executor/layers/quantization/marlin.py +261 -0
  541. vllm/model_executor/layers/quantization/modelopt.py +737 -0
  542. vllm/model_executor/layers/quantization/moe_wna16.py +449 -0
  543. vllm/model_executor/layers/quantization/neuron_quant.py +76 -0
  544. vllm/model_executor/layers/quantization/ptpc_fp8.py +127 -0
  545. vllm/model_executor/layers/quantization/qqq.py +275 -0
  546. vllm/model_executor/layers/quantization/quark/__init__.py +0 -0
  547. vllm/model_executor/layers/quantization/quark/quark.py +441 -0
  548. vllm/model_executor/layers/quantization/quark/quark_moe.py +237 -0
  549. vllm/model_executor/layers/quantization/quark/schemes/__init__.py +9 -0
  550. vllm/model_executor/layers/quantization/quark/schemes/quark_scheme.py +55 -0
  551. vllm/model_executor/layers/quantization/quark/schemes/quark_w4a4_mxfp4.py +126 -0
  552. vllm/model_executor/layers/quantization/quark/schemes/quark_w8a8_fp8.py +146 -0
  553. vllm/model_executor/layers/quantization/quark/schemes/quark_w8a8_int8.py +122 -0
  554. vllm/model_executor/layers/quantization/quark/utils.py +105 -0
  555. vllm/model_executor/layers/quantization/schema.py +86 -0
  556. vllm/model_executor/layers/quantization/torchao.py +161 -0
  557. vllm/model_executor/layers/quantization/tpu_int8.py +121 -0
  558. vllm/model_executor/layers/quantization/utils/__init__.py +6 -0
  559. vllm/model_executor/layers/quantization/utils/allspark_utils.py +52 -0
  560. vllm/model_executor/layers/quantization/utils/bitblas_utils.py +208 -0
  561. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  562. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  563. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  564. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  565. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  566. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  567. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  568. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=1536,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  569. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  570. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  571. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  572. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  573. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  574. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  575. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  576. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  577. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  578. vllm/model_executor/layers/quantization/utils/configs/N=1536,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  579. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  580. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  581. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  582. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  583. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  584. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  585. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  586. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  587. vllm/model_executor/layers/quantization/utils/configs/N=2048,K=512,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  588. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  589. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  590. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  591. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  592. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  593. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  594. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  595. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  596. vllm/model_executor/layers/quantization/utils/configs/N=2304,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  597. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  598. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  599. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  600. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  601. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  602. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  603. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  604. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  605. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  606. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  607. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  608. vllm/model_executor/layers/quantization/utils/configs/N=24576,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  609. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  610. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  611. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  612. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  613. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  614. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  615. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  616. vllm/model_executor/layers/quantization/utils/configs/N=256,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  617. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=1536,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  618. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=1536,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  619. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=1536,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  620. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=1536,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  621. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=1536,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  622. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=1536,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  623. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=1536,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  624. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  625. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  626. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  627. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  628. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  629. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  630. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  631. vllm/model_executor/layers/quantization/utils/configs/N=3072,K=7168,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  632. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  633. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  634. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  635. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  636. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  637. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  638. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  639. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  640. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  641. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  642. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  643. vllm/model_executor/layers/quantization/utils/configs/N=32768,K=512,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  644. vllm/model_executor/layers/quantization/utils/configs/N=36864,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  645. vllm/model_executor/layers/quantization/utils/configs/N=36864,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  646. vllm/model_executor/layers/quantization/utils/configs/N=36864,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  647. vllm/model_executor/layers/quantization/utils/configs/N=36864,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  648. vllm/model_executor/layers/quantization/utils/configs/N=36864,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  649. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  650. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  651. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  652. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  653. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  654. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  655. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  656. vllm/model_executor/layers/quantization/utils/configs/N=4096,K=512,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  657. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  658. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  659. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  660. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  661. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  662. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  663. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  664. vllm/model_executor/layers/quantization/utils/configs/N=4608,K=7168,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  665. vllm/model_executor/layers/quantization/utils/configs/N=512,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  666. vllm/model_executor/layers/quantization/utils/configs/N=512,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  667. vllm/model_executor/layers/quantization/utils/configs/N=512,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  668. vllm/model_executor/layers/quantization/utils/configs/N=512,K=7168,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  669. vllm/model_executor/layers/quantization/utils/configs/N=512,K=7168,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  670. vllm/model_executor/layers/quantization/utils/configs/N=512,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  671. vllm/model_executor/layers/quantization/utils/configs/N=512,K=7168,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  672. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  673. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  674. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  675. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  676. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  677. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  678. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  679. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  680. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  681. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  682. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +18 -0
  683. vllm/model_executor/layers/quantization/utils/configs/N=576,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  684. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  685. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  686. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  687. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  688. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  689. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  690. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  691. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  692. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1024,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  693. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  694. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  695. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  696. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  697. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  698. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  699. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  700. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  701. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=1152,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  702. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  703. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  704. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  705. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  706. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  707. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  708. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  709. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=128,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  710. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  711. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  712. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  713. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  714. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  715. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  716. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  717. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  718. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  719. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  720. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  721. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=16384,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  722. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  723. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  724. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  725. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  726. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  727. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  728. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  729. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_H20,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  730. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  731. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  732. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  733. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=18432,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  734. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  735. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  736. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  737. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  738. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  739. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  740. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  741. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2048,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  742. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  743. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  744. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  745. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  746. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  747. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  748. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  749. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=2304,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  750. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=256,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  751. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=256,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  752. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=256,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  753. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=256,device_name=NVIDIA_B200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  754. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=256,device_name=NVIDIA_H20,dtype=int8_w8a8,block_shape=[128,128].json +146 -0
  755. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=256,device_name=NVIDIA_H200,dtype=fp8_w8a8,block_shape=[128,128].json +146 -0
  756. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=256,device_name=NVIDIA_L20,dtype=fp8_w8a8,block_shape=[128,128].json +26 -0
  757. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=8192,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  758. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=8192,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  759. vllm/model_executor/layers/quantization/utils/configs/N=7168,K=8192,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  760. vllm/model_executor/layers/quantization/utils/configs/N=8192,K=1536,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  761. vllm/model_executor/layers/quantization/utils/configs/N=8192,K=1536,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  762. vllm/model_executor/layers/quantization/utils/configs/N=8192,K=1536,device_name=AMD_Instinct_MI325_OAM,dtype=fp8_w8a8,block_shape=[128,128].json +164 -0
  763. vllm/model_executor/layers/quantization/utils/fp8_utils.py +618 -0
  764. vllm/model_executor/layers/quantization/utils/gptq_utils.py +95 -0
  765. vllm/model_executor/layers/quantization/utils/int8_utils.py +485 -0
  766. vllm/model_executor/layers/quantization/utils/layer_utils.py +40 -0
  767. vllm/model_executor/layers/quantization/utils/machete_utils.py +33 -0
  768. vllm/model_executor/layers/quantization/utils/marlin_utils.py +476 -0
  769. vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py +283 -0
  770. vllm/model_executor/layers/quantization/utils/marlin_utils_fp8.py +325 -0
  771. vllm/model_executor/layers/quantization/utils/marlin_utils_test.py +165 -0
  772. vllm/model_executor/layers/quantization/utils/marlin_utils_test_24.py +464 -0
  773. vllm/model_executor/layers/quantization/utils/marlin_utils_test_qqq.py +126 -0
  774. vllm/model_executor/layers/quantization/utils/mxfp4_utils.py +45 -0
  775. vllm/model_executor/layers/quantization/utils/nvfp4_emulation_utils.py +104 -0
  776. vllm/model_executor/layers/quantization/utils/quant_utils.py +573 -0
  777. vllm/model_executor/layers/quantization/utils/w8a8_utils.py +405 -0
  778. vllm/model_executor/layers/rejection_sampler.py +406 -0
  779. vllm/model_executor/layers/resampler.py +270 -0
  780. vllm/model_executor/layers/rotary_embedding.py +1862 -0
  781. vllm/model_executor/layers/sampler.py +1204 -0
  782. vllm/model_executor/layers/spec_decode_base_sampler.py +259 -0
  783. vllm/model_executor/layers/typical_acceptance_sampler.py +166 -0
  784. vllm/model_executor/layers/utils.py +95 -0
  785. vllm/model_executor/layers/vocab_parallel_embedding.py +487 -0
  786. vllm/model_executor/model_loader/__init__.py +76 -0
  787. vllm/model_executor/model_loader/base_loader.py +43 -0
  788. vllm/model_executor/model_loader/bitsandbytes_loader.py +570 -0
  789. vllm/model_executor/model_loader/default_loader.py +282 -0
  790. vllm/model_executor/model_loader/dummy_loader.py +27 -0
  791. vllm/model_executor/model_loader/gguf_loader.py +120 -0
  792. vllm/model_executor/model_loader/neuron.py +476 -0
  793. vllm/model_executor/model_loader/neuronx_distributed.py +685 -0
  794. vllm/model_executor/model_loader/runai_streamer_loader.py +109 -0
  795. vllm/model_executor/model_loader/sharded_state_loader.py +201 -0
  796. vllm/model_executor/model_loader/tensorizer.py +600 -0
  797. vllm/model_executor/model_loader/tensorizer_loader.py +123 -0
  798. vllm/model_executor/model_loader/tpu.py +112 -0
  799. vllm/model_executor/model_loader/utils.py +302 -0
  800. vllm/model_executor/model_loader/weight_utils.py +782 -0
  801. vllm/model_executor/models/__init__.py +28 -0
  802. vllm/model_executor/models/adapters.py +248 -0
  803. vllm/model_executor/models/aimv2.py +246 -0
  804. vllm/model_executor/models/arctic.py +559 -0
  805. vllm/model_executor/models/aria.py +657 -0
  806. vllm/model_executor/models/aya_vision.py +466 -0
  807. vllm/model_executor/models/baichuan.py +474 -0
  808. vllm/model_executor/models/bamba.py +543 -0
  809. vllm/model_executor/models/bart.py +938 -0
  810. vllm/model_executor/models/bert.py +523 -0
  811. vllm/model_executor/models/bert_with_rope.py +769 -0
  812. vllm/model_executor/models/blip.py +339 -0
  813. vllm/model_executor/models/blip2.py +718 -0
  814. vllm/model_executor/models/bloom.py +373 -0
  815. vllm/model_executor/models/chameleon.py +1136 -0
  816. vllm/model_executor/models/chatglm.py +478 -0
  817. vllm/model_executor/models/clip.py +407 -0
  818. vllm/model_executor/models/commandr.py +472 -0
  819. vllm/model_executor/models/constant_size_cache.py +137 -0
  820. vllm/model_executor/models/dbrx.py +472 -0
  821. vllm/model_executor/models/deepseek.py +486 -0
  822. vllm/model_executor/models/deepseek_mtp.py +269 -0
  823. vllm/model_executor/models/deepseek_v2.py +843 -0
  824. vllm/model_executor/models/deepseek_vl2.py +648 -0
  825. vllm/model_executor/models/eagle.py +260 -0
  826. vllm/model_executor/models/exaone.py +551 -0
  827. vllm/model_executor/models/fairseq2_llama.py +154 -0
  828. vllm/model_executor/models/falcon.py +510 -0
  829. vllm/model_executor/models/falcon_h1.py +685 -0
  830. vllm/model_executor/models/florence2.py +1103 -0
  831. vllm/model_executor/models/fuyu.py +389 -0
  832. vllm/model_executor/models/gemma.py +425 -0
  833. vllm/model_executor/models/gemma2.py +425 -0
  834. vllm/model_executor/models/gemma3.py +533 -0
  835. vllm/model_executor/models/gemma3_mm.py +709 -0
  836. vllm/model_executor/models/glm.py +23 -0
  837. vllm/model_executor/models/glm4.py +305 -0
  838. vllm/model_executor/models/glm4v.py +648 -0
  839. vllm/model_executor/models/gpt2.py +328 -0
  840. vllm/model_executor/models/gpt_bigcode.py +335 -0
  841. vllm/model_executor/models/gpt_j.py +339 -0
  842. vllm/model_executor/models/gpt_neox.py +332 -0
  843. vllm/model_executor/models/granite.py +493 -0
  844. vllm/model_executor/models/granite_speech.py +779 -0
  845. vllm/model_executor/models/granitemoe.py +437 -0
  846. vllm/model_executor/models/granitemoehybrid.py +586 -0
  847. vllm/model_executor/models/granitemoeshared.py +341 -0
  848. vllm/model_executor/models/gritlm.py +224 -0
  849. vllm/model_executor/models/grok1.py +546 -0
  850. vllm/model_executor/models/h2ovl.py +546 -0
  851. vllm/model_executor/models/idefics2_vision_model.py +389 -0
  852. vllm/model_executor/models/idefics3.py +776 -0
  853. vllm/model_executor/models/interfaces.py +572 -0
  854. vllm/model_executor/models/interfaces_base.py +164 -0
  855. vllm/model_executor/models/intern_vit.py +480 -0
  856. vllm/model_executor/models/internlm2.py +455 -0
  857. vllm/model_executor/models/internlm2_ve.py +147 -0
  858. vllm/model_executor/models/internvl.py +1418 -0
  859. vllm/model_executor/models/jais.py +373 -0
  860. vllm/model_executor/models/jamba.py +592 -0
  861. vllm/model_executor/models/kimi_vl.py +577 -0
  862. vllm/model_executor/models/llama.py +644 -0
  863. vllm/model_executor/models/llama4.py +532 -0
  864. vllm/model_executor/models/llama_eagle.py +165 -0
  865. vllm/model_executor/models/llama_eagle3.py +263 -0
  866. vllm/model_executor/models/llava.py +866 -0
  867. vllm/model_executor/models/llava_next.py +586 -0
  868. vllm/model_executor/models/llava_next_video.py +471 -0
  869. vllm/model_executor/models/llava_onevision.py +956 -0
  870. vllm/model_executor/models/mamba.py +273 -0
  871. vllm/model_executor/models/mamba2.py +308 -0
  872. vllm/model_executor/models/mamba_cache.py +76 -0
  873. vllm/model_executor/models/medusa.py +219 -0
  874. vllm/model_executor/models/mimo.py +192 -0
  875. vllm/model_executor/models/mimo_mtp.py +285 -0
  876. vllm/model_executor/models/minicpm.py +592 -0
  877. vllm/model_executor/models/minicpm3.py +230 -0
  878. vllm/model_executor/models/minicpm_eagle.py +391 -0
  879. vllm/model_executor/models/minicpmo.py +759 -0
  880. vllm/model_executor/models/minicpmv.py +1287 -0
  881. vllm/model_executor/models/minimax_cache.py +36 -0
  882. vllm/model_executor/models/minimax_text_01.py +1301 -0
  883. vllm/model_executor/models/minimax_vl_01.py +364 -0
  884. vllm/model_executor/models/mistral3.py +604 -0
  885. vllm/model_executor/models/mixtral.py +488 -0
  886. vllm/model_executor/models/mixtral_quant.py +453 -0
  887. vllm/model_executor/models/mllama.py +1624 -0
  888. vllm/model_executor/models/mllama4.py +938 -0
  889. vllm/model_executor/models/mlp_speculator.py +206 -0
  890. vllm/model_executor/models/modernbert.py +331 -0
  891. vllm/model_executor/models/module_mapping.py +72 -0
  892. vllm/model_executor/models/molmo.py +1568 -0
  893. vllm/model_executor/models/moonvit.py +630 -0
  894. vllm/model_executor/models/mpt.py +331 -0
  895. vllm/model_executor/models/nemotron.py +508 -0
  896. vllm/model_executor/models/nemotron_h.py +573 -0
  897. vllm/model_executor/models/nemotron_nas.py +484 -0
  898. vllm/model_executor/models/nvlm_d.py +216 -0
  899. vllm/model_executor/models/olmo.py +389 -0
  900. vllm/model_executor/models/olmo2.py +414 -0
  901. vllm/model_executor/models/olmoe.py +468 -0
  902. vllm/model_executor/models/opt.py +412 -0
  903. vllm/model_executor/models/orion.py +349 -0
  904. vllm/model_executor/models/ovis.py +567 -0
  905. vllm/model_executor/models/paligemma.py +398 -0
  906. vllm/model_executor/models/persimmon.py +344 -0
  907. vllm/model_executor/models/phi.py +356 -0
  908. vllm/model_executor/models/phi3.py +19 -0
  909. vllm/model_executor/models/phi3_small.py +465 -0
  910. vllm/model_executor/models/phi3v.py +723 -0
  911. vllm/model_executor/models/phi4mm.py +1246 -0
  912. vllm/model_executor/models/phi4mm_audio.py +1233 -0
  913. vllm/model_executor/models/phi4mm_utils.py +1884 -0
  914. vllm/model_executor/models/phimoe.py +665 -0
  915. vllm/model_executor/models/pixtral.py +1316 -0
  916. vllm/model_executor/models/plamo2.py +738 -0
  917. vllm/model_executor/models/prithvi_geospatial_mae.py +232 -0
  918. vllm/model_executor/models/qwen.py +362 -0
  919. vllm/model_executor/models/qwen2.py +497 -0
  920. vllm/model_executor/models/qwen2_5_omni_thinker.py +904 -0
  921. vllm/model_executor/models/qwen2_5_vl.py +1166 -0
  922. vllm/model_executor/models/qwen2_audio.py +410 -0
  923. vllm/model_executor/models/qwen2_moe.py +540 -0
  924. vllm/model_executor/models/qwen2_rm.py +132 -0
  925. vllm/model_executor/models/qwen2_vl.py +1405 -0
  926. vllm/model_executor/models/qwen3.py +321 -0
  927. vllm/model_executor/models/qwen3_moe.py +535 -0
  928. vllm/model_executor/models/qwen_vl.py +785 -0
  929. vllm/model_executor/models/registry.py +622 -0
  930. vllm/model_executor/models/roberta.py +276 -0
  931. vllm/model_executor/models/siglip.py +524 -0
  932. vllm/model_executor/models/skyworkr1v.py +951 -0
  933. vllm/model_executor/models/smolvlm.py +52 -0
  934. vllm/model_executor/models/solar.py +506 -0
  935. vllm/model_executor/models/stablelm.py +343 -0
  936. vllm/model_executor/models/starcoder2.py +356 -0
  937. vllm/model_executor/models/tarsier.py +643 -0
  938. vllm/model_executor/models/telechat2.py +140 -0
  939. vllm/model_executor/models/teleflm.py +79 -0
  940. vllm/model_executor/models/transformers.py +508 -0
  941. vllm/model_executor/models/ultravox.py +656 -0
  942. vllm/model_executor/models/utils.py +731 -0
  943. vllm/model_executor/models/vision.py +147 -0
  944. vllm/model_executor/models/whisper.py +747 -0
  945. vllm/model_executor/models/zamba2.py +1009 -0
  946. vllm/model_executor/parameter.py +459 -0
  947. vllm/model_executor/pooling_metadata.py +72 -0
  948. vllm/model_executor/sampling_metadata.py +597 -0
  949. vllm/model_executor/utils.py +77 -0
  950. vllm/multimodal/__init__.py +33 -0
  951. vllm/multimodal/audio.py +106 -0
  952. vllm/multimodal/base.py +219 -0
  953. vllm/multimodal/hasher.py +118 -0
  954. vllm/multimodal/image.py +97 -0
  955. vllm/multimodal/inputs.py +876 -0
  956. vllm/multimodal/parse.py +461 -0
  957. vllm/multimodal/processing.py +1895 -0
  958. vllm/multimodal/profiling.py +258 -0
  959. vllm/multimodal/registry.py +331 -0
  960. vllm/multimodal/utils.py +436 -0
  961. vllm/multimodal/video.py +198 -0
  962. vllm/outputs.py +512 -0
  963. vllm/platforms/__init__.py +291 -0
  964. vllm/platforms/cpu.py +266 -0
  965. vllm/platforms/cuda.py +526 -0
  966. vllm/platforms/hpu.py +106 -0
  967. vllm/platforms/interface.py +538 -0
  968. vllm/platforms/neuron.py +150 -0
  969. vllm/platforms/rocm.py +435 -0
  970. vllm/platforms/tpu.py +216 -0
  971. vllm/platforms/xpu.py +156 -0
  972. vllm/plugins/__init__.py +94 -0
  973. vllm/plugins/lora_resolvers/README.md +15 -0
  974. vllm/plugins/lora_resolvers/__init__.py +0 -0
  975. vllm/plugins/lora_resolvers/filesystem_resolver.py +50 -0
  976. vllm/pooling_params.py +54 -0
  977. vllm/profiler/__init__.py +0 -0
  978. vllm/profiler/layerwise_profile.py +375 -0
  979. vllm/profiler/utils.py +148 -0
  980. vllm/prompt_adapter/__init__.py +0 -0
  981. vllm/prompt_adapter/layers.py +83 -0
  982. vllm/prompt_adapter/models.py +358 -0
  983. vllm/prompt_adapter/request.py +37 -0
  984. vllm/prompt_adapter/utils.py +98 -0
  985. vllm/prompt_adapter/worker_manager.py +179 -0
  986. vllm/py.typed +2 -0
  987. vllm/reasoning/__init__.py +15 -0
  988. vllm/reasoning/abs_reasoning_parsers.py +192 -0
  989. vllm/reasoning/deepseek_r1_reasoning_parser.py +173 -0
  990. vllm/reasoning/granite_reasoning_parser.py +363 -0
  991. vllm/reasoning/qwen3_reasoning_parser.py +151 -0
  992. vllm/sampling_params.py +602 -0
  993. vllm/scalar_type.py +347 -0
  994. vllm/scripts.py +15 -0
  995. vllm/sequence.py +1568 -0
  996. vllm/spec_decode/__init__.py +0 -0
  997. vllm/spec_decode/batch_expansion.py +506 -0
  998. vllm/spec_decode/draft_model_runner.py +349 -0
  999. vllm/spec_decode/interfaces.py +99 -0
  1000. vllm/spec_decode/medusa_worker.py +138 -0
  1001. vllm/spec_decode/metrics.py +213 -0
  1002. vllm/spec_decode/mlp_speculator_worker.py +94 -0
  1003. vllm/spec_decode/mqa_scorer.py +160 -0
  1004. vllm/spec_decode/multi_step_worker.py +423 -0
  1005. vllm/spec_decode/ngram_worker.py +196 -0
  1006. vllm/spec_decode/proposer_worker_base.py +59 -0
  1007. vllm/spec_decode/smaller_tp_proposer_worker.py +196 -0
  1008. vllm/spec_decode/spec_decode_worker.py +1326 -0
  1009. vllm/spec_decode/target_model_runner.py +45 -0
  1010. vllm/spec_decode/top1_proposer.py +275 -0
  1011. vllm/spec_decode/util.py +277 -0
  1012. vllm/test_utils.py +130 -0
  1013. vllm/third_party/__init__.py +0 -0
  1014. vllm/third_party/pynvml.py +6140 -0
  1015. vllm/tracing.py +131 -0
  1016. vllm/transformers_utils/__init__.py +24 -0
  1017. vllm/transformers_utils/chat_templates/__init__.py +5 -0
  1018. vllm/transformers_utils/chat_templates/registry.py +60 -0
  1019. vllm/transformers_utils/chat_templates/template_basic.jinja +3 -0
  1020. vllm/transformers_utils/chat_templates/template_blip2.jinja +11 -0
  1021. vllm/transformers_utils/chat_templates/template_chatml.jinja +10 -0
  1022. vllm/transformers_utils/chat_templates/template_deepseek_vl2.jinja +23 -0
  1023. vllm/transformers_utils/chat_templates/template_fuyu.jinja +3 -0
  1024. vllm/transformers_utils/config.py +887 -0
  1025. vllm/transformers_utils/configs/__init__.py +61 -0
  1026. vllm/transformers_utils/configs/arctic.py +207 -0
  1027. vllm/transformers_utils/configs/chatglm.py +72 -0
  1028. vllm/transformers_utils/configs/cohere2.py +195 -0
  1029. vllm/transformers_utils/configs/dbrx.py +280 -0
  1030. vllm/transformers_utils/configs/deepseek_vl2.py +216 -0
  1031. vllm/transformers_utils/configs/eagle.py +85 -0
  1032. vllm/transformers_utils/configs/exaone.py +190 -0
  1033. vllm/transformers_utils/configs/falcon.py +90 -0
  1034. vllm/transformers_utils/configs/h2ovl.py +16 -0
  1035. vllm/transformers_utils/configs/internvl.py +54 -0
  1036. vllm/transformers_utils/configs/jais.py +238 -0
  1037. vllm/transformers_utils/configs/kimi_vl.py +37 -0
  1038. vllm/transformers_utils/configs/medusa.py +63 -0
  1039. vllm/transformers_utils/configs/minimax_text_01.py +70 -0
  1040. vllm/transformers_utils/configs/minimax_vl_01.py +71 -0
  1041. vllm/transformers_utils/configs/mllama.py +31 -0
  1042. vllm/transformers_utils/configs/mlp_speculator.py +68 -0
  1043. vllm/transformers_utils/configs/moonvit.py +33 -0
  1044. vllm/transformers_utils/configs/mpt.py +180 -0
  1045. vllm/transformers_utils/configs/nemotron.py +205 -0
  1046. vllm/transformers_utils/configs/nemotron_h.py +258 -0
  1047. vllm/transformers_utils/configs/nvlm_d.py +15 -0
  1048. vllm/transformers_utils/configs/ovis.py +184 -0
  1049. vllm/transformers_utils/configs/skyworkr1v.py +54 -0
  1050. vllm/transformers_utils/configs/solar.py +247 -0
  1051. vllm/transformers_utils/configs/telechat2.py +64 -0
  1052. vllm/transformers_utils/configs/ultravox.py +108 -0
  1053. vllm/transformers_utils/detokenizer.py +168 -0
  1054. vllm/transformers_utils/detokenizer_utils.py +189 -0
  1055. vllm/transformers_utils/processor.py +221 -0
  1056. vllm/transformers_utils/processors/__init__.py +8 -0
  1057. vllm/transformers_utils/processors/deepseek_vl2.py +363 -0
  1058. vllm/transformers_utils/processors/ovis.py +420 -0
  1059. vllm/transformers_utils/s3_utils.py +162 -0
  1060. vllm/transformers_utils/tokenizer.py +302 -0
  1061. vllm/transformers_utils/tokenizer_base.py +149 -0
  1062. vllm/transformers_utils/tokenizer_group.py +120 -0
  1063. vllm/transformers_utils/tokenizers/__init__.py +10 -0
  1064. vllm/transformers_utils/tokenizers/mistral.py +493 -0
  1065. vllm/transformers_utils/utils.py +99 -0
  1066. vllm/triton_utils/__init__.py +14 -0
  1067. vllm/triton_utils/importing.py +50 -0
  1068. vllm/usage/__init__.py +0 -0
  1069. vllm/usage/usage_lib.py +256 -0
  1070. vllm/utils.py +2910 -0
  1071. vllm/v1/__init__.py +0 -0
  1072. vllm/v1/attention/__init__.py +0 -0
  1073. vllm/v1/attention/backends/__init__.py +0 -0
  1074. vllm/v1/attention/backends/cpu_attn.py +163 -0
  1075. vllm/v1/attention/backends/flash_attn.py +869 -0
  1076. vllm/v1/attention/backends/flashinfer.py +651 -0
  1077. vllm/v1/attention/backends/flex_attention.py +477 -0
  1078. vllm/v1/attention/backends/mla/__init__.py +0 -0
  1079. vllm/v1/attention/backends/mla/common.py +931 -0
  1080. vllm/v1/attention/backends/mla/cutlass_mla.py +97 -0
  1081. vllm/v1/attention/backends/mla/flashmla.py +152 -0
  1082. vllm/v1/attention/backends/mla/rocm_aiter_mla.py +220 -0
  1083. vllm/v1/attention/backends/mla/triton_mla.py +120 -0
  1084. vllm/v1/attention/backends/pallas.py +240 -0
  1085. vllm/v1/attention/backends/triton_attn.py +285 -0
  1086. vllm/v1/attention/backends/utils.py +52 -0
  1087. vllm/v1/core/__init__.py +0 -0
  1088. vllm/v1/core/block_pool.py +349 -0
  1089. vllm/v1/core/encoder_cache_manager.py +150 -0
  1090. vllm/v1/core/kv_cache_coordinator.py +363 -0
  1091. vllm/v1/core/kv_cache_manager.py +392 -0
  1092. vllm/v1/core/kv_cache_utils.py +996 -0
  1093. vllm/v1/core/sched/__init__.py +0 -0
  1094. vllm/v1/core/sched/interface.py +150 -0
  1095. vllm/v1/core/sched/output.py +154 -0
  1096. vllm/v1/core/sched/scheduler.py +1044 -0
  1097. vllm/v1/core/sched/utils.py +23 -0
  1098. vllm/v1/core/single_type_kv_cache_manager.py +403 -0
  1099. vllm/v1/engine/__init__.py +173 -0
  1100. vllm/v1/engine/async_llm.py +558 -0
  1101. vllm/v1/engine/coordinator.py +253 -0
  1102. vllm/v1/engine/core.py +961 -0
  1103. vllm/v1/engine/core_client.py +1129 -0
  1104. vllm/v1/engine/detokenizer.py +261 -0
  1105. vllm/v1/engine/exceptions.py +17 -0
  1106. vllm/v1/engine/llm_engine.py +317 -0
  1107. vllm/v1/engine/logprobs.py +199 -0
  1108. vllm/v1/engine/mm_input_cache.py +91 -0
  1109. vllm/v1/engine/output_processor.py +428 -0
  1110. vllm/v1/engine/parallel_sampling.py +133 -0
  1111. vllm/v1/engine/processor.py +407 -0
  1112. vllm/v1/executor/__init__.py +0 -0
  1113. vllm/v1/executor/abstract.py +113 -0
  1114. vllm/v1/executor/multiproc_executor.py +537 -0
  1115. vllm/v1/executor/ray_distributed_executor.py +62 -0
  1116. vllm/v1/kv_cache_interface.py +194 -0
  1117. vllm/v1/metrics/__init__.py +0 -0
  1118. vllm/v1/metrics/loggers.py +523 -0
  1119. vllm/v1/metrics/prometheus.py +82 -0
  1120. vllm/v1/metrics/ray_wrappers.py +131 -0
  1121. vllm/v1/metrics/reader.py +246 -0
  1122. vllm/v1/metrics/stats.py +239 -0
  1123. vllm/v1/outputs.py +116 -0
  1124. vllm/v1/request.py +193 -0
  1125. vllm/v1/sample/__init__.py +0 -0
  1126. vllm/v1/sample/metadata.py +44 -0
  1127. vllm/v1/sample/ops/__init__.py +0 -0
  1128. vllm/v1/sample/ops/bad_words.py +39 -0
  1129. vllm/v1/sample/ops/penalties.py +59 -0
  1130. vllm/v1/sample/ops/topk_topp_sampler.py +293 -0
  1131. vllm/v1/sample/rejection_sampler.py +631 -0
  1132. vllm/v1/sample/sampler.py +286 -0
  1133. vllm/v1/sample/tpu/__init__.py +0 -0
  1134. vllm/v1/sample/tpu/metadata.py +124 -0
  1135. vllm/v1/sample/tpu/sampler.py +145 -0
  1136. vllm/v1/serial_utils.py +315 -0
  1137. vllm/v1/spec_decode/__init__.py +0 -0
  1138. vllm/v1/spec_decode/eagle.py +432 -0
  1139. vllm/v1/spec_decode/medusa.py +62 -0
  1140. vllm/v1/spec_decode/metadata.py +62 -0
  1141. vllm/v1/spec_decode/metrics.py +178 -0
  1142. vllm/v1/spec_decode/ngram_proposer.py +132 -0
  1143. vllm/v1/spec_decode/utils.py +46 -0
  1144. vllm/v1/structured_output/__init__.py +222 -0
  1145. vllm/v1/structured_output/backend_guidance.py +245 -0
  1146. vllm/v1/structured_output/backend_types.py +134 -0
  1147. vllm/v1/structured_output/backend_xgrammar.py +318 -0
  1148. vllm/v1/structured_output/request.py +86 -0
  1149. vllm/v1/structured_output/utils.py +175 -0
  1150. vllm/v1/utils.py +743 -0
  1151. vllm/v1/worker/__init__.py +0 -0
  1152. vllm/v1/worker/block_table.py +142 -0
  1153. vllm/v1/worker/cpu_model_runner.py +86 -0
  1154. vllm/v1/worker/cpu_worker.py +152 -0
  1155. vllm/v1/worker/gpu_input_batch.py +681 -0
  1156. vllm/v1/worker/gpu_model_runner.py +2320 -0
  1157. vllm/v1/worker/gpu_worker.py +393 -0
  1158. vllm/v1/worker/lora_model_runner_mixin.py +173 -0
  1159. vllm/v1/worker/tpu_model_runner.py +1673 -0
  1160. vllm/v1/worker/tpu_worker.py +299 -0
  1161. vllm/v1/worker/utils.py +111 -0
  1162. vllm/v1/worker/worker_base.py +65 -0
  1163. vllm/version.py +41 -0
  1164. vllm/vllm_flash_attn/.gitkeep +0 -0
  1165. vllm/worker/__init__.py +0 -0
  1166. vllm/worker/cache_engine.py +145 -0
  1167. vllm/worker/cpu_enc_dec_model_runner.py +326 -0
  1168. vllm/worker/cpu_model_runner.py +671 -0
  1169. vllm/worker/cpu_pooling_model_runner.py +125 -0
  1170. vllm/worker/cpu_worker.py +450 -0
  1171. vllm/worker/enc_dec_model_runner.py +555 -0
  1172. vllm/worker/hpu_model_runner.py +2320 -0
  1173. vllm/worker/hpu_worker.py +484 -0
  1174. vllm/worker/model_runner.py +2178 -0
  1175. vllm/worker/model_runner_base.py +282 -0
  1176. vllm/worker/multi_step_hpu_worker.py +123 -0
  1177. vllm/worker/multi_step_model_runner.py +911 -0
  1178. vllm/worker/multi_step_neuron_model_runner.py +84 -0
  1179. vllm/worker/multi_step_neuronx_distributed_model_runner.py +63 -0
  1180. vllm/worker/multi_step_tpu_worker.py +108 -0
  1181. vllm/worker/multi_step_worker.py +197 -0
  1182. vllm/worker/neuron_model_runner.py +460 -0
  1183. vllm/worker/neuron_worker.py +193 -0
  1184. vllm/worker/neuronx_distributed_model_runner.py +294 -0
  1185. vllm/worker/pooling_model_runner.py +211 -0
  1186. vllm/worker/tpu_model_runner.py +909 -0
  1187. vllm/worker/tpu_worker.py +337 -0
  1188. vllm/worker/utils.py +53 -0
  1189. vllm/worker/worker.py +577 -0
  1190. vllm/worker/worker_base.py +646 -0
  1191. vllm/worker/xpu_model_runner.py +606 -0
  1192. vllm/worker/xpu_worker.py +186 -0
  1193. vllm_cpu_amxbf16-0.9.1.dist-info/METADATA +305 -0
  1194. vllm_cpu_amxbf16-0.9.1.dist-info/RECORD +1197 -0
  1195. vllm_cpu_amxbf16-0.9.1.dist-info/WHEEL +5 -0
  1196. vllm_cpu_amxbf16-0.9.1.dist-info/entry_points.txt +5 -0
  1197. vllm_cpu_amxbf16-0.9.1.dist-info/top_level.txt +1 -0
vllm/utils.py ADDED
@@ -0,0 +1,2910 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+
4
+ from __future__ import annotations
5
+
6
+ import asyncio
7
+ import concurrent
8
+ import contextlib
9
+ import datetime
10
+ import enum
11
+ import gc
12
+ import getpass
13
+ import hashlib
14
+ import importlib
15
+ import importlib.metadata
16
+ import importlib.util
17
+ import inspect
18
+ import ipaddress
19
+ import json
20
+ import multiprocessing
21
+ import os
22
+ import pickle
23
+ import signal
24
+ import socket
25
+ import subprocess
26
+ import sys
27
+ import tempfile
28
+ import textwrap
29
+ import threading
30
+ import time
31
+ import traceback
32
+ import types
33
+ import uuid
34
+ import warnings
35
+ import weakref
36
+ from argparse import (Action, ArgumentDefaultsHelpFormatter, ArgumentParser,
37
+ ArgumentTypeError, RawDescriptionHelpFormatter,
38
+ _ArgumentGroup)
39
+ from asyncio import FIRST_COMPLETED, AbstractEventLoop, Task
40
+ from collections import UserDict, defaultdict
41
+ from collections.abc import (AsyncGenerator, Awaitable, Collection, Generator,
42
+ Hashable, Iterable, Iterator, KeysView, Mapping)
43
+ from concurrent.futures.process import ProcessPoolExecutor
44
+ from dataclasses import dataclass, field
45
+ from functools import cache, lru_cache, partial, wraps
46
+ from types import MappingProxyType
47
+ from typing import (TYPE_CHECKING, Any, Callable, Generic, Literal, NamedTuple,
48
+ Optional, Sequence, Tuple, Type, TypeVar, Union, cast,
49
+ overload)
50
+ from urllib.parse import urlparse
51
+ from uuid import uuid4
52
+
53
+ import cachetools
54
+ import cloudpickle
55
+ import numpy as np
56
+ import numpy.typing as npt
57
+ import psutil
58
+ import regex as re
59
+ import torch
60
+ import torch.types
61
+ import yaml
62
+ import zmq
63
+ import zmq.asyncio
64
+ from packaging import version
65
+ from packaging.version import Version
66
+ from torch.library import Library
67
+ from typing_extensions import Never, ParamSpec, TypeIs, assert_never
68
+
69
+ import vllm.envs as envs
70
+ # NOTE: import triton_utils to make TritonPlaceholderModule work
71
+ # if triton is unavailable
72
+ import vllm.triton_utils # noqa: F401
73
+ from vllm.logger import enable_trace_function_call, init_logger
74
+
75
+ if TYPE_CHECKING:
76
+ from argparse import Namespace
77
+
78
+ from vllm.config import ModelConfig, VllmConfig
79
+
80
+ logger = init_logger(__name__)
81
+
82
+ # This value is chosen to have a balance between ITL and TTFT. Note it is
83
+ # not optimized for throughput.
84
+ DEFAULT_MAX_NUM_BATCHED_TOKENS = 2048
85
+ POOLING_MODEL_MAX_NUM_BATCHED_TOKENS = 32768
86
+ MULTIMODAL_MODEL_MAX_NUM_BATCHED_TOKENS = 5120
87
+
88
+ # Exception strings for non-implemented encoder/decoder scenarios
89
+
90
+ # Reminder: Please update docs/features/compatibility_matrix.md
91
+ # If the feature combo become valid
92
+
93
+ STR_NOT_IMPL_ENC_DEC_SWA = \
94
+ "Sliding window attention for encoder/decoder models " + \
95
+ "is not currently supported."
96
+
97
+ STR_NOT_IMPL_ENC_DEC_PREFIX_CACHE = \
98
+ "Prefix caching for encoder/decoder models " + \
99
+ "is not currently supported."
100
+
101
+ STR_NOT_IMPL_ENC_DEC_CHUNKED_PREFILL = \
102
+ "Chunked prefill for encoder/decoder models " + \
103
+ "is not currently supported."
104
+
105
+ STR_NOT_IMPL_ENC_DEC_LOGIT_SOFTCAP = (
106
+ "Models with logits_soft_cap "
107
+ "require FlashInfer backend, which is "
108
+ "currently not supported for encoder/decoder "
109
+ "models.")
110
+
111
+ STR_NOT_IMPL_ENC_DEC_LORA = ("LoRA is not currently "
112
+ "supported with encoder/decoder "
113
+ "models.")
114
+
115
+ STR_NOT_IMPL_ENC_DEC_PP = ("Pipeline parallelism is not "
116
+ "currently supported with "
117
+ "encoder/decoder models.")
118
+
119
+ STR_NOT_IMPL_ENC_DEC_MM = ("Multimodal is not currently "
120
+ "supported with encoder/decoder "
121
+ "models.")
122
+
123
+ STR_NOT_IMPL_ENC_DEC_SPEC_DEC = ("Speculative decoding is not "
124
+ "currently supported with encoder/"
125
+ "decoder models.")
126
+
127
+ STR_NOT_IMPL_ENC_DEC_BACKEND = ("XFormers and Flash-Attention are the only "
128
+ "backends currently supported with encoder/"
129
+ "decoder models.")
130
+
131
+ STR_NOT_IMPL_ENC_DEC_PROMPT_ADAPTER = ("Prompt adapters are not "
132
+ "currently supported with encoder/"
133
+ "decoder models.")
134
+
135
+ # Efficiently import all enc/dec error strings
136
+ # rather than having to import all of the above
137
+ STR_NOT_IMPL_ENC_DEC_ERR_STRS = {
138
+ "STR_NOT_IMPL_ENC_DEC_SWA": STR_NOT_IMPL_ENC_DEC_SWA,
139
+ "STR_NOT_IMPL_ENC_DEC_PREFIX_CACHE": STR_NOT_IMPL_ENC_DEC_PREFIX_CACHE,
140
+ "STR_NOT_IMPL_ENC_DEC_CHUNKED_PREFILL":
141
+ STR_NOT_IMPL_ENC_DEC_CHUNKED_PREFILL,
142
+ "STR_NOT_IMPL_ENC_DEC_LOGIT_SOFTCAP": STR_NOT_IMPL_ENC_DEC_LOGIT_SOFTCAP,
143
+ "STR_NOT_IMPL_ENC_DEC_LORA": STR_NOT_IMPL_ENC_DEC_LORA,
144
+ "STR_NOT_IMPL_ENC_DEC_PP": STR_NOT_IMPL_ENC_DEC_PP,
145
+ "STR_NOT_IMPL_ENC_DEC_MM": STR_NOT_IMPL_ENC_DEC_MM,
146
+ "STR_NOT_IMPL_ENC_DEC_SPEC_DEC": STR_NOT_IMPL_ENC_DEC_SPEC_DEC,
147
+ "STR_NOT_IMPL_ENC_DEC_BACKEND": STR_NOT_IMPL_ENC_DEC_BACKEND,
148
+ "STR_NOT_IMPL_ENC_DEC_PROMPT_ADAPTER": STR_NOT_IMPL_ENC_DEC_PROMPT_ADAPTER,
149
+ }
150
+
151
+ # Constants related to forcing the attention backend selection
152
+
153
+ # String name of register which may be set in order to
154
+ # force auto-selection of attention backend by Attention
155
+ # wrapper
156
+ STR_BACKEND_ENV_VAR: str = "VLLM_ATTENTION_BACKEND"
157
+
158
+ # Possible string values of STR_BACKEND_ENV_VAR
159
+ # register, corresponding to possible backends
160
+ STR_FLASHINFER_ATTN_VAL: str = "FLASHINFER"
161
+ STR_TORCH_SDPA_ATTN_VAL: str = "TORCH_SDPA"
162
+ STR_ROCM_FLASH_ATTN_VAL: str = "ROCM_FLASH"
163
+ STR_XFORMERS_ATTN_VAL: str = "XFORMERS"
164
+ STR_FLASH_ATTN_VAL: str = "FLASH_ATTN"
165
+ STR_DUAL_CHUNK_FLASH_ATTN_VAL: str = "DUAL_CHUNK_FLASH_ATTN"
166
+ STR_INVALID_VAL: str = "INVALID"
167
+
168
+ GB_bytes = 1_000_000_000
169
+ """The number of bytes in one gigabyte (GB)."""
170
+
171
+ GiB_bytes = 1 << 30
172
+ """The number of bytes in one gibibyte (GiB)."""
173
+
174
+ STR_DTYPE_TO_TORCH_DTYPE = {
175
+ "half": torch.half,
176
+ "bfloat16": torch.bfloat16,
177
+ "float": torch.float,
178
+ "fp8": torch.uint8,
179
+ "fp8_e4m3": torch.uint8,
180
+ "fp8_e5m2": torch.uint8,
181
+ "int8": torch.int8,
182
+ }
183
+
184
+ TORCH_DTYPE_TO_NUMPY_DTYPE = {
185
+ torch.float16: np.float16,
186
+ torch.float32: np.float32,
187
+ torch.float64: np.float64,
188
+ torch.uint8: np.uint8,
189
+ torch.int32: np.int32,
190
+ torch.int64: np.int64,
191
+ }
192
+
193
+ P = ParamSpec('P')
194
+ T = TypeVar("T")
195
+ U = TypeVar("U")
196
+
197
+ _K = TypeVar("_K", bound=Hashable)
198
+ _V = TypeVar("_V")
199
+ _T = TypeVar("_T")
200
+
201
+
202
+ class _Sentinel:
203
+ ...
204
+
205
+
206
+ ALL_PINNED_SENTINEL = _Sentinel()
207
+
208
+
209
+ class Device(enum.Enum):
210
+ GPU = enum.auto()
211
+ CPU = enum.auto()
212
+
213
+
214
+ class LayerBlockType(enum.Enum):
215
+ attention = "attention"
216
+ mamba = "mamba"
217
+
218
+
219
+ class Counter:
220
+
221
+ def __init__(self, start: int = 0) -> None:
222
+ self.counter = start
223
+
224
+ def __next__(self) -> int:
225
+ i = self.counter
226
+ self.counter += 1
227
+ return i
228
+
229
+ def reset(self) -> None:
230
+ self.counter = 0
231
+
232
+
233
+ class _MappingOrderCacheView(UserDict[_K, _V]):
234
+
235
+ def __init__(self, data: Mapping[_K, _V], ordered_keys: Mapping[_K, None]):
236
+ super().__init__(data)
237
+ self.ordered_keys = ordered_keys
238
+
239
+ def __iter__(self) -> Iterator[_K]:
240
+ return iter(self.ordered_keys)
241
+
242
+ def keys(self) -> KeysView[_K]:
243
+ return KeysView(self.ordered_keys)
244
+
245
+
246
+ class CacheInfo(NamedTuple):
247
+ hits: int
248
+ total: int
249
+
250
+ @property
251
+ def hit_ratio(self) -> float:
252
+ if self.total == 0:
253
+ return 0
254
+
255
+ return self.hits / self.total
256
+
257
+ def __sub__(self, other: CacheInfo):
258
+ return CacheInfo(
259
+ hits=self.hits - other.hits,
260
+ total=self.total - other.total,
261
+ )
262
+
263
+
264
+ class LRUCache(cachetools.LRUCache[_K, _V], Generic[_K, _V]):
265
+
266
+ def __init__(self,
267
+ capacity: float,
268
+ getsizeof: Optional[Callable[[_V], float]] = None):
269
+ super().__init__(capacity, getsizeof)
270
+
271
+ self.pinned_items = set[_K]()
272
+
273
+ self._hits = 0
274
+ self._total = 0
275
+ self._last_info = CacheInfo(hits=0, total=0)
276
+
277
+ def __getitem__(self, key: _K, *, update_info: bool = True) -> _V:
278
+ value = super().__getitem__(key)
279
+
280
+ if update_info:
281
+ self._hits += 1
282
+ self._total += 1
283
+
284
+ return value
285
+
286
+ def __delitem__(self, key: _K) -> None:
287
+ run_on_remove = key in self
288
+ value = self.__getitem__(key,
289
+ update_info=False) # type: ignore[call-arg]
290
+ super().__delitem__(key)
291
+ if key in self.pinned_items:
292
+ # Todo: add warning to inform that del pinned item
293
+ self._unpin(key)
294
+ if run_on_remove:
295
+ self._on_remove(key, value)
296
+
297
+ @property
298
+ def cache(self) -> Mapping[_K, _V]:
299
+ """Return the internal cache dictionary in order (read-only)."""
300
+ return _MappingOrderCacheView(
301
+ self._Cache__data, # type: ignore
302
+ self.order)
303
+
304
+ @property
305
+ def order(self) -> Mapping[_K, None]:
306
+ """Return the internal order dictionary (read-only)."""
307
+ return MappingProxyType(self._LRUCache__order) # type: ignore
308
+
309
+ @property
310
+ def capacity(self) -> float:
311
+ return self.maxsize
312
+
313
+ @property
314
+ def usage(self) -> float:
315
+ if self.maxsize == 0:
316
+ return 0
317
+
318
+ return self.currsize / self.maxsize
319
+
320
+ def stat(self, *, delta: bool = False) -> CacheInfo:
321
+ """
322
+ Gets the cumulative number of hits and queries against this cache.
323
+
324
+ If `delta=True`, instead gets these statistics
325
+ since the last call that also passed `delta=True`.
326
+ """
327
+ info = CacheInfo(hits=self._hits, total=self._total)
328
+
329
+ if delta:
330
+ info_delta = info - self._last_info
331
+ self._last_info = info
332
+ info = info_delta
333
+
334
+ return info
335
+
336
+ def touch(self, key: _K) -> None:
337
+ try:
338
+ self._LRUCache__order.move_to_end(key) # type: ignore
339
+ except KeyError:
340
+ self._LRUCache__order[key] = None # type: ignore
341
+
342
+ @overload
343
+ def get(self, key: _K, /) -> Optional[_V]:
344
+ ...
345
+
346
+ @overload
347
+ def get(self, key: _K, /, default: Union[_V, _T]) -> Union[_V, _T]:
348
+ ...
349
+
350
+ def get(self,
351
+ key: _K,
352
+ /,
353
+ default: Optional[Union[_V,
354
+ _T]] = None) -> Optional[Union[_V, _T]]:
355
+ value: Optional[Union[_V, _T]]
356
+ if key in self:
357
+ value = self.__getitem__(
358
+ key, update_info=False) # type: ignore[call-arg]
359
+
360
+ self._hits += 1
361
+ else:
362
+ value = default
363
+
364
+ self._total += 1
365
+ return value
366
+
367
+ @overload
368
+ def pop(self, key: _K) -> _V:
369
+ ...
370
+
371
+ @overload
372
+ def pop(self, key: _K, default: Union[_V, _T]) -> Union[_V, _T]:
373
+ ...
374
+
375
+ def pop(self,
376
+ key: _K,
377
+ default: Optional[Union[_V,
378
+ _T]] = None) -> Optional[Union[_V, _T]]:
379
+ value: Optional[Union[_V, _T]]
380
+ if key not in self:
381
+ return default
382
+
383
+ value = self.__getitem__(key,
384
+ update_info=False) # type: ignore[call-arg]
385
+ self.__delitem__(key)
386
+ return value
387
+
388
+ def put(self, key: _K, value: _V) -> None:
389
+ self.__setitem__(key, value)
390
+
391
+ def pin(self, key: _K) -> None:
392
+ """
393
+ Pins a key in the cache preventing it from being
394
+ evicted in the LRU order.
395
+ """
396
+ if key not in self:
397
+ raise ValueError(f"Cannot pin key: {key} not in cache.")
398
+ self.pinned_items.add(key)
399
+
400
+ def _unpin(self, key: _K) -> None:
401
+ """
402
+ Unpins a key in the cache allowing it to be
403
+ evicted in the LRU order.
404
+ """
405
+ self.pinned_items.remove(key)
406
+
407
+ def _on_remove(self, key: _K, value: Optional[_V]) -> None:
408
+ pass
409
+
410
+ def remove_oldest(self, *, remove_pinned: bool = False) -> None:
411
+ if len(self) == 0:
412
+ return
413
+
414
+ self.popitem(remove_pinned=remove_pinned)
415
+
416
+ def _remove_old_if_needed(self) -> None:
417
+ while self.currsize > self.capacity:
418
+ self.remove_oldest()
419
+
420
+ def popitem(self, remove_pinned: bool = False):
421
+ """Remove and return the `(key, value)` pair least recently used."""
422
+ if not remove_pinned:
423
+ # pop the oldest item in the cache that is not pinned
424
+ lru_key = next(
425
+ (key for key in self.order if key not in self.pinned_items),
426
+ ALL_PINNED_SENTINEL)
427
+ if lru_key is ALL_PINNED_SENTINEL:
428
+ raise RuntimeError("All items are pinned, "
429
+ "cannot remove oldest from the cache.")
430
+ else:
431
+ lru_key = next(iter(self.order))
432
+ value = self.pop(cast(_K, lru_key))
433
+ return (lru_key, value)
434
+
435
+ def clear(self) -> None:
436
+ while len(self) > 0:
437
+ self.remove_oldest(remove_pinned=True)
438
+
439
+ self._hits = 0
440
+ self._total = 0
441
+ self._last_info = CacheInfo(hits=0, total=0)
442
+
443
+
444
+ class PyObjectCache:
445
+ """Used to cache python objects to avoid object allocations
446
+ across scheduler iterations.
447
+ """
448
+
449
+ def __init__(self, obj_builder):
450
+ self._obj_builder = obj_builder
451
+ self._index = 0
452
+
453
+ self._obj_cache = []
454
+ for _ in range(128):
455
+ self._obj_cache.append(self._obj_builder())
456
+
457
+ def _grow_cache(self):
458
+ # Double the size of the cache
459
+ num_objs = len(self._obj_cache)
460
+ for _ in range(num_objs):
461
+ self._obj_cache.append(self._obj_builder())
462
+
463
+ def get_object(self):
464
+ """Returns a pre-allocated cached object. If there is not enough
465
+ objects, then the cache size will double.
466
+ """
467
+ if self._index >= len(self._obj_cache):
468
+ self._grow_cache()
469
+ assert self._index < len(self._obj_cache)
470
+
471
+ obj = self._obj_cache[self._index]
472
+ self._index += 1
473
+
474
+ return obj
475
+
476
+ def reset(self):
477
+ """Makes all cached-objects available for the next scheduler iteration.
478
+ """
479
+ self._index = 0
480
+
481
+
482
+ @cache
483
+ def get_max_shared_memory_bytes(gpu: int = 0) -> int:
484
+ """Returns the maximum shared memory per thread block in bytes."""
485
+ from vllm import _custom_ops as ops
486
+ max_shared_mem = (
487
+ ops.get_max_shared_memory_per_block_device_attribute(gpu))
488
+ # value 0 will cause MAX_SEQ_LEN become negative and test_attention.py
489
+ # will fail
490
+ assert max_shared_mem > 0, "max_shared_mem can not be zero"
491
+ return int(max_shared_mem)
492
+
493
+
494
+ def get_cpu_memory() -> int:
495
+ """Returns the total CPU memory of the node in bytes."""
496
+ return psutil.virtual_memory().total
497
+
498
+
499
+ def random_uuid() -> str:
500
+ return str(uuid.uuid4().hex)
501
+
502
+
503
+ def make_async(
504
+ func: Callable[P, T],
505
+ executor: Optional[concurrent.futures.Executor] = None
506
+ ) -> Callable[P, Awaitable[T]]:
507
+ """Take a blocking function, and run it on in an executor thread.
508
+
509
+ This function prevents the blocking function from blocking the
510
+ asyncio event loop.
511
+ The code in this function needs to be thread safe.
512
+ """
513
+
514
+ def _async_wrapper(*args: P.args, **kwargs: P.kwargs) -> asyncio.Future:
515
+ loop = asyncio.get_event_loop()
516
+ p_func = partial(func, *args, **kwargs)
517
+ return loop.run_in_executor(executor=executor, func=p_func)
518
+
519
+ return _async_wrapper
520
+
521
+
522
+ def _next_task(iterator: AsyncGenerator[T, None],
523
+ loop: AbstractEventLoop) -> Task:
524
+ # Can use anext() in python >= 3.10
525
+ return loop.create_task(iterator.__anext__()) # type: ignore[arg-type]
526
+
527
+
528
+ async def merge_async_iterators(
529
+ *iterators: AsyncGenerator[T,
530
+ None], ) -> AsyncGenerator[tuple[int, T], None]:
531
+ """Merge multiple asynchronous iterators into a single iterator.
532
+
533
+ This method handle the case where some iterators finish before others.
534
+ When it yields, it yields a tuple (i, item) where i is the index of the
535
+ iterator that yields the item.
536
+ """
537
+ if len(iterators) == 1:
538
+ # Fast-path single iterator case.
539
+ async for item in iterators[0]:
540
+ yield 0, item
541
+ return
542
+
543
+ loop = asyncio.get_running_loop()
544
+
545
+ awaits = {_next_task(pair[1], loop): pair for pair in enumerate(iterators)}
546
+ try:
547
+ while awaits:
548
+ done, _ = await asyncio.wait(awaits.keys(),
549
+ return_when=FIRST_COMPLETED)
550
+ for d in done:
551
+ pair = awaits.pop(d)
552
+ try:
553
+ item = await d
554
+ i, it = pair
555
+ awaits[_next_task(it, loop)] = pair
556
+ yield i, item
557
+ except StopAsyncIteration:
558
+ pass
559
+ finally:
560
+ # Cancel any remaining iterators
561
+ for f, (_, it) in awaits.items():
562
+ with contextlib.suppress(BaseException):
563
+ f.cancel()
564
+ await it.aclose()
565
+
566
+
567
+ async def collect_from_async_generator(
568
+ iterator: AsyncGenerator[T, None]) -> list[T]:
569
+ """Collect all items from an async generator into a list."""
570
+ items = []
571
+ async for item in iterator:
572
+ items.append(item)
573
+ return items
574
+
575
+
576
+ def get_ip() -> str:
577
+ host_ip = envs.VLLM_HOST_IP
578
+ if "HOST_IP" in os.environ and "VLLM_HOST_IP" not in os.environ:
579
+ logger.warning(
580
+ "The environment variable HOST_IP is deprecated and ignored, as"
581
+ " it is often used by Docker and other software to"
582
+ " interact with the container's network stack. Please "
583
+ "use VLLM_HOST_IP instead to set the IP address for vLLM processes"
584
+ " to communicate with each other.")
585
+ if host_ip:
586
+ return host_ip
587
+
588
+ # IP is not set, try to get it from the network interface
589
+
590
+ # try ipv4
591
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
592
+ try:
593
+ s.connect(("8.8.8.8", 80)) # Doesn't need to be reachable
594
+ return s.getsockname()[0]
595
+ except Exception:
596
+ pass
597
+
598
+ # try ipv6
599
+ try:
600
+ s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
601
+ # Google's public DNS server, see
602
+ # https://developers.google.com/speed/public-dns/docs/using#addresses
603
+ s.connect(("2001:4860:4860::8888", 80)) # Doesn't need to be reachable
604
+ return s.getsockname()[0]
605
+ except Exception:
606
+ pass
607
+
608
+ warnings.warn(
609
+ "Failed to get the IP address, using 0.0.0.0 by default."
610
+ "The value can be set by the environment variable"
611
+ " VLLM_HOST_IP or HOST_IP.",
612
+ stacklevel=2)
613
+ return "0.0.0.0"
614
+
615
+
616
+ def is_valid_ipv6_address(address: str) -> bool:
617
+ try:
618
+ ipaddress.IPv6Address(address)
619
+ return True
620
+ except ValueError:
621
+ return False
622
+
623
+
624
+ def get_distributed_init_method(ip: str, port: int) -> str:
625
+ return get_tcp_uri(ip, port)
626
+
627
+
628
+ def get_tcp_uri(ip: str, port: int) -> str:
629
+ # Brackets are not permitted in ipv4 addresses,
630
+ # see https://github.com/python/cpython/issues/103848
631
+ return f"tcp://[{ip}]:{port}" if ":" in ip else f"tcp://{ip}:{port}"
632
+
633
+
634
+ def get_open_zmq_ipc_path() -> str:
635
+ base_rpc_path = envs.VLLM_RPC_BASE_PATH
636
+ return f"ipc://{base_rpc_path}/{uuid4()}"
637
+
638
+
639
+ def get_open_zmq_inproc_path() -> str:
640
+ return f"inproc://{uuid4()}"
641
+
642
+
643
+ def get_open_port() -> int:
644
+ """
645
+ Get an open port for the vLLM process to listen on.
646
+ An edge case to handle, is when we run data parallel,
647
+ we need to avoid ports that are potentially used by
648
+ the data parallel master process.
649
+ Right now we reserve 10 ports for the data parallel master
650
+ process. Currently it uses 2 ports.
651
+ """
652
+ if "VLLM_DP_MASTER_PORT" in os.environ:
653
+ dp_master_port = envs.VLLM_DP_MASTER_PORT
654
+ reserved_port_range = range(dp_master_port, dp_master_port + 10)
655
+ while True:
656
+ candidate_port = _get_open_port()
657
+ if candidate_port not in reserved_port_range:
658
+ return candidate_port
659
+ return _get_open_port()
660
+
661
+
662
+ def _get_open_port() -> int:
663
+ port = envs.VLLM_PORT
664
+ if port is not None:
665
+ while True:
666
+ try:
667
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
668
+ s.bind(("", port))
669
+ return port
670
+ except OSError:
671
+ port += 1 # Increment port number if already in use
672
+ logger.info("Port %d is already in use, trying port %d",
673
+ port - 1, port)
674
+ # try ipv4
675
+ try:
676
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
677
+ s.bind(("", 0))
678
+ return s.getsockname()[1]
679
+ except OSError:
680
+ # try ipv6
681
+ with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
682
+ s.bind(("", 0))
683
+ return s.getsockname()[1]
684
+
685
+
686
+ def find_process_using_port(port: int) -> Optional[psutil.Process]:
687
+ # TODO: We can not check for running processes with network
688
+ # port on macOS. Therefore, we can not have a full graceful shutdown
689
+ # of vLLM. For now, let's not look for processes in this case.
690
+ # Ref: https://www.florianreinhard.de/accessdenied-in-psutil/
691
+ if sys.platform.startswith("darwin"):
692
+ return None
693
+
694
+ for conn in psutil.net_connections():
695
+ if conn.laddr.port == port:
696
+ try:
697
+ return psutil.Process(conn.pid)
698
+ except psutil.NoSuchProcess:
699
+ return None
700
+ return None
701
+
702
+
703
+ def update_environment_variables(envs: dict[str, str]):
704
+ for k, v in envs.items():
705
+ if k in os.environ and os.environ[k] != v:
706
+ logger.warning(
707
+ "Overwriting environment variable %s "
708
+ "from '%s' to '%s'", k, os.environ[k], v)
709
+ os.environ[k] = v
710
+
711
+
712
+ def chunk_list(lst: list[T], chunk_size: int):
713
+ """Yield successive chunk_size chunks from lst."""
714
+ for i in range(0, len(lst), chunk_size):
715
+ yield lst[i:i + chunk_size]
716
+
717
+
718
+ def cdiv(a: int, b: int) -> int:
719
+ """Ceiling division."""
720
+ return -(a // -b)
721
+
722
+
723
+ def next_power_of_2(n) -> int:
724
+ """The next power of 2 (inclusive)"""
725
+ if n < 1:
726
+ return 1
727
+ return 1 << (n - 1).bit_length()
728
+
729
+
730
+ def round_up(x: int, y: int) -> int:
731
+ return ((x + y - 1) // y) * y
732
+
733
+
734
+ def round_down(x: int, y: int) -> int:
735
+ return (x // y) * y
736
+
737
+
738
+ def _generate_random_fp8(
739
+ tensor: torch.Tensor,
740
+ low: float,
741
+ high: float,
742
+ ) -> None:
743
+ # NOTE(zhaoyang): Due to NaN and Inf representation for fp8 data type,
744
+ # it may occur Inf or NaN if we directly use torch.randint
745
+ # to generate random data for fp8 data.
746
+ # For example, s.11111.00 in fp8e5m2 format represents Inf.
747
+ # | E4M3 | E5M2
748
+ #-----|-------------|-------------------
749
+ # Inf | N/A | s.11111.00
750
+ # NaN | s.1111.111 | s.11111.{01,10,11}
751
+ from vllm import _custom_ops as ops
752
+ tensor_tmp = torch.empty_like(tensor, dtype=torch.float16)
753
+ tensor_tmp.uniform_(low, high)
754
+ ops.convert_fp8(tensor, tensor_tmp)
755
+ del tensor_tmp
756
+
757
+
758
+ def get_kv_cache_torch_dtype(
759
+ cache_dtype: Optional[Union[str, torch.dtype]],
760
+ model_dtype: Optional[Union[str, torch.dtype]] = None) -> torch.dtype:
761
+ if isinstance(cache_dtype, str):
762
+ if cache_dtype == "auto":
763
+ if isinstance(model_dtype,
764
+ str) and model_dtype in STR_DTYPE_TO_TORCH_DTYPE:
765
+ torch_dtype = STR_DTYPE_TO_TORCH_DTYPE[model_dtype]
766
+ elif isinstance(model_dtype, torch.dtype):
767
+ torch_dtype = model_dtype
768
+ else:
769
+ raise ValueError(f"Invalid model dtype: {model_dtype}")
770
+ elif cache_dtype in STR_DTYPE_TO_TORCH_DTYPE:
771
+ torch_dtype = STR_DTYPE_TO_TORCH_DTYPE[cache_dtype]
772
+ else:
773
+ raise ValueError(f"Invalid kv cache dtype: {cache_dtype}")
774
+ elif isinstance(cache_dtype, torch.dtype):
775
+ torch_dtype = cache_dtype
776
+ else:
777
+ raise ValueError(f"Invalid kv cache dtype: {cache_dtype}")
778
+ return torch_dtype
779
+
780
+
781
+ def create_kv_caches_with_random_flash(
782
+ num_blocks: int,
783
+ block_size: int,
784
+ num_layers: int,
785
+ num_heads: int,
786
+ head_size: int,
787
+ cache_dtype: Optional[Union[str, torch.dtype]],
788
+ model_dtype: Optional[Union[str, torch.dtype]] = None,
789
+ seed: Optional[int] = None,
790
+ device: Optional[str] = "cuda",
791
+ cache_layout: Optional[str] = "NHD",
792
+ ) -> tuple[list[torch.Tensor], list[torch.Tensor]]:
793
+ from vllm.platforms import current_platform
794
+ current_platform.seed_everything(seed)
795
+
796
+ torch_dtype = get_kv_cache_torch_dtype(cache_dtype, model_dtype)
797
+ generic_kv_cache_shape = (num_blocks, 2, block_size, num_heads, head_size)
798
+ assert cache_layout in ("NHD", "HND")
799
+ stride_order = (0, 1, 2, 3, 4) if cache_layout == "NHD" else (0, 1, 3, 2,
800
+ 4)
801
+
802
+ kv_cache_allocation_shape = tuple(generic_kv_cache_shape[i]
803
+ for i in stride_order)
804
+ scale = head_size**-0.5
805
+
806
+ key_caches: list[torch.Tensor] = []
807
+ value_caches: list[torch.Tensor] = []
808
+
809
+ for _ in range(num_layers):
810
+ key_value_cache = torch.empty(size=kv_cache_allocation_shape,
811
+ dtype=torch_dtype,
812
+ device=device).permute(*stride_order)
813
+ if cache_dtype in ["auto", "half", "bfloat16", "float"]:
814
+ key_value_cache.uniform_(-scale, scale)
815
+ elif cache_dtype == 'fp8':
816
+ _generate_random_fp8(key_value_cache, -scale, scale)
817
+ else:
818
+ raise ValueError(
819
+ f"Does not support key cache of type {cache_dtype}")
820
+ key_caches.append(key_value_cache[:, 0])
821
+ value_caches.append(key_value_cache[:, 1])
822
+ return key_caches, value_caches
823
+
824
+
825
+ def create_kv_caches_with_random(
826
+ num_blocks: int,
827
+ block_size: int,
828
+ num_layers: int,
829
+ num_heads: int,
830
+ head_size: int,
831
+ cache_dtype: Optional[Union[str, torch.dtype]],
832
+ model_dtype: Optional[Union[str, torch.dtype]] = None,
833
+ seed: Optional[int] = None,
834
+ device: Optional[str] = "cuda",
835
+ ) -> tuple[list[torch.Tensor], list[torch.Tensor]]:
836
+
837
+ if cache_dtype == "fp8" and head_size % 16:
838
+ raise ValueError(
839
+ f"Does not support key cache of type fp8 with head_size {head_size}"
840
+ )
841
+ from vllm.platforms import current_platform
842
+ current_platform.seed_everything(seed)
843
+
844
+ torch_dtype = get_kv_cache_torch_dtype(cache_dtype, model_dtype)
845
+
846
+ scale = head_size**-0.5
847
+ x = 16 // torch.tensor([], dtype=torch_dtype).element_size()
848
+ key_cache_shape = (num_blocks, num_heads, head_size // x, block_size, x)
849
+ key_caches: list[torch.Tensor] = []
850
+ for _ in range(num_layers):
851
+ key_cache = torch.empty(size=key_cache_shape,
852
+ dtype=torch_dtype,
853
+ device=device)
854
+ if cache_dtype in ["auto", "half", "bfloat16", "float"]:
855
+ key_cache.uniform_(-scale, scale)
856
+ elif cache_dtype == 'fp8':
857
+ _generate_random_fp8(key_cache, -scale, scale)
858
+ else:
859
+ raise ValueError(
860
+ f"Does not support key cache of type {cache_dtype}")
861
+ key_caches.append(key_cache)
862
+
863
+ value_cache_shape = (num_blocks, num_heads, head_size, block_size)
864
+ value_caches: list[torch.Tensor] = []
865
+ for _ in range(num_layers):
866
+ value_cache = torch.empty(size=value_cache_shape,
867
+ dtype=torch_dtype,
868
+ device=device)
869
+ if cache_dtype in ["auto", "half", "bfloat16", "float"]:
870
+ value_cache.uniform_(-scale, scale)
871
+ elif cache_dtype == 'fp8':
872
+ _generate_random_fp8(value_cache, -scale, scale)
873
+ else:
874
+ raise ValueError(
875
+ f"Does not support value cache of type {cache_dtype}")
876
+ value_caches.append(value_cache)
877
+ return key_caches, value_caches
878
+
879
+
880
+ @cache
881
+ def is_pin_memory_available() -> bool:
882
+ from vllm.platforms import current_platform
883
+ return current_platform.is_pin_memory_available()
884
+
885
+
886
+ @cache
887
+ def is_uva_available() -> bool:
888
+ """Check if Unified Virtual Addressing (UVA) is available."""
889
+ # UVA requires pinned memory.
890
+ # TODO: Add more requirements for UVA if needed.
891
+ return is_pin_memory_available()
892
+
893
+
894
+ class DeviceMemoryProfiler:
895
+
896
+ def __init__(self, device: Optional[torch.types.Device] = None):
897
+ self.device = device
898
+
899
+ def current_memory_usage(self) -> float:
900
+ # Return the memory usage in bytes.
901
+ from vllm.platforms import current_platform
902
+ gc.collect()
903
+ return current_platform.get_current_memory_usage(self.device)
904
+
905
+ def __enter__(self):
906
+ self.initial_memory = self.current_memory_usage()
907
+ # This allows us to call methods of the context manager if needed
908
+ return self
909
+
910
+ def __exit__(self, exc_type, exc_val, exc_tb):
911
+ self.final_memory = self.current_memory_usage()
912
+ self.consumed_memory = self.final_memory - self.initial_memory
913
+
914
+ # Force garbage collection
915
+ gc.collect()
916
+
917
+
918
+ def make_ndarray_with_pad(
919
+ x: list[list[T]],
920
+ pad: T,
921
+ dtype: npt.DTypeLike,
922
+ *,
923
+ max_len: Optional[int] = None,
924
+ ) -> npt.NDArray:
925
+ """
926
+ Make a padded array from 2D inputs.
927
+
928
+ The padding is applied to the end of each inner list until it reaches
929
+ `max_len`.
930
+ """
931
+ if max_len is None:
932
+ # Unlike for most functions, map is faster than a genexpr over `len`
933
+ max_len = max(map(len, x), default=0)
934
+
935
+ padded_x = np.full((len(x), max_len), pad, dtype=dtype)
936
+ for ind, blocktb in enumerate(x):
937
+ assert len(blocktb) <= max_len
938
+ padded_x[ind, :len(blocktb)] = blocktb
939
+
940
+ return padded_x
941
+
942
+
943
+ def make_tensor_with_pad(
944
+ x: list[list[T]],
945
+ pad: T,
946
+ dtype: torch.dtype,
947
+ *,
948
+ max_len: Optional[int] = None,
949
+ device: Optional[Union[str, torch.device]] = None,
950
+ pin_memory: bool = False,
951
+ ) -> torch.Tensor:
952
+ """
953
+ Make a padded tensor from 2D inputs.
954
+
955
+ The padding is applied to the end of each inner list until it reaches
956
+ `max_len`.
957
+ """
958
+ np_dtype = TORCH_DTYPE_TO_NUMPY_DTYPE[dtype]
959
+ padded_x = make_ndarray_with_pad(x, pad, np_dtype, max_len=max_len)
960
+
961
+ tensor = torch.from_numpy(padded_x).to(device)
962
+ if pin_memory:
963
+ tensor = tensor.pin_memory()
964
+
965
+ return tensor
966
+
967
+
968
+ def async_tensor_h2d(
969
+ data: list,
970
+ dtype: torch.dtype,
971
+ target_device: Union[str, torch.device],
972
+ pin_memory: bool,
973
+ ) -> torch.Tensor:
974
+ """Asynchronously create a tensor and copy it from host to device."""
975
+ t = torch.tensor(data, dtype=dtype, pin_memory=pin_memory, device="cpu")
976
+ return t.to(device=target_device, non_blocking=True)
977
+
978
+
979
+ def get_dtype_size(dtype: torch.dtype) -> int:
980
+ """Get the size of the data type in bytes."""
981
+ return torch.tensor([], dtype=dtype).element_size()
982
+
983
+
984
+ # bool = 0, int = 1, float = 2, complex = 3
985
+ def _get_precision_level(dtype: torch.dtype) -> int:
986
+ # NOTE: Complex dtypes return `is_floating_point=False`
987
+ return ((dtype != torch.bool) + dtype.is_floating_point +
988
+ dtype.is_complex * 2)
989
+
990
+
991
+ def is_lossless_cast(src_dtype: torch.dtype, tgt_dtype: torch.dtype):
992
+ """
993
+ Test whether it is lossless to cast a tensor from
994
+ `src_dtype` to `tgt_dtype`.
995
+ """
996
+ if src_dtype == tgt_dtype:
997
+ return True
998
+
999
+ src_level = _get_precision_level(src_dtype)
1000
+ tgt_level = _get_precision_level(tgt_dtype)
1001
+
1002
+ if src_level < tgt_level:
1003
+ return True
1004
+ if src_level > tgt_level:
1005
+ return False
1006
+
1007
+ # Compare integral types
1008
+ if not src_dtype.is_floating_point and not src_dtype.is_complex:
1009
+ src_info = torch.iinfo(src_dtype)
1010
+ tgt_info = torch.iinfo(tgt_dtype)
1011
+ return src_info.min >= tgt_info.min and src_info.max <= tgt_info.max
1012
+
1013
+ # Compare floating-point types
1014
+ src_info = torch.finfo(src_dtype)
1015
+ tgt_info = torch.finfo(tgt_dtype)
1016
+ return (src_info.min >= tgt_info.min and src_info.max <= tgt_info.max
1017
+ and src_info.resolution >= tgt_info.resolution)
1018
+
1019
+
1020
+ def common_broadcastable_dtype(dtypes: Collection[torch.dtype]):
1021
+ """
1022
+ Get the common `dtype` where all of the other `dtypes` can be
1023
+ cast to it without losing any information.
1024
+ """
1025
+ return max(
1026
+ dtypes,
1027
+ key=lambda dtype: sum(is_lossless_cast(dt, dtype) for dt in dtypes),
1028
+ )
1029
+
1030
+
1031
+ # `collections` helpers
1032
+ def is_list_of(
1033
+ value: object,
1034
+ typ: Union[type[T], tuple[type[T], ...]],
1035
+ *,
1036
+ check: Literal["first", "all"] = "first",
1037
+ ) -> TypeIs[list[T]]:
1038
+ if not isinstance(value, list):
1039
+ return False
1040
+
1041
+ if check == "first":
1042
+ return len(value) == 0 or isinstance(value[0], typ)
1043
+ elif check == "all":
1044
+ return all(isinstance(v, typ) for v in value)
1045
+
1046
+ assert_never(check)
1047
+
1048
+
1049
+ def flatten_2d_lists(lists: Iterable[Iterable[T]]) -> list[T]:
1050
+ """Flatten a list of lists to a single list."""
1051
+ return [item for sublist in lists for item in sublist]
1052
+
1053
+
1054
+ def full_groupby(values: Iterable[_V], *, key: Callable[[_V], _K]):
1055
+ """
1056
+ Unlike [`itertools.groupby`][], groups are not broken by
1057
+ non-contiguous data.
1058
+ """
1059
+ groups = defaultdict[_K, list[_V]](list)
1060
+
1061
+ for value in values:
1062
+ groups[key(value)].append(value)
1063
+
1064
+ return groups.items()
1065
+
1066
+
1067
+ # TODO: This function can be removed if transformer_modules classes are
1068
+ # serialized by value when communicating between processes
1069
+ def init_cached_hf_modules() -> None:
1070
+ """
1071
+ Lazy initialization of the Hugging Face modules.
1072
+ """
1073
+ from transformers.dynamic_module_utils import init_hf_modules
1074
+ init_hf_modules()
1075
+
1076
+
1077
+ @cache
1078
+ def find_library(lib_name: str) -> str:
1079
+ """
1080
+ Find the library file in the system.
1081
+ `lib_name` is full filename, with both prefix and suffix.
1082
+ This function resolves `lib_name` to the full path of the library.
1083
+ """
1084
+ # Adapted from https://github.com/openai/triton/blob/main/third_party/nvidia/backend/driver.py#L19 # noqa
1085
+ # According to https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
1086
+ # `/sbin/ldconfig` should exist in all Linux systems.
1087
+ # `/sbin/ldconfig` searches the library in the system
1088
+ libs = subprocess.check_output(["/sbin/ldconfig", "-p"]).decode()
1089
+ # each line looks like the following:
1090
+ # libcuda.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libcuda.so.1
1091
+ locs = [line.split()[-1] for line in libs.splitlines() if lib_name in line]
1092
+ # `LD_LIBRARY_PATH` searches the library in the user-defined paths
1093
+ env_ld_library_path = envs.LD_LIBRARY_PATH
1094
+ if not locs and env_ld_library_path:
1095
+ locs = [
1096
+ os.path.join(dir, lib_name)
1097
+ for dir in env_ld_library_path.split(":")
1098
+ if os.path.exists(os.path.join(dir, lib_name))
1099
+ ]
1100
+ if not locs:
1101
+ raise ValueError(f"Cannot find {lib_name} in the system.")
1102
+ return locs[0]
1103
+
1104
+
1105
+ def find_nccl_library() -> str:
1106
+ """
1107
+ We either use the library file specified by the `VLLM_NCCL_SO_PATH`
1108
+ environment variable, or we find the library file brought by PyTorch.
1109
+ After importing `torch`, `libnccl.so.2` or `librccl.so.1` can be
1110
+ found by `ctypes` automatically.
1111
+ """
1112
+ so_file = envs.VLLM_NCCL_SO_PATH
1113
+
1114
+ # manually load the nccl library
1115
+ if so_file:
1116
+ logger.info(
1117
+ "Found nccl from environment variable VLLM_NCCL_SO_PATH=%s",
1118
+ so_file)
1119
+ else:
1120
+ if torch.version.cuda is not None:
1121
+ so_file = "libnccl.so.2"
1122
+ elif torch.version.hip is not None:
1123
+ so_file = "librccl.so.1"
1124
+ else:
1125
+ raise ValueError("NCCL only supports CUDA and ROCm backends.")
1126
+ logger.info("Found nccl from library %s", so_file)
1127
+ return so_file
1128
+
1129
+
1130
+ prev_set_stream = torch.cuda.set_stream
1131
+
1132
+ _current_stream = None
1133
+
1134
+
1135
+ def _patched_set_stream(stream: torch.cuda.Stream) -> None:
1136
+ global _current_stream
1137
+ _current_stream = stream
1138
+ prev_set_stream(stream)
1139
+
1140
+
1141
+ torch.cuda.set_stream = _patched_set_stream
1142
+
1143
+
1144
+ def current_stream() -> torch.cuda.Stream:
1145
+ """
1146
+ replace `torch.cuda.current_stream()` with `vllm.utils.current_stream()`.
1147
+ it turns out that `torch.cuda.current_stream()` is quite expensive,
1148
+ as it will construct a new stream object at each call.
1149
+ here we patch `torch.cuda.set_stream` to keep track of the current stream
1150
+ directly, so that we can avoid calling `torch.cuda.current_stream()`.
1151
+
1152
+ the underlying hypothesis is that we do not call `torch._C._cuda_setStream`
1153
+ from C/C++ code.
1154
+ """
1155
+ from vllm.platforms import current_platform
1156
+ global _current_stream
1157
+ if _current_stream is None:
1158
+ # when this function is called before any stream is set,
1159
+ # we return the default stream.
1160
+ # On ROCm using the default 0 stream in combination with RCCL
1161
+ # is hurting performance. Therefore creating a dedicated stream
1162
+ # per process
1163
+ _current_stream = torch.cuda.Stream() if current_platform.is_rocm(
1164
+ ) else torch.cuda.current_stream()
1165
+ return _current_stream
1166
+
1167
+
1168
+ def enable_trace_function_call_for_thread(vllm_config: VllmConfig) -> None:
1169
+ """Set up function tracing for the current thread,
1170
+ if enabled via the VLLM_TRACE_FUNCTION environment variable
1171
+ """
1172
+
1173
+ if envs.VLLM_TRACE_FUNCTION:
1174
+ tmp_dir = tempfile.gettempdir()
1175
+ # add username to tmp_dir to avoid permission issues
1176
+ tmp_dir = os.path.join(tmp_dir, getpass.getuser())
1177
+ filename = (f"VLLM_TRACE_FUNCTION_for_process_{os.getpid()}"
1178
+ f"_thread_{threading.get_ident()}_"
1179
+ f"at_{datetime.datetime.now()}.log").replace(" ", "_")
1180
+ log_path = os.path.join(tmp_dir, "vllm",
1181
+ f"vllm-instance-{vllm_config.instance_id}",
1182
+ filename)
1183
+ os.makedirs(os.path.dirname(log_path), exist_ok=True)
1184
+ enable_trace_function_call(log_path)
1185
+
1186
+
1187
+ # `functools` helpers
1188
+ def identity(value: T, **kwargs) -> T:
1189
+ """Returns the first provided value."""
1190
+ return value
1191
+
1192
+
1193
+ F = TypeVar('F', bound=Callable[..., Any])
1194
+
1195
+
1196
+ def deprecate_args(
1197
+ start_index: int,
1198
+ is_deprecated: Union[bool, Callable[[], bool]] = True,
1199
+ additional_message: Optional[str] = None,
1200
+ ) -> Callable[[F], F]:
1201
+
1202
+ if not callable(is_deprecated):
1203
+ is_deprecated = partial(identity, is_deprecated)
1204
+
1205
+ def wrapper(fn: F) -> F:
1206
+
1207
+ params = inspect.signature(fn).parameters
1208
+ pos_types = (
1209
+ inspect.Parameter.POSITIONAL_ONLY,
1210
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
1211
+ )
1212
+ pos_kws = [
1213
+ kw for kw, param in params.items() if param.kind in pos_types
1214
+ ]
1215
+
1216
+ @wraps(fn)
1217
+ def inner(*args, **kwargs):
1218
+ if is_deprecated():
1219
+ deprecated_args = pos_kws[start_index:len(args)]
1220
+ if deprecated_args:
1221
+ msg = (
1222
+ f"The positional arguments {deprecated_args} are "
1223
+ "deprecated and will be removed in a future update.")
1224
+ if additional_message is not None:
1225
+ msg += f" {additional_message}"
1226
+
1227
+ warnings.warn(
1228
+ DeprecationWarning(msg),
1229
+ stacklevel=3, # The inner function takes up one level
1230
+ )
1231
+
1232
+ return fn(*args, **kwargs)
1233
+
1234
+ return inner # type: ignore
1235
+
1236
+ return wrapper
1237
+
1238
+
1239
+ def deprecate_kwargs(
1240
+ *kws: str,
1241
+ is_deprecated: Union[bool, Callable[[], bool]] = True,
1242
+ additional_message: Optional[str] = None,
1243
+ ) -> Callable[[F], F]:
1244
+ deprecated_kws = set(kws)
1245
+
1246
+ if not callable(is_deprecated):
1247
+ is_deprecated = partial(identity, is_deprecated)
1248
+
1249
+ def wrapper(fn: F) -> F:
1250
+
1251
+ @wraps(fn)
1252
+ def inner(*args, **kwargs):
1253
+ if is_deprecated():
1254
+ deprecated_kwargs = kwargs.keys() & deprecated_kws
1255
+ if deprecated_kwargs:
1256
+ msg = (
1257
+ f"The keyword arguments {deprecated_kwargs} are "
1258
+ "deprecated and will be removed in a future update.")
1259
+ if additional_message is not None:
1260
+ msg += f" {additional_message}"
1261
+
1262
+ warnings.warn(
1263
+ DeprecationWarning(msg),
1264
+ stacklevel=3, # The inner function takes up one level
1265
+ )
1266
+
1267
+ return fn(*args, **kwargs)
1268
+
1269
+ return inner # type: ignore
1270
+
1271
+ return wrapper
1272
+
1273
+
1274
+ @lru_cache(maxsize=8)
1275
+ def _cuda_device_count_stateless(
1276
+ cuda_visible_devices: Optional[str] = None) -> int:
1277
+ # Note: cuda_visible_devices is not used, but we keep it as an argument for
1278
+ # LRU Cache purposes.
1279
+
1280
+ # Code below is based on
1281
+ # https://github.com/pytorch/pytorch/blob/
1282
+ # c1cd946818442aca8c7f812b16d187ce1586c3bc/
1283
+ # torch/cuda/__init__.py#L831C1-L831C17
1284
+ import torch.cuda
1285
+ import torch.version
1286
+
1287
+ from vllm.platforms import current_platform
1288
+ if not torch.cuda._is_compiled():
1289
+ return 0
1290
+ if current_platform.is_rocm():
1291
+ # ROCm uses amdsmi instead of nvml for stateless device count
1292
+ # This requires a sufficiently modern version of Torch 2.4.0
1293
+ raw_count = torch.cuda._device_count_amdsmi() if (hasattr(
1294
+ torch.cuda, "_device_count_amdsmi")) else -1
1295
+ else:
1296
+ raw_count = torch.cuda._device_count_nvml()
1297
+ r = torch._C._cuda_getDeviceCount() if raw_count < 0 else raw_count
1298
+ return r
1299
+
1300
+
1301
+ def cuda_device_count_stateless() -> int:
1302
+ """Get number of CUDA devices, caching based on the value of
1303
+ CUDA_VISIBLE_DEVICES at the time of call.
1304
+
1305
+ This should be used instead of torch.cuda.device_count()
1306
+ unless CUDA_VISIBLE_DEVICES has already been set to the desired
1307
+ value."""
1308
+
1309
+ # This can be removed and simply replaced with torch.cuda.get_device_count
1310
+ # after https://github.com/pytorch/pytorch/pull/122815 is released.
1311
+ return _cuda_device_count_stateless(envs.CUDA_VISIBLE_DEVICES)
1312
+
1313
+
1314
+ def cuda_is_initialized() -> bool:
1315
+ """Check if CUDA is initialized."""
1316
+ if not torch.cuda._is_compiled():
1317
+ return False
1318
+ return torch.cuda.is_initialized()
1319
+
1320
+
1321
+ def cuda_get_device_properties(device,
1322
+ names: Sequence[str],
1323
+ init_cuda=False) -> tuple[Any, ...]:
1324
+ """Get specified CUDA device property values without initializing CUDA in
1325
+ the current process."""
1326
+ if init_cuda or cuda_is_initialized():
1327
+ props = torch.cuda.get_device_properties(device)
1328
+ return tuple(getattr(props, name) for name in names)
1329
+
1330
+ # Run in subprocess to avoid initializing CUDA as a side effect.
1331
+ mp_ctx = multiprocessing.get_context("fork")
1332
+ with ProcessPoolExecutor(max_workers=1, mp_context=mp_ctx) as executor:
1333
+ return executor.submit(cuda_get_device_properties, device, names,
1334
+ True).result()
1335
+
1336
+
1337
+ def weak_bind(bound_method: Callable[..., Any], ) -> Callable[..., None]:
1338
+ """Make an instance method that weakly references
1339
+ its associated instance and no-ops once that
1340
+ instance is collected."""
1341
+ ref = weakref.ref(bound_method.__self__) # type: ignore[attr-defined]
1342
+ unbound = bound_method.__func__ # type: ignore[attr-defined]
1343
+
1344
+ def weak_bound(*args, **kwargs) -> None:
1345
+ if inst := ref():
1346
+ unbound(inst, *args, **kwargs)
1347
+
1348
+ return weak_bound
1349
+
1350
+
1351
+ #From: https://stackoverflow.com/a/4104188/2749989
1352
+ def run_once(f: Callable[P, None]) -> Callable[P, None]:
1353
+
1354
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
1355
+ if not wrapper.has_run: # type: ignore[attr-defined]
1356
+ wrapper.has_run = True # type: ignore[attr-defined]
1357
+ return f(*args, **kwargs)
1358
+
1359
+ wrapper.has_run = False # type: ignore[attr-defined]
1360
+ return wrapper
1361
+
1362
+
1363
+ class StoreBoolean(Action):
1364
+
1365
+ def __call__(self, parser, namespace, values, option_string=None):
1366
+ if values.lower() == "true":
1367
+ setattr(namespace, self.dest, True)
1368
+ elif values.lower() == "false":
1369
+ setattr(namespace, self.dest, False)
1370
+ else:
1371
+ raise ValueError(f"Invalid boolean value: {values}. "
1372
+ "Expected 'true' or 'false'.")
1373
+
1374
+
1375
+ class SortedHelpFormatter(ArgumentDefaultsHelpFormatter,
1376
+ RawDescriptionHelpFormatter):
1377
+ """SortedHelpFormatter that sorts arguments by their option strings."""
1378
+
1379
+ def _split_lines(self, text, width):
1380
+ """
1381
+ 1. Sentences split across lines have their single newlines removed.
1382
+ 2. Paragraphs and explicit newlines are split into separate lines.
1383
+ 3. Each line is wrapped to the specified width (width of terminal).
1384
+ """
1385
+ # The patterns also include whitespace after the newline
1386
+ single_newline = re.compile(r"(?<!\n)\n(?!\n)\s*")
1387
+ multiple_newlines = re.compile(r"\n{2,}\s*")
1388
+ text = single_newline.sub(' ', text)
1389
+ lines = re.split(multiple_newlines, text)
1390
+ return sum([textwrap.wrap(line, width) for line in lines], [])
1391
+
1392
+ def add_arguments(self, actions):
1393
+ actions = sorted(actions, key=lambda x: x.option_strings)
1394
+ super().add_arguments(actions)
1395
+
1396
+
1397
+ class FlexibleArgumentParser(ArgumentParser):
1398
+ """ArgumentParser that allows both underscore and dash in names."""
1399
+
1400
+ _deprecated: set[Action] = set()
1401
+
1402
+ def __init__(self, *args, **kwargs):
1403
+ # Set the default 'formatter_class' to SortedHelpFormatter
1404
+ if 'formatter_class' not in kwargs:
1405
+ kwargs['formatter_class'] = SortedHelpFormatter
1406
+ super().__init__(*args, **kwargs)
1407
+
1408
+ if sys.version_info < (3, 13):
1409
+ # Enable the deprecated kwarg for Python 3.12 and below
1410
+
1411
+ def parse_known_args(self, args=None, namespace=None):
1412
+ namespace, args = super().parse_known_args(args, namespace)
1413
+ for action in FlexibleArgumentParser._deprecated:
1414
+ if (hasattr(namespace, dest := action.dest)
1415
+ and getattr(namespace, dest) != action.default):
1416
+ logger.warning_once("argument '%s' is deprecated", dest)
1417
+ return namespace, args
1418
+
1419
+ def add_argument(self, *args, **kwargs):
1420
+ deprecated = kwargs.pop("deprecated", False)
1421
+ action = super().add_argument(*args, **kwargs)
1422
+ if deprecated:
1423
+ FlexibleArgumentParser._deprecated.add(action)
1424
+ return action
1425
+
1426
+ class _FlexibleArgumentGroup(_ArgumentGroup):
1427
+
1428
+ def add_argument(self, *args, **kwargs):
1429
+ deprecated = kwargs.pop("deprecated", False)
1430
+ action = super().add_argument(*args, **kwargs)
1431
+ if deprecated:
1432
+ FlexibleArgumentParser._deprecated.add(action)
1433
+ return action
1434
+
1435
+ def add_argument_group(self, *args, **kwargs):
1436
+ group = self._FlexibleArgumentGroup(self, *args, **kwargs)
1437
+ self._action_groups.append(group)
1438
+ return group
1439
+
1440
+ def parse_args( # type: ignore[override]
1441
+ self,
1442
+ args: list[str] | None = None,
1443
+ namespace: Namespace | None = None,
1444
+ ):
1445
+ if args is None:
1446
+ args = sys.argv[1:]
1447
+
1448
+ # Check for --model in command line arguments first
1449
+ if args and args[0] == "serve":
1450
+ model_in_cli_args = any(arg == '--model' for arg in args)
1451
+
1452
+ if model_in_cli_args:
1453
+ raise ValueError(
1454
+ "With `vllm serve`, you should provide the model as a "
1455
+ "positional argument or in a config file instead of via "
1456
+ "the `--model` option.")
1457
+
1458
+ if '--config' in args:
1459
+ args = self._pull_args_from_config(args)
1460
+
1461
+ def repl(match: re.Match) -> str:
1462
+ """Replaces underscores with dashes in the matched string."""
1463
+ return match.group(0).replace("_", "-")
1464
+
1465
+ # Everything between the first -- and the first .
1466
+ pattern = re.compile(r"(?<=--)[^\.]*")
1467
+
1468
+ # Convert underscores to dashes and vice versa in argument names
1469
+ processed_args = []
1470
+ for arg in args:
1471
+ if arg.startswith('--'):
1472
+ if '=' in arg:
1473
+ key, value = arg.split('=', 1)
1474
+ key = pattern.sub(repl, key, count=1)
1475
+ processed_args.append(f'{key}={value}')
1476
+ else:
1477
+ key = pattern.sub(repl, arg, count=1)
1478
+ processed_args.append(key)
1479
+ elif arg.startswith('-O') and arg != '-O' and len(arg) == 2:
1480
+ # allow -O flag to be used without space, e.g. -O3
1481
+ processed_args.append('-O')
1482
+ processed_args.append(arg[2:])
1483
+ else:
1484
+ processed_args.append(arg)
1485
+
1486
+ def create_nested_dict(keys: list[str], value: str):
1487
+ """Creates a nested dictionary from a list of keys and a value.
1488
+
1489
+ For example, `keys = ["a", "b", "c"]` and `value = 1` will create:
1490
+ `{"a": {"b": {"c": 1}}}`
1491
+ """
1492
+ nested_dict: Any = value
1493
+ for key in reversed(keys):
1494
+ nested_dict = {key: nested_dict}
1495
+ return nested_dict
1496
+
1497
+ def recursive_dict_update(original: dict, update: dict):
1498
+ """Recursively updates a dictionary with another dictionary."""
1499
+ for k, v in update.items():
1500
+ if isinstance(v, dict) and isinstance(original.get(k), dict):
1501
+ recursive_dict_update(original[k], v)
1502
+ else:
1503
+ original[k] = v
1504
+
1505
+ delete = set()
1506
+ dict_args: dict[str, dict] = defaultdict(dict)
1507
+ for i, processed_arg in enumerate(processed_args):
1508
+ if processed_arg.startswith("--") and "." in processed_arg:
1509
+ if "=" in processed_arg:
1510
+ processed_arg, value = processed_arg.split("=", 1)
1511
+ if "." not in processed_arg:
1512
+ # False positive, . was only in the value
1513
+ continue
1514
+ else:
1515
+ value = processed_args[i + 1]
1516
+ delete.add(i + 1)
1517
+ key, *keys = processed_arg.split(".")
1518
+ # Merge all values with the same key into a single dict
1519
+ arg_dict = create_nested_dict(keys, value)
1520
+ recursive_dict_update(dict_args[key], arg_dict)
1521
+ delete.add(i)
1522
+ # Filter out the dict args we set to None
1523
+ processed_args = [
1524
+ a for i, a in enumerate(processed_args) if i not in delete
1525
+ ]
1526
+ # Add the dict args back as if they were originally passed as JSON
1527
+ for dict_arg, dict_value in dict_args.items():
1528
+ processed_args.append(dict_arg)
1529
+ processed_args.append(json.dumps(dict_value))
1530
+
1531
+ return super().parse_args(processed_args, namespace)
1532
+
1533
+ def check_port(self, value):
1534
+ try:
1535
+ value = int(value)
1536
+ except ValueError:
1537
+ msg = "Port must be an integer"
1538
+ raise ArgumentTypeError(msg) from None
1539
+
1540
+ if not (1024 <= value <= 65535):
1541
+ raise ArgumentTypeError("Port must be between 1024 and 65535")
1542
+
1543
+ return value
1544
+
1545
+ def _pull_args_from_config(self, args: list[str]) -> list[str]:
1546
+ """Method to pull arguments specified in the config file
1547
+ into the command-line args variable.
1548
+
1549
+ The arguments in config file will be inserted between
1550
+ the argument list.
1551
+
1552
+ example:
1553
+ ```yaml
1554
+ port: 12323
1555
+ tensor-parallel-size: 4
1556
+ ```
1557
+ ```python
1558
+ $: vllm {serve,chat,complete} "facebook/opt-12B" \
1559
+ --config config.yaml -tp 2
1560
+ $: args = [
1561
+ "serve,chat,complete",
1562
+ "facebook/opt-12B",
1563
+ '--config', 'config.yaml',
1564
+ '-tp', '2'
1565
+ ]
1566
+ $: args = [
1567
+ "serve,chat,complete",
1568
+ "facebook/opt-12B",
1569
+ '--port', '12323',
1570
+ '--tensor-parallel-size', '4',
1571
+ '-tp', '2'
1572
+ ]
1573
+ ```
1574
+
1575
+ Please note how the config args are inserted after the sub command.
1576
+ this way the order of priorities is maintained when these are args
1577
+ parsed by super().
1578
+ """
1579
+ assert args.count(
1580
+ '--config') <= 1, "More than one config file specified!"
1581
+
1582
+ index = args.index('--config')
1583
+ if index == len(args) - 1:
1584
+ raise ValueError("No config file specified! \
1585
+ Please check your command-line arguments.")
1586
+
1587
+ file_path = args[index + 1]
1588
+
1589
+ config_args = self._load_config_file(file_path)
1590
+
1591
+ # 0th index is for {serve,chat,complete}
1592
+ # optionally followed by model_tag (only for serve)
1593
+ # followed by config args
1594
+ # followed by rest of cli args.
1595
+ # maintaining this order will enforce the precedence
1596
+ # of cli > config > defaults
1597
+ if args[0] == "serve":
1598
+ model_in_cli = len(args) > 1 and not args[1].startswith('-')
1599
+ model_in_config = any(arg == '--model' for arg in config_args)
1600
+
1601
+ if not model_in_cli and not model_in_config:
1602
+ raise ValueError(
1603
+ "No model specified! Please specify model either "
1604
+ "as a positional argument or in a config file.")
1605
+
1606
+ if model_in_cli:
1607
+ # Model specified as positional arg, keep CLI version
1608
+ args = [args[0]] + [
1609
+ args[1]
1610
+ ] + config_args + args[2:index] + args[index + 2:]
1611
+ else:
1612
+ # No model in CLI, use config if available
1613
+ args = [args[0]
1614
+ ] + config_args + args[1:index] + args[index + 2:]
1615
+ else:
1616
+ args = [args[0]] + config_args + args[1:index] + args[index + 2:]
1617
+
1618
+ return args
1619
+
1620
+ def _load_config_file(self, file_path: str) -> list[str]:
1621
+ """Loads a yaml file and returns the key value pairs as a
1622
+ flattened list with argparse like pattern
1623
+ ```yaml
1624
+ port: 12323
1625
+ tensor-parallel-size: 4
1626
+ ```
1627
+ returns:
1628
+ processed_args: list[str] = [
1629
+ '--port': '12323',
1630
+ '--tensor-parallel-size': '4'
1631
+ ]
1632
+ """
1633
+ extension: str = file_path.split('.')[-1]
1634
+ if extension not in ('yaml', 'yml'):
1635
+ raise ValueError(
1636
+ "Config file must be of a yaml/yml type.\
1637
+ %s supplied", extension)
1638
+
1639
+ # only expecting a flat dictionary of atomic types
1640
+ processed_args: list[str] = []
1641
+
1642
+ config: dict[str, Union[int, str]] = {}
1643
+ try:
1644
+ with open(file_path) as config_file:
1645
+ config = yaml.safe_load(config_file)
1646
+ except Exception as ex:
1647
+ logger.error(
1648
+ "Unable to read the config file at %s. \
1649
+ Make sure path is correct", file_path)
1650
+ raise ex
1651
+
1652
+ store_boolean_arguments = [
1653
+ action.dest for action in self._actions
1654
+ if isinstance(action, StoreBoolean)
1655
+ ]
1656
+
1657
+ for key, value in config.items():
1658
+ if isinstance(value, bool) and key not in store_boolean_arguments:
1659
+ if value:
1660
+ processed_args.append('--' + key)
1661
+ else:
1662
+ processed_args.append('--' + key)
1663
+ processed_args.append(str(value))
1664
+
1665
+ return processed_args
1666
+
1667
+
1668
+ async def _run_task_with_lock(task: Callable, lock: asyncio.Lock, *args,
1669
+ **kwargs):
1670
+ """Utility function to run async task in a lock"""
1671
+ async with lock:
1672
+ return await task(*args, **kwargs)
1673
+
1674
+
1675
+ def supports_kw(
1676
+ callable: Callable[..., object],
1677
+ kw_name: str,
1678
+ *,
1679
+ requires_kw_only: bool = False,
1680
+ allow_var_kwargs: bool = True,
1681
+ ) -> bool:
1682
+ """Check if a keyword is a valid kwarg for a callable; if requires_kw_only
1683
+ disallows kwargs names that can also be positional arguments.
1684
+ """
1685
+ params = inspect.signature(callable).parameters
1686
+ if not params:
1687
+ return False
1688
+
1689
+ param_val = params.get(kw_name)
1690
+
1691
+ # Types where the it may be valid, i.e., explicitly defined & nonvariadic
1692
+ passable_kw_types = set((inspect.Parameter.POSITIONAL_ONLY,
1693
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
1694
+ inspect.Parameter.KEYWORD_ONLY))
1695
+
1696
+ if param_val:
1697
+ is_sig_param = param_val.kind in passable_kw_types
1698
+ # We want kwargs only, but this is passable as a positional arg
1699
+ if (requires_kw_only and is_sig_param
1700
+ and param_val.kind != inspect.Parameter.KEYWORD_ONLY):
1701
+ return False
1702
+ if ((requires_kw_only
1703
+ and param_val.kind == inspect.Parameter.KEYWORD_ONLY)
1704
+ or (not requires_kw_only and is_sig_param)):
1705
+ return True
1706
+
1707
+ # If we're okay with var-kwargs, it's supported as long as
1708
+ # the kw_name isn't something like *args, **kwargs
1709
+ if allow_var_kwargs:
1710
+ # Get the last param; type is ignored here because params is a proxy
1711
+ # mapping, but it wraps an ordered dict, and they appear in order.
1712
+ # Ref: https://docs.python.org/3/library/inspect.html#inspect.Signature.parameters
1713
+ last_param = params[next(reversed(params))] # type: ignore
1714
+ return (last_param.kind == inspect.Parameter.VAR_KEYWORD
1715
+ and last_param.name != kw_name)
1716
+ return False
1717
+
1718
+
1719
+ def resolve_mm_processor_kwargs(
1720
+ init_kwargs: Optional[Mapping[str, object]],
1721
+ inference_kwargs: Optional[Mapping[str, object]],
1722
+ callable: Callable[..., object],
1723
+ *,
1724
+ requires_kw_only: bool = True,
1725
+ allow_var_kwargs: bool = False,
1726
+ ) -> dict[str, Any]:
1727
+ """Applies filtering to eliminate invalid mm_processor_kwargs, i.e.,
1728
+ those who are not explicit keywords to the given callable (of one is
1729
+ given; otherwise no filtering is done), then merges the kwarg dicts,
1730
+ giving priority to inference_kwargs if there are any collisions.
1731
+
1732
+ In the case that no kwarg overrides are provided, returns an empty
1733
+ dict so that it can still be kwarg expanded into the callable later on.
1734
+
1735
+ If allow_var_kwargs=True, allows for things that can be expanded into
1736
+ kwargs as long as they aren't naming collision for var_kwargs or potential
1737
+ positional arguments.
1738
+ """
1739
+ # Filter inference time multimodal processor kwargs provided
1740
+ runtime_mm_kwargs = get_allowed_kwarg_only_overrides(
1741
+ callable,
1742
+ overrides=inference_kwargs,
1743
+ requires_kw_only=requires_kw_only,
1744
+ allow_var_kwargs=allow_var_kwargs,
1745
+ )
1746
+
1747
+ # Filter init time multimodal processor kwargs provided
1748
+ init_mm_kwargs = get_allowed_kwarg_only_overrides(
1749
+ callable,
1750
+ overrides=init_kwargs,
1751
+ requires_kw_only=requires_kw_only,
1752
+ allow_var_kwargs=allow_var_kwargs,
1753
+ )
1754
+
1755
+ # Merge the final processor kwargs, prioritizing inference
1756
+ # time values over the initialization time values.
1757
+ mm_processor_kwargs = {**init_mm_kwargs, **runtime_mm_kwargs}
1758
+ return mm_processor_kwargs
1759
+
1760
+
1761
+ def get_allowed_kwarg_only_overrides(
1762
+ callable: Callable[..., object],
1763
+ overrides: Optional[Mapping[str, object]],
1764
+ *,
1765
+ requires_kw_only: bool = True,
1766
+ allow_var_kwargs: bool = False,
1767
+ ) -> dict[str, Any]:
1768
+ """
1769
+ Given a callable which has one or more keyword only params and a dict
1770
+ mapping param names to values, drop values that can be not be kwarg
1771
+ expanded to overwrite one or more keyword-only args. This is used in a
1772
+ few places to handle custom processor overrides for multimodal models,
1773
+ e.g., for profiling when processor options provided by the user
1774
+ may affect the number of mm tokens per instance.
1775
+
1776
+ Args:
1777
+ callable: Callable which takes 0 or more keyword only arguments.
1778
+ If None is provided, all overrides names are allowed.
1779
+ overrides: Potential overrides to be used when invoking the callable.
1780
+ allow_var_kwargs: Allows overrides that are expandable for var kwargs.
1781
+
1782
+ Returns:
1783
+ Dictionary containing the kwargs to be leveraged which may be used
1784
+ to overwrite one or more keyword only arguments when invoking the
1785
+ callable.
1786
+ """
1787
+ if not overrides:
1788
+ return {}
1789
+
1790
+ # Drop any mm_processor_kwargs provided by the user that
1791
+ # are not kwargs, unless it can fit it var_kwargs param
1792
+ filtered_overrides = {
1793
+ kwarg_name: val
1794
+ for kwarg_name, val in overrides.items()
1795
+ if supports_kw(callable,
1796
+ kwarg_name,
1797
+ requires_kw_only=requires_kw_only,
1798
+ allow_var_kwargs=allow_var_kwargs)
1799
+ }
1800
+
1801
+ # If anything is dropped, log a warning
1802
+ dropped_keys = overrides.keys() - filtered_overrides.keys()
1803
+ if dropped_keys:
1804
+ if requires_kw_only:
1805
+ logger.warning(
1806
+ "The following intended overrides are not keyword-only args "
1807
+ "and will be dropped: %s", dropped_keys)
1808
+ else:
1809
+ logger.warning(
1810
+ "The following intended overrides are not keyword args "
1811
+ "and will be dropped: %s", dropped_keys)
1812
+
1813
+ return filtered_overrides
1814
+
1815
+
1816
+ # Using dynamo with vLLM doesn't really work well with PyTorch versions < 2.4.0.
1817
+ # In particular, the FakeScalarType is not supported for earlier versions of
1818
+ # PyTorch which breaks dynamo for any ops registered using ScalarType.
1819
+ def supports_dynamo() -> bool:
1820
+ base_torch_version = Version(Version(torch.__version__).base_version)
1821
+ return base_torch_version >= Version("2.4.0")
1822
+
1823
+
1824
+ # Some backends use pytorch version < 2.4.0 which doesn't
1825
+ # support `torch.library.custom_op`.
1826
+ def supports_custom_op() -> bool:
1827
+ return hasattr(torch.library, "custom_op")
1828
+
1829
+
1830
+ class AtomicCounter:
1831
+ """An atomic, thread-safe counter"""
1832
+
1833
+ def __init__(self, initial=0):
1834
+ """Initialize a new atomic counter to given initial value"""
1835
+ self._value = initial
1836
+ self._lock = threading.Lock()
1837
+
1838
+ def inc(self, num=1):
1839
+ """Atomically increment the counter by num and return the new value"""
1840
+ with self._lock:
1841
+ self._value += num
1842
+ return self._value
1843
+
1844
+ def dec(self, num=1):
1845
+ """Atomically decrement the counter by num and return the new value"""
1846
+ with self._lock:
1847
+ self._value -= num
1848
+ return self._value
1849
+
1850
+ @property
1851
+ def value(self):
1852
+ return self._value
1853
+
1854
+
1855
+ # Adapted from: https://stackoverflow.com/a/47212782/5082708
1856
+ class LazyDict(Mapping[str, T], Generic[T]):
1857
+
1858
+ def __init__(self, factory: dict[str, Callable[[], T]]):
1859
+ self._factory = factory
1860
+ self._dict: dict[str, T] = {}
1861
+
1862
+ def __getitem__(self, key: str) -> T:
1863
+ if key not in self._dict:
1864
+ if key not in self._factory:
1865
+ raise KeyError(key)
1866
+ self._dict[key] = self._factory[key]()
1867
+ return self._dict[key]
1868
+
1869
+ def __setitem__(self, key: str, value: Callable[[], T]):
1870
+ self._factory[key] = value
1871
+
1872
+ def __iter__(self):
1873
+ return iter(self._factory)
1874
+
1875
+ def __len__(self):
1876
+ return len(self._factory)
1877
+
1878
+
1879
+ class ClassRegistry(UserDict[Type[T], _V]):
1880
+
1881
+ def __getitem__(self, key: Type[T]) -> _V:
1882
+ for cls in key.mro():
1883
+ if cls in self.data:
1884
+ return self.data[cls]
1885
+
1886
+ raise KeyError(key)
1887
+
1888
+ def __contains__(self, key: object) -> bool:
1889
+ return self.contains(key)
1890
+
1891
+ def contains(self, key: object, *, strict: bool = False) -> bool:
1892
+ if not isinstance(key, type):
1893
+ return False
1894
+
1895
+ if strict:
1896
+ return key in self.data
1897
+
1898
+ return any(cls in self.data for cls in key.mro())
1899
+
1900
+
1901
+ def weak_ref_tensor(tensor: Any) -> Any:
1902
+ """
1903
+ Create a weak reference to a tensor.
1904
+ The new tensor will share the same data as the original tensor,
1905
+ but will not keep the original tensor alive.
1906
+ """
1907
+ if isinstance(tensor, torch.Tensor):
1908
+ return torch.ops._C.weak_ref_tensor(tensor)
1909
+ else:
1910
+ return tensor
1911
+
1912
+
1913
+ def weak_ref_tensors(
1914
+ tensors: Union[torch.Tensor, list[torch.Tensor], tuple[torch.Tensor]]
1915
+ ) -> Union[torch.Tensor, list[Any], tuple[Any], Any]:
1916
+ """
1917
+ Convenience function to create weak references to tensors,
1918
+ for single tensor, list of tensors or tuple of tensors.
1919
+ """
1920
+ if isinstance(tensors, torch.Tensor):
1921
+ return weak_ref_tensor(tensors)
1922
+ if isinstance(tensors, list):
1923
+ return [weak_ref_tensor(t) for t in tensors]
1924
+ if isinstance(tensors, tuple):
1925
+ return tuple(weak_ref_tensor(t) for t in tensors)
1926
+ raise ValueError("Invalid type for tensors")
1927
+
1928
+
1929
+ def get_cuda_view_from_cpu_tensor(cpu_tensor: torch.Tensor) -> torch.Tensor:
1930
+ """
1931
+ Get a CUDA view of a CPU tensor using Unified Virtual Addressing (UVA).
1932
+ """
1933
+ assert cpu_tensor.is_pinned(), "CPU tensor must be pinned"
1934
+ return torch.ops._C.get_cuda_view_from_cpu_tensor(cpu_tensor)
1935
+
1936
+
1937
+ def import_from_path(module_name: str, file_path: Union[str, os.PathLike]):
1938
+ """
1939
+ Import a Python file according to its file path.
1940
+
1941
+ Based on the official recipe:
1942
+ https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
1943
+ """
1944
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
1945
+ if spec is None:
1946
+ raise ModuleNotFoundError(f"No module named '{module_name}'")
1947
+
1948
+ assert spec.loader is not None
1949
+
1950
+ module = importlib.util.module_from_spec(spec)
1951
+ sys.modules[module_name] = module
1952
+ spec.loader.exec_module(module)
1953
+ return module
1954
+
1955
+
1956
+ @cache
1957
+ def get_vllm_optional_dependencies():
1958
+ metadata = importlib.metadata.metadata("vllm")
1959
+ requirements = metadata.get_all("Requires-Dist", [])
1960
+ extras = metadata.get_all("Provides-Extra", [])
1961
+
1962
+ return {
1963
+ extra: [
1964
+ re.split(r";|>=|<=|==", req)[0] for req in requirements
1965
+ if req.endswith(f'extra == "{extra}"')
1966
+ ]
1967
+ for extra in extras
1968
+ }
1969
+
1970
+
1971
+ class _PlaceholderBase:
1972
+ """
1973
+ Disallows downstream usage of placeholder modules.
1974
+
1975
+ We need to explicitly override each dunder method because
1976
+ [`__getattr__`][vllm.utils._PlaceholderBase.__getattr__]
1977
+ is not called when they are accessed.
1978
+
1979
+ Info:
1980
+ [Special method lookup](https://docs.python.org/3/reference/datamodel.html#special-lookup)
1981
+ """
1982
+
1983
+ def __getattr__(self, key: str) -> Never:
1984
+ """
1985
+ The main class should implement this to throw an error
1986
+ for attribute accesses representing downstream usage.
1987
+ """
1988
+ raise NotImplementedError
1989
+
1990
+ # [Basic customization]
1991
+
1992
+ def __lt__(self, other: object):
1993
+ return self.__getattr__("__lt__")
1994
+
1995
+ def __le__(self, other: object):
1996
+ return self.__getattr__("__le__")
1997
+
1998
+ def __eq__(self, other: object):
1999
+ return self.__getattr__("__eq__")
2000
+
2001
+ def __ne__(self, other: object):
2002
+ return self.__getattr__("__ne__")
2003
+
2004
+ def __gt__(self, other: object):
2005
+ return self.__getattr__("__gt__")
2006
+
2007
+ def __ge__(self, other: object):
2008
+ return self.__getattr__("__ge__")
2009
+
2010
+ def __hash__(self):
2011
+ return self.__getattr__("__hash__")
2012
+
2013
+ def __bool__(self):
2014
+ return self.__getattr__("__bool__")
2015
+
2016
+ # [Callable objects]
2017
+
2018
+ def __call__(self, *args: object, **kwargs: object):
2019
+ return self.__getattr__("__call__")
2020
+
2021
+ # [Container types]
2022
+
2023
+ def __len__(self):
2024
+ return self.__getattr__("__len__")
2025
+
2026
+ def __getitem__(self, key: object):
2027
+ return self.__getattr__("__getitem__")
2028
+
2029
+ def __setitem__(self, key: object, value: object):
2030
+ return self.__getattr__("__setitem__")
2031
+
2032
+ def __delitem__(self, key: object):
2033
+ return self.__getattr__("__delitem__")
2034
+
2035
+ # __missing__ is optional according to __getitem__ specification,
2036
+ # so it is skipped
2037
+
2038
+ # __iter__ and __reversed__ have a default implementation
2039
+ # based on __len__ and __getitem__, so they are skipped.
2040
+
2041
+ # [Numeric Types]
2042
+
2043
+ def __add__(self, other: object):
2044
+ return self.__getattr__("__add__")
2045
+
2046
+ def __sub__(self, other: object):
2047
+ return self.__getattr__("__sub__")
2048
+
2049
+ def __mul__(self, other: object):
2050
+ return self.__getattr__("__mul__")
2051
+
2052
+ def __matmul__(self, other: object):
2053
+ return self.__getattr__("__matmul__")
2054
+
2055
+ def __truediv__(self, other: object):
2056
+ return self.__getattr__("__truediv__")
2057
+
2058
+ def __floordiv__(self, other: object):
2059
+ return self.__getattr__("__floordiv__")
2060
+
2061
+ def __mod__(self, other: object):
2062
+ return self.__getattr__("__mod__")
2063
+
2064
+ def __divmod__(self, other: object):
2065
+ return self.__getattr__("__divmod__")
2066
+
2067
+ def __pow__(self, other: object, modulo: object = ...):
2068
+ return self.__getattr__("__pow__")
2069
+
2070
+ def __lshift__(self, other: object):
2071
+ return self.__getattr__("__lshift__")
2072
+
2073
+ def __rshift__(self, other: object):
2074
+ return self.__getattr__("__rshift__")
2075
+
2076
+ def __and__(self, other: object):
2077
+ return self.__getattr__("__and__")
2078
+
2079
+ def __xor__(self, other: object):
2080
+ return self.__getattr__("__xor__")
2081
+
2082
+ def __or__(self, other: object):
2083
+ return self.__getattr__("__or__")
2084
+
2085
+ # r* and i* methods have lower priority than
2086
+ # the methods for left operand so they are skipped
2087
+
2088
+ def __neg__(self):
2089
+ return self.__getattr__("__neg__")
2090
+
2091
+ def __pos__(self):
2092
+ return self.__getattr__("__pos__")
2093
+
2094
+ def __abs__(self):
2095
+ return self.__getattr__("__abs__")
2096
+
2097
+ def __invert__(self):
2098
+ return self.__getattr__("__invert__")
2099
+
2100
+ # __complex__, __int__ and __float__ have a default implementation
2101
+ # based on __index__, so they are skipped.
2102
+
2103
+ def __index__(self):
2104
+ return self.__getattr__("__index__")
2105
+
2106
+ def __round__(self, ndigits: object = ...):
2107
+ return self.__getattr__("__round__")
2108
+
2109
+ def __trunc__(self):
2110
+ return self.__getattr__("__trunc__")
2111
+
2112
+ def __floor__(self):
2113
+ return self.__getattr__("__floor__")
2114
+
2115
+ def __ceil__(self):
2116
+ return self.__getattr__("__ceil__")
2117
+
2118
+ # [Context managers]
2119
+
2120
+ def __enter__(self):
2121
+ return self.__getattr__("__enter__")
2122
+
2123
+ def __exit__(self, *args: object, **kwargs: object):
2124
+ return self.__getattr__("__exit__")
2125
+
2126
+
2127
+ class PlaceholderModule(_PlaceholderBase):
2128
+ """
2129
+ A placeholder object to use when a module does not exist.
2130
+
2131
+ This enables more informative errors when trying to access attributes
2132
+ of a module that does not exists.
2133
+ """
2134
+
2135
+ def __init__(self, name: str) -> None:
2136
+ super().__init__()
2137
+
2138
+ # Apply name mangling to avoid conflicting with module attributes
2139
+ self.__name = name
2140
+
2141
+ def placeholder_attr(self, attr_path: str):
2142
+ return _PlaceholderModuleAttr(self, attr_path)
2143
+
2144
+ def __getattr__(self, key: str):
2145
+ name = self.__name
2146
+
2147
+ try:
2148
+ importlib.import_module(name)
2149
+ except ImportError as exc:
2150
+ for extra, names in get_vllm_optional_dependencies().items():
2151
+ if name in names:
2152
+ msg = f"Please install vllm[{extra}] for {extra} support"
2153
+ raise ImportError(msg) from exc
2154
+
2155
+ raise exc
2156
+
2157
+ raise AssertionError("PlaceholderModule should not be used "
2158
+ "when the original module can be imported")
2159
+
2160
+
2161
+ class _PlaceholderModuleAttr(_PlaceholderBase):
2162
+
2163
+ def __init__(self, module: PlaceholderModule, attr_path: str) -> None:
2164
+ super().__init__()
2165
+
2166
+ # Apply name mangling to avoid conflicting with module attributes
2167
+ self.__module = module
2168
+ self.__attr_path = attr_path
2169
+
2170
+ def placeholder_attr(self, attr_path: str):
2171
+ return _PlaceholderModuleAttr(self.__module,
2172
+ f"{self.__attr_path}.{attr_path}")
2173
+
2174
+ def __getattr__(self, key: str):
2175
+ getattr(self.__module, f"{self.__attr_path}.{key}")
2176
+
2177
+ raise AssertionError("PlaceholderModule should not be used "
2178
+ "when the original module can be imported")
2179
+
2180
+
2181
+ # create a library to hold the custom op
2182
+ vllm_lib = Library("vllm", "FRAGMENT") # noqa
2183
+
2184
+
2185
+ def direct_register_custom_op(
2186
+ op_name: str,
2187
+ op_func: Callable,
2188
+ mutates_args: list[str],
2189
+ fake_impl: Optional[Callable] = None,
2190
+ target_lib: Optional[Library] = None,
2191
+ dispatch_key: str = "CUDA",
2192
+ tags: Tuple[torch.Tag, ...] = (),
2193
+ ):
2194
+ """
2195
+ `torch.library.custom_op` can have significant overhead because it
2196
+ needs to consider complicated dispatching logic. This function
2197
+ directly registers a custom op and dispatches it to the CUDA backend.
2198
+ See https://gist.github.com/youkaichao/ecbea9ec9fc79a45d2adce1784d7a9a5
2199
+ for more details.
2200
+
2201
+ By default, the custom op is registered to the vLLM library. If you
2202
+ want to register it to a different library, you can pass the library
2203
+ object to the `target_lib` argument.
2204
+
2205
+ IMPORTANT: the lifetime of the operator is tied to the lifetime of the
2206
+ library object. If you want to bind the operator to a different library,
2207
+ make sure the library object is alive when the operator is used.
2208
+ """
2209
+ if not supports_custom_op():
2210
+ from vllm.platforms import current_platform
2211
+ assert not current_platform.is_cuda_alike(), (
2212
+ "cuda platform needs torch>=2.4 to support custom op, "
2213
+ "chances are you are using an old version of pytorch "
2214
+ "or a custom build of pytorch. It is recommended to "
2215
+ "use vLLM in a fresh new environment and let it install "
2216
+ "the required dependencies.")
2217
+ return
2218
+
2219
+ import torch.library
2220
+ if hasattr(torch.library, "infer_schema"):
2221
+ schema_str = torch.library.infer_schema(op_func,
2222
+ mutates_args=mutates_args)
2223
+ else:
2224
+ # for pytorch 2.4
2225
+ import torch._custom_op.impl
2226
+ schema_str = torch._custom_op.impl.infer_schema(op_func, mutates_args)
2227
+ my_lib = target_lib or vllm_lib
2228
+ my_lib.define(op_name + schema_str, tags=tags)
2229
+ my_lib.impl(op_name, op_func, dispatch_key=dispatch_key)
2230
+ if fake_impl is not None:
2231
+ my_lib._register_fake(op_name, fake_impl)
2232
+
2233
+
2234
+ def resolve_obj_by_qualname(qualname: str) -> Any:
2235
+ """
2236
+ Resolve an object by its fully qualified name.
2237
+ """
2238
+ module_name, obj_name = qualname.rsplit(".", 1)
2239
+ module = importlib.import_module(module_name)
2240
+ return getattr(module, obj_name)
2241
+
2242
+
2243
+ def kill_process_tree(pid: int):
2244
+ """
2245
+ Kills all descendant processes of the given pid by sending SIGKILL.
2246
+
2247
+ Args:
2248
+ pid (int): Process ID of the parent process
2249
+ """
2250
+ try:
2251
+ parent = psutil.Process(pid)
2252
+ except psutil.NoSuchProcess:
2253
+ return
2254
+
2255
+ # Get all children recursively
2256
+ children = parent.children(recursive=True)
2257
+
2258
+ # Send SIGKILL to all children first
2259
+ for child in children:
2260
+ with contextlib.suppress(ProcessLookupError):
2261
+ os.kill(child.pid, signal.SIGKILL)
2262
+
2263
+ # Finally kill the parent
2264
+ with contextlib.suppress(ProcessLookupError):
2265
+ os.kill(pid, signal.SIGKILL)
2266
+
2267
+
2268
+ @dataclass
2269
+ class MemorySnapshot:
2270
+ """Memory snapshot."""
2271
+ torch_peak: int = 0
2272
+ free_memory: int = 0
2273
+ total_memory: int = 0
2274
+ cuda_memory: int = 0
2275
+ torch_memory: int = 0
2276
+ non_torch_memory: int = 0
2277
+ timestamp: float = 0.0
2278
+ auto_measure: bool = True
2279
+
2280
+ def __post_init__(self):
2281
+ if self.auto_measure:
2282
+ self.measure()
2283
+
2284
+ def measure(self):
2285
+ # we measure the torch peak memory usage via allocated_bytes,
2286
+ # rather than `torch.cuda.memory_reserved()` .
2287
+ # After `torch.cuda.reset_peak_memory_stats()`,
2288
+ # `torch.cuda.memory_reserved()` will keep growing, and only shrink
2289
+ # when we call `torch.cuda.empty_cache()` or OOM happens.
2290
+ self.torch_peak = torch.cuda.memory_stats().get(
2291
+ "allocated_bytes.all.peak", 0)
2292
+
2293
+ self.free_memory, self.total_memory = torch.cuda.mem_get_info()
2294
+ self.cuda_memory = self.total_memory - self.free_memory
2295
+
2296
+ # torch.cuda.memory_reserved() is how many bytes
2297
+ # PyTorch gets from cuda (by calling cudaMalloc, etc.)
2298
+ # this is used to measure the non-torch memory usage
2299
+ self.torch_memory = torch.cuda.memory_reserved()
2300
+
2301
+ self.non_torch_memory = self.cuda_memory - self.torch_memory
2302
+ self.timestamp = time.time()
2303
+
2304
+ def __sub__(self, other: MemorySnapshot) -> MemorySnapshot:
2305
+ return MemorySnapshot(
2306
+ torch_peak=self.torch_peak - other.torch_peak,
2307
+ free_memory=self.free_memory - other.free_memory,
2308
+ total_memory=self.total_memory - other.total_memory,
2309
+ cuda_memory=self.cuda_memory - other.cuda_memory,
2310
+ torch_memory=self.torch_memory - other.torch_memory,
2311
+ non_torch_memory=self.non_torch_memory - other.non_torch_memory,
2312
+ timestamp=self.timestamp - other.timestamp,
2313
+ auto_measure=False,
2314
+ )
2315
+
2316
+
2317
+ @dataclass
2318
+ class MemoryProfilingResult:
2319
+ """Memory profiling result. All numbers are in bytes.
2320
+ """
2321
+ non_kv_cache_memory: int = 0
2322
+ torch_peak_increase: int = 0
2323
+ non_torch_increase: int = 0
2324
+ weights_memory: float = 0
2325
+ before_create: MemorySnapshot = field(default_factory=MemorySnapshot)
2326
+ before_profile: MemorySnapshot = field(default_factory=MemorySnapshot)
2327
+ after_profile: MemorySnapshot = field(default_factory=MemorySnapshot)
2328
+ profile_time: float = 0.0
2329
+
2330
+ def __repr__(self) -> str:
2331
+ return (f"Memory profiling takes {self.profile_time:.2f} seconds. "
2332
+ f"Total non KV cache memory: "
2333
+ f"{(self.non_kv_cache_memory / GiB_bytes):.2f}GiB; "
2334
+ f"torch peak memory increase: "
2335
+ f"{(self.torch_peak_increase / GiB_bytes):.2f}GiB; "
2336
+ f"non-torch forward increase memory: "
2337
+ f"{(self.non_torch_increase / GiB_bytes):.2f}GiB; "
2338
+ f"weights memory: {(self.weights_memory / GiB_bytes):.2f}GiB.")
2339
+
2340
+
2341
+ @contextlib.contextmanager
2342
+ def memory_profiling(
2343
+ baseline_snapshot: MemorySnapshot,
2344
+ weights_memory: int) -> Generator[MemoryProfilingResult, None, None]:
2345
+ """Memory profiling context manager.
2346
+ baseline_snapshot: the memory snapshot before the current vLLM instance.
2347
+ weights_memory: memory used by PyTorch when loading the model weights.
2348
+ Note that, before loading the model weights, we also initialize the device
2349
+ and distributed environment, which may consume some memory. This part is not
2350
+ included in the weights_memory because PyTorch does not control it.
2351
+
2352
+ The memory in one GPU can be classified into 3 categories:
2353
+ 1. memory used by anything other than the current vLLM instance.
2354
+ 2. memory used by torch in the current vLLM instance.
2355
+ 3. memory used in the current vLLM instance, but not by torch.
2356
+
2357
+ A quantitive example:
2358
+
2359
+ Before creating the current vLLM instance:
2360
+ category 1: 1 GiB
2361
+ category 2: 0 GiB
2362
+ category 3: 0 GiB
2363
+
2364
+ After creating the current vLLM instance and loading the model,
2365
+ (i.e. before profiling):
2366
+ category 1: 1 GiB
2367
+ category 2: 2 GiB (model weights take 2 GiB)
2368
+ category 3: 0.5 GiB (memory used by NCCL)
2369
+
2370
+ During profiling (peak):
2371
+ category 1: 1 GiB
2372
+ category 2: 4 GiB (peak activation tensors take 2 GiB)
2373
+ category 3: 1 GiB (memory used by NCCL + buffers for some attention backends)
2374
+
2375
+ After profiling:
2376
+ category 1: 1 GiB
2377
+ category 2: 3 GiB (after garbage-collecting activation tensors)
2378
+ category 3: 1 GiB (memory used by NCCL + buffers for some attention backends)
2379
+
2380
+ In this case, non-kv cache takes 5 GiB in total, including:
2381
+ a. 2 GiB used by the model weights (category 2)
2382
+ b. 2 GiB reserved for the peak activation tensors (category 2)
2383
+ c. 1 GiB used by non-torch components (category 3)
2384
+
2385
+ The memory used for loading weights (a.) is directly given from the argument `weights_memory`.
2386
+
2387
+ The increase of `torch.cuda.memory_stats()["allocated_bytes.all.peak"]` during profiling gives (b.).
2388
+
2389
+ The increase of `non_torch_memory` from creating the current vLLM instance until after profiling to get (c.).
2390
+ """ # noqa
2391
+ gc.collect()
2392
+ torch.cuda.empty_cache()
2393
+ torch.cuda.reset_peak_memory_stats()
2394
+
2395
+ result = MemoryProfilingResult()
2396
+
2397
+ result.before_create = baseline_snapshot
2398
+ # the part of memory used for holding the model weights
2399
+ result.weights_memory = weights_memory
2400
+
2401
+ result.before_profile.measure()
2402
+
2403
+ yield result
2404
+
2405
+ gc.collect()
2406
+ torch.cuda.empty_cache()
2407
+
2408
+ result.after_profile.measure()
2409
+
2410
+ diff_profile = result.after_profile - result.before_profile
2411
+ diff_from_create = result.after_profile - result.before_create
2412
+ result.torch_peak_increase = diff_profile.torch_peak
2413
+ result.non_torch_increase = diff_from_create.non_torch_memory
2414
+ result.profile_time = diff_profile.timestamp
2415
+ result.non_kv_cache_memory = result.non_torch_increase + result.torch_peak_increase + result.weights_memory # noqa
2416
+
2417
+
2418
+ # Adapted from: https://github.com/sgl-project/sglang/blob/v0.4.1/python/sglang/srt/utils.py#L630 # noqa: E501
2419
+ def set_ulimit(target_soft_limit=65535):
2420
+ if sys.platform.startswith('win'):
2421
+ logger.info("Windows detected, skipping ulimit adjustment.")
2422
+ return
2423
+
2424
+ import resource
2425
+ resource_type = resource.RLIMIT_NOFILE
2426
+ current_soft, current_hard = resource.getrlimit(resource_type)
2427
+
2428
+ if current_soft < target_soft_limit:
2429
+ try:
2430
+ resource.setrlimit(resource_type,
2431
+ (target_soft_limit, current_hard))
2432
+ except ValueError as e:
2433
+ logger.warning(
2434
+ "Found ulimit of %s and failed to automatically increase "
2435
+ "with error %s. This can cause fd limit errors like "
2436
+ "`OSError: [Errno 24] Too many open files`. Consider "
2437
+ "increasing with ulimit -n", current_soft, e)
2438
+
2439
+
2440
+ # Adapted from: https://github.com/sgl-project/sglang/blob/v0.4.1/python/sglang/utils.py#L28 # noqa: E501
2441
+ def get_exception_traceback():
2442
+ etype, value, tb = sys.exc_info()
2443
+ err_str = "".join(traceback.format_exception(etype, value, tb))
2444
+ return err_str
2445
+
2446
+
2447
+ def split_zmq_path(path: str) -> Tuple[str, str, str]:
2448
+ """Split a zmq path into its parts."""
2449
+ parsed = urlparse(path)
2450
+ if not parsed.scheme:
2451
+ raise ValueError(f"Invalid zmq path: {path}")
2452
+
2453
+ scheme = parsed.scheme
2454
+ host = parsed.hostname or ""
2455
+ port = str(parsed.port or "")
2456
+
2457
+ if scheme == "tcp" and not all((host, port)):
2458
+ # The host and port fields are required for tcp
2459
+ raise ValueError(f"Invalid zmq path: {path}")
2460
+
2461
+ if scheme != "tcp" and port:
2462
+ # port only makes sense with tcp
2463
+ raise ValueError(f"Invalid zmq path: {path}")
2464
+
2465
+ return scheme, host, port
2466
+
2467
+
2468
+ def make_zmq_path(scheme: str, host: str, port: Optional[int] = None) -> str:
2469
+ """Make a ZMQ path from its parts.
2470
+
2471
+ Args:
2472
+ scheme: The ZMQ transport scheme (e.g. tcp, ipc, inproc).
2473
+ host: The host - can be an IPv4 address, IPv6 address, or hostname.
2474
+ port: Optional port number, only used for TCP sockets.
2475
+
2476
+ Returns:
2477
+ A properly formatted ZMQ path string.
2478
+ """
2479
+ if port is None:
2480
+ return f"{scheme}://{host}"
2481
+ if is_valid_ipv6_address(host):
2482
+ return f"{scheme}://[{host}]:{port}"
2483
+ return f"{scheme}://{host}:{port}"
2484
+
2485
+
2486
+ # Adapted from: https://github.com/sgl-project/sglang/blob/v0.4.1/python/sglang/srt/utils.py#L783 # noqa: E501
2487
+ def make_zmq_socket(
2488
+ ctx: Union[zmq.asyncio.Context, zmq.Context], # type: ignore[name-defined]
2489
+ path: str,
2490
+ socket_type: Any,
2491
+ bind: Optional[bool] = None,
2492
+ identity: Optional[bytes] = None,
2493
+ linger: Optional[int] = None,
2494
+ ) -> Union[zmq.Socket, zmq.asyncio.Socket]: # type: ignore[name-defined]
2495
+ """Make a ZMQ socket with the proper bind/connect semantics."""
2496
+
2497
+ mem = psutil.virtual_memory()
2498
+ socket = ctx.socket(socket_type)
2499
+
2500
+ # Calculate buffer size based on system memory
2501
+ total_mem = mem.total / 1024**3
2502
+ available_mem = mem.available / 1024**3
2503
+ # For systems with substantial memory (>32GB total, >16GB available):
2504
+ # - Set a large 0.5GB buffer to improve throughput
2505
+ # For systems with less memory:
2506
+ # - Use system default (-1) to avoid excessive memory consumption
2507
+ if total_mem > 32 and available_mem > 16:
2508
+ buf_size = int(0.5 * 1024**3) # 0.5GB in bytes
2509
+ else:
2510
+ buf_size = -1 # Use system default buffer size
2511
+
2512
+ if bind is None:
2513
+ bind = socket_type not in (zmq.PUSH, zmq.SUB, zmq.XSUB)
2514
+
2515
+ if socket_type in (zmq.PULL, zmq.DEALER, zmq.ROUTER):
2516
+ socket.setsockopt(zmq.RCVHWM, 0)
2517
+ socket.setsockopt(zmq.RCVBUF, buf_size)
2518
+
2519
+ if socket_type in (zmq.PUSH, zmq.DEALER, zmq.ROUTER):
2520
+ socket.setsockopt(zmq.SNDHWM, 0)
2521
+ socket.setsockopt(zmq.SNDBUF, buf_size)
2522
+
2523
+ if identity is not None:
2524
+ socket.setsockopt(zmq.IDENTITY, identity)
2525
+
2526
+ if linger is not None:
2527
+ socket.setsockopt(zmq.LINGER, linger)
2528
+
2529
+ # Determine if the path is a TCP socket with an IPv6 address.
2530
+ # Enable IPv6 on the zmq socket if so.
2531
+ scheme, host, _ = split_zmq_path(path)
2532
+ if scheme == "tcp" and is_valid_ipv6_address(host):
2533
+ socket.setsockopt(zmq.IPV6, 1)
2534
+
2535
+ if bind:
2536
+ socket.bind(path)
2537
+ else:
2538
+ socket.connect(path)
2539
+
2540
+ return socket
2541
+
2542
+
2543
+ @contextlib.contextmanager
2544
+ def zmq_socket_ctx(
2545
+ path: str,
2546
+ socket_type: Any,
2547
+ bind: Optional[bool] = None,
2548
+ linger: int = 0,
2549
+ identity: Optional[bytes] = None,
2550
+ ) -> Iterator[zmq.Socket]:
2551
+ """Context manager for a ZMQ socket"""
2552
+
2553
+ ctx = zmq.Context() # type: ignore[attr-defined]
2554
+ try:
2555
+ yield make_zmq_socket(ctx,
2556
+ path,
2557
+ socket_type,
2558
+ bind=bind,
2559
+ identity=identity)
2560
+ except KeyboardInterrupt:
2561
+ logger.debug("Got Keyboard Interrupt.")
2562
+
2563
+ finally:
2564
+ ctx.destroy(linger=linger)
2565
+
2566
+
2567
+ def is_in_ray_actor():
2568
+ """Check if we are in a Ray actor."""
2569
+
2570
+ try:
2571
+ import ray
2572
+ return (ray.is_initialized()
2573
+ and ray.get_runtime_context().get_actor_id() is not None)
2574
+ except ImportError:
2575
+ return False
2576
+
2577
+
2578
+ def _maybe_force_spawn():
2579
+ """Check if we need to force the use of the `spawn` multiprocessing start
2580
+ method.
2581
+ """
2582
+ if os.environ.get("VLLM_WORKER_MULTIPROC_METHOD") == "spawn":
2583
+ return
2584
+
2585
+ reason = None
2586
+ if cuda_is_initialized():
2587
+ reason = "CUDA is initialized"
2588
+ elif is_in_ray_actor():
2589
+ # even if we choose to spawn, we need to pass the ray address
2590
+ # to the subprocess so that it knows how to connect to the ray cluster.
2591
+ # env vars are inherited by subprocesses, even if we use spawn.
2592
+ import ray
2593
+ os.environ["RAY_ADDRESS"] = ray.get_runtime_context().gcs_address
2594
+ reason = "In a Ray actor and can only be spawned"
2595
+
2596
+ if reason is not None:
2597
+ logger.warning(
2598
+ "We must use the `spawn` multiprocessing start method. "
2599
+ "Overriding VLLM_WORKER_MULTIPROC_METHOD to 'spawn'. "
2600
+ "See https://docs.vllm.ai/en/latest/usage/"
2601
+ "troubleshooting.html#python-multiprocessing "
2602
+ "for more information. Reason: %s", reason)
2603
+ os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
2604
+
2605
+
2606
+ def get_mp_context():
2607
+ """Get a multiprocessing context with a particular method (spawn or fork).
2608
+ By default we follow the value of the VLLM_WORKER_MULTIPROC_METHOD to
2609
+ determine the multiprocessing method (default is fork). However, under
2610
+ certain conditions, we may enforce spawn and override the value of
2611
+ VLLM_WORKER_MULTIPROC_METHOD.
2612
+ """
2613
+ _maybe_force_spawn()
2614
+ mp_method = envs.VLLM_WORKER_MULTIPROC_METHOD
2615
+ return multiprocessing.get_context(mp_method)
2616
+
2617
+
2618
+ def bind_kv_cache(
2619
+ ctx: dict[str, Any],
2620
+ kv_cache: list[list[torch.Tensor]], # [virtual_engine][layer_index]
2621
+ ) -> None:
2622
+ # Bind the kv_cache tensor to Attention modules, similar to
2623
+ # ctx[layer_name].kv_cache[ve]=kv_cache[ve][extract_layer_index(layer_name)]
2624
+ # Special things handled here:
2625
+ # 1. Some models have non-attention layers, e.g., Jamba
2626
+ # 2. Pipeline parallelism, each rank only has a subset of layers
2627
+ # 3. Encoder attention has no kv cache
2628
+ # 4. Encoder-decoder models, encoder-decoder attention and decoder-only
2629
+ # attention of the same layer (e.g., bart's decoder.layers.1.self_attn
2630
+ # and decoder.layers.1.encoder_attn) is mapped to the same kv cache
2631
+ # tensor
2632
+ from vllm.attention import AttentionType
2633
+ from vllm.model_executor.models.utils import extract_layer_index
2634
+ layer_need_kv_cache = [
2635
+ layer_name for layer_name in ctx
2636
+ if (hasattr(ctx[layer_name], 'attn_type') and ctx[layer_name].attn_type
2637
+ in (AttentionType.DECODER, AttentionType.ENCODER_DECODER))
2638
+ ]
2639
+ layer_index_sorted = sorted(
2640
+ set(
2641
+ extract_layer_index(layer_name)
2642
+ for layer_name in layer_need_kv_cache))
2643
+ for layer_name in layer_need_kv_cache:
2644
+ kv_cache_idx = layer_index_sorted.index(
2645
+ extract_layer_index(layer_name))
2646
+ forward_ctx = ctx[layer_name]
2647
+ assert len(forward_ctx.kv_cache) == len(kv_cache)
2648
+ for ve, ve_kv_cache in enumerate(kv_cache):
2649
+ forward_ctx.kv_cache[ve] = ve_kv_cache[kv_cache_idx]
2650
+
2651
+
2652
+ def run_method(obj: Any, method: Union[str, bytes, Callable], args: tuple[Any],
2653
+ kwargs: dict[str, Any]) -> Any:
2654
+ """
2655
+ Run a method of an object with the given arguments and keyword arguments.
2656
+ If the method is string, it will be converted to a method using getattr.
2657
+ If the method is serialized bytes and will be deserialized using
2658
+ cloudpickle.
2659
+ If the method is a callable, it will be called directly.
2660
+ """
2661
+ if isinstance(method, bytes):
2662
+ func = partial(cloudpickle.loads(method), obj)
2663
+ elif isinstance(method, str):
2664
+ try:
2665
+ func = getattr(obj, method)
2666
+ except AttributeError:
2667
+ raise NotImplementedError(f"Method {method!r} is not"
2668
+ " implemented.") from None
2669
+ else:
2670
+ func = partial(method, obj) # type: ignore
2671
+ return func(*args, **kwargs)
2672
+
2673
+
2674
+ def import_pynvml():
2675
+ """
2676
+ Historical comments:
2677
+
2678
+ libnvml.so is the library behind nvidia-smi, and
2679
+ pynvml is a Python wrapper around it. We use it to get GPU
2680
+ status without initializing CUDA context in the current process.
2681
+ Historically, there are two packages that provide pynvml:
2682
+ - `nvidia-ml-py` (https://pypi.org/project/nvidia-ml-py/): The official
2683
+ wrapper. It is a dependency of vLLM, and is installed when users
2684
+ install vLLM. It provides a Python module named `pynvml`.
2685
+ - `pynvml` (https://pypi.org/project/pynvml/): An unofficial wrapper.
2686
+ Prior to version 12.0, it also provides a Python module `pynvml`,
2687
+ and therefore conflicts with the official one. What's worse,
2688
+ the module is a Python package, and has higher priority than
2689
+ the official one which is a standalone Python file.
2690
+ This causes errors when both of them are installed.
2691
+ Starting from version 12.0, it migrates to a new module
2692
+ named `pynvml_utils` to avoid the conflict.
2693
+ It is so confusing that many packages in the community use the
2694
+ unofficial one by mistake, and we have to handle this case.
2695
+ For example, `nvcr.io/nvidia/pytorch:24.12-py3` uses the unofficial
2696
+ one, and it will cause errors, see the issue
2697
+ https://github.com/vllm-project/vllm/issues/12847 for example.
2698
+ After all the troubles, we decide to copy the official `pynvml`
2699
+ module to our codebase, and use it directly.
2700
+ """
2701
+ import vllm.third_party.pynvml as pynvml
2702
+ return pynvml
2703
+
2704
+
2705
+ def warn_for_unimplemented_methods(cls: type[T]) -> type[T]:
2706
+ """
2707
+ A replacement for `abc.ABC`.
2708
+ When we use `abc.ABC`, subclasses will fail to instantiate
2709
+ if they do not implement all abstract methods.
2710
+ Here, we only require `raise NotImplementedError` in the
2711
+ base class, and log a warning if the method is not implemented
2712
+ in the subclass.
2713
+ """
2714
+
2715
+ original_init = cls.__init__
2716
+
2717
+ def find_unimplemented_methods(self: object):
2718
+ unimplemented_methods = []
2719
+ for attr_name in dir(self):
2720
+ # bypass inner method
2721
+ if attr_name.startswith('_'):
2722
+ continue
2723
+
2724
+ try:
2725
+ attr = getattr(self, attr_name)
2726
+ # get the func of callable method
2727
+ if callable(attr):
2728
+ attr_func = attr.__func__
2729
+ except AttributeError:
2730
+ continue
2731
+ src = inspect.getsource(attr_func)
2732
+ if "NotImplementedError" in src:
2733
+ unimplemented_methods.append(attr_name)
2734
+ if unimplemented_methods:
2735
+ method_names = ','.join(unimplemented_methods)
2736
+ msg = (f"Methods {method_names} not implemented in {self}")
2737
+ logger.warning(msg)
2738
+
2739
+ @wraps(original_init)
2740
+ def wrapped_init(self, *args, **kwargs) -> None:
2741
+ original_init(self, *args, **kwargs)
2742
+ find_unimplemented_methods(self)
2743
+
2744
+ type.__setattr__(cls, '__init__', wrapped_init)
2745
+ return cls
2746
+
2747
+
2748
+ class LazyLoader(types.ModuleType):
2749
+ """
2750
+ LazyLoader module borrowed from Tensorflow
2751
+ https://github.com/tensorflow/tensorflow/blob/main/tensorflow/python/util/lazy_loader.py
2752
+ with a addition of "module caching".
2753
+
2754
+ Lazily import a module, mainly to avoid pulling in large dependencies.
2755
+ Modules such as `xgrammar` might do additional side effects, so we
2756
+ only want to use this when it is needed, delaying all eager effects
2757
+ """
2758
+
2759
+ def __init__(
2760
+ self,
2761
+ local_name: str,
2762
+ parent_module_globals: dict[str, Any],
2763
+ name: str,
2764
+ ):
2765
+ self._local_name = local_name
2766
+ self._parent_module_globals = parent_module_globals
2767
+ self._module: types.ModuleType | None = None
2768
+
2769
+ super().__init__(str(name))
2770
+
2771
+ def _load(self) -> types.ModuleType:
2772
+ # Import the target module and insert it into the parent's namespace
2773
+ try:
2774
+ module = importlib.import_module(self.__name__)
2775
+ self._parent_module_globals[self._local_name] = module
2776
+ # The additional add to sys.modules
2777
+ # ensures library is actually loaded.
2778
+ sys.modules[self._local_name] = module
2779
+ except ModuleNotFoundError as err:
2780
+ raise err from None
2781
+
2782
+ # Update this object's dict so that if someone keeps a
2783
+ # reference to the LazyLoader, lookups are efficient
2784
+ # (__getattr__ is only called on lookups that fail).
2785
+ self.__dict__.update(module.__dict__)
2786
+ return module
2787
+
2788
+ def __getattr__(self, item: Any) -> Any:
2789
+ if self._module is None:
2790
+ self._module = self._load()
2791
+ return getattr(self._module, item)
2792
+
2793
+ def __dir__(self) -> list[str]:
2794
+ if self._module is None:
2795
+ self._module = self._load()
2796
+ return dir(self._module)
2797
+
2798
+
2799
+ def swap_dict_values(obj: dict[_K, _V], key1: _K, key2: _K) -> None:
2800
+ """
2801
+ Helper function to swap values for two keys
2802
+ """
2803
+ v1 = obj.get(key1)
2804
+ v2 = obj.get(key2)
2805
+ if v1 is not None:
2806
+ obj[key2] = v1
2807
+ else:
2808
+ obj.pop(key2, None)
2809
+ if v2 is not None:
2810
+ obj[key1] = v2
2811
+ else:
2812
+ obj.pop(key1, None)
2813
+
2814
+
2815
+ @contextlib.contextmanager
2816
+ def cprofile_context(save_file: Optional[str] = None):
2817
+ """Run a cprofile
2818
+
2819
+ Args:
2820
+ save_file: path to save the profile result. "1" or
2821
+ None will result in printing to stdout.
2822
+ """
2823
+ import cProfile
2824
+
2825
+ prof = cProfile.Profile()
2826
+ prof.enable()
2827
+
2828
+ try:
2829
+ yield
2830
+ finally:
2831
+ prof.disable()
2832
+ if save_file and save_file != "1":
2833
+ prof.dump_stats(save_file)
2834
+ else:
2835
+ prof.print_stats(sort="cumtime")
2836
+
2837
+
2838
+ def cprofile(save_file: Optional[str] = None, enabled: bool = True):
2839
+ """Decorator to profile a Python method using cProfile.
2840
+
2841
+ Args:
2842
+ save_file: Path to save the profile result.
2843
+ If "1", None, or "", results will be printed to stdout.
2844
+ enabled: Set to false to turn this into a no-op
2845
+ """
2846
+
2847
+ def decorator(func: Callable):
2848
+
2849
+ @wraps(func)
2850
+ def wrapper(*args, **kwargs):
2851
+ if not enabled:
2852
+ # If profiling is disabled, just call the function directly.
2853
+ return func(*args, **kwargs)
2854
+
2855
+ with cprofile_context(save_file):
2856
+ return func(*args, **kwargs)
2857
+
2858
+ return wrapper
2859
+
2860
+ return decorator
2861
+
2862
+
2863
+ # Only relevant for models using ALiBi (e.g, MPT)
2864
+ def check_use_alibi(model_config: ModelConfig) -> bool:
2865
+ cfg = model_config.hf_text_config
2866
+ return (getattr(cfg, "alibi", False) # Falcon
2867
+ or ("BloomForCausalLM" in getattr(model_config.hf_config,
2868
+ "architectures", [])) # Bloom
2869
+ or getattr(cfg, "position_encoding_type", "") ==
2870
+ "alibi" # codellm_1b_alibi
2871
+ or (hasattr(cfg, "attn_config") # MPT
2872
+ and ((isinstance(cfg.attn_config, dict)
2873
+ and cfg.attn_config.get("alibi", False)) or
2874
+ (not isinstance(cfg.attn_config, dict)
2875
+ and getattr(cfg.attn_config, "alibi", False)))))
2876
+
2877
+
2878
+ def sha256(input) -> int:
2879
+ """Hash any picklable Python object using SHA-256.
2880
+
2881
+ The input is serialized using pickle before hashing, which allows
2882
+ arbitrary Python objects to be used. Note that this function does
2883
+ not use a hash seed—if you need one, prepend it explicitly to the input.
2884
+
2885
+ Args:
2886
+ input: Any picklable Python object.
2887
+
2888
+ Returns:
2889
+ An integer representing the SHA-256 hash of the serialized input.
2890
+ """
2891
+ input_bytes = pickle.dumps(input, protocol=pickle.HIGHEST_PROTOCOL)
2892
+ return int.from_bytes(hashlib.sha256(input_bytes).digest(),
2893
+ byteorder="big")
2894
+
2895
+
2896
+ def is_torch_equal_or_newer(target: str) -> bool:
2897
+ """Check if the installed torch version is >= the target version.
2898
+
2899
+ Args:
2900
+ target: a version string, like "2.6.0".
2901
+
2902
+ Returns:
2903
+ Whether the condition meets.
2904
+ """
2905
+ try:
2906
+ torch_version = version.parse(str(torch.__version__))
2907
+ return torch_version >= version.parse(target)
2908
+ except Exception:
2909
+ # Fallback to PKG-INFO to load the package info, needed by the doc gen.
2910
+ return Version(importlib.metadata.version('torch')) >= Version(target)