vllm-cpu-avx512bf16 0.9.0.post2__cp310-cp310-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 (1175) hide show
  1. vllm/_C.abi3.so +0 -0
  2. vllm/__init__.py +170 -0
  3. vllm/_custom_ops.py +1742 -0
  4. vllm/_ipex_ops.py +243 -0
  5. vllm/_version.py +34 -0
  6. vllm/adapter_commons/__init__.py +0 -0
  7. vllm/adapter_commons/layers.py +15 -0
  8. vllm/adapter_commons/models.py +105 -0
  9. vllm/adapter_commons/request.py +25 -0
  10. vllm/adapter_commons/utils.py +92 -0
  11. vllm/adapter_commons/worker_manager.py +38 -0
  12. vllm/assets/__init__.py +0 -0
  13. vllm/assets/audio.py +44 -0
  14. vllm/assets/base.py +40 -0
  15. vllm/assets/image.py +33 -0
  16. vllm/assets/video.py +114 -0
  17. vllm/attention/__init__.py +19 -0
  18. vllm/attention/backends/__init__.py +0 -0
  19. vllm/attention/backends/abstract.py +306 -0
  20. vllm/attention/backends/blocksparse_attn.py +457 -0
  21. vllm/attention/backends/cpu_mla.py +305 -0
  22. vllm/attention/backends/dual_chunk_flash_attn.py +1494 -0
  23. vllm/attention/backends/flash_attn.py +999 -0
  24. vllm/attention/backends/flashinfer.py +1100 -0
  25. vllm/attention/backends/flashmla.py +242 -0
  26. vllm/attention/backends/hpu_attn.py +309 -0
  27. vllm/attention/backends/ipex_attn.py +394 -0
  28. vllm/attention/backends/mla/__init__.py +0 -0
  29. vllm/attention/backends/mla/common.py +1381 -0
  30. vllm/attention/backends/pallas.py +347 -0
  31. vllm/attention/backends/placeholder_attn.py +399 -0
  32. vllm/attention/backends/rocm_aiter_mla.py +435 -0
  33. vllm/attention/backends/rocm_flash_attn.py +970 -0
  34. vllm/attention/backends/torch_sdpa.py +691 -0
  35. vllm/attention/backends/triton_mla.py +113 -0
  36. vllm/attention/backends/utils.py +609 -0
  37. vllm/attention/backends/xformers.py +798 -0
  38. vllm/attention/layer.py +452 -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 +432 -0
  42. vllm/attention/ops/blocksparse_attention/interface.py +238 -0
  43. vllm/attention/ops/blocksparse_attention/utils.py +245 -0
  44. vllm/attention/ops/chunked_prefill_paged_decode.py +367 -0
  45. vllm/attention/ops/flashmla.py +115 -0
  46. vllm/attention/ops/hpu_paged_attn.py +87 -0
  47. vllm/attention/ops/ipex_attn.py +194 -0
  48. vllm/attention/ops/merge_attn_states.py +42 -0
  49. vllm/attention/ops/nki_flash_attn.py +905 -0
  50. vllm/attention/ops/paged_attn.py +255 -0
  51. vllm/attention/ops/prefix_prefill.py +901 -0
  52. vllm/attention/ops/rocm_aiter_mla.py +99 -0
  53. vllm/attention/ops/rocm_aiter_paged_attn.py +101 -0
  54. vllm/attention/ops/triton_decode_attention.py +673 -0
  55. vllm/attention/ops/triton_flash_attention.py +1374 -0
  56. vllm/attention/ops/triton_merge_attn_states.py +96 -0
  57. vllm/attention/ops/triton_unified_attention.py +337 -0
  58. vllm/attention/selector.py +186 -0
  59. vllm/attention/utils/fa_utils.py +54 -0
  60. vllm/beam_search.py +82 -0
  61. vllm/benchmarks/__init__.py +0 -0
  62. vllm/benchmarks/datasets.py +921 -0
  63. vllm/benchmarks/endpoint_request_func.py +160 -0
  64. vllm/benchmarks/latency.py +184 -0
  65. vllm/benchmarks/serve.py +925 -0
  66. vllm/benchmarks/throughput.py +609 -0
  67. vllm/benchmarks/utils.py +69 -0
  68. vllm/collect_env.py +818 -0
  69. vllm/compilation/__init__.py +0 -0
  70. vllm/compilation/activation_quant_fusion.py +88 -0
  71. vllm/compilation/backends.py +560 -0
  72. vllm/compilation/base_piecewise_backend.py +71 -0
  73. vllm/compilation/collective_fusion.py +126 -0
  74. vllm/compilation/compiler_interface.py +533 -0
  75. vllm/compilation/counter.py +33 -0
  76. vllm/compilation/cuda_piecewise_backend.py +213 -0
  77. vllm/compilation/decorators.py +249 -0
  78. vllm/compilation/fix_functionalization.py +190 -0
  79. vllm/compilation/fusion.py +617 -0
  80. vllm/compilation/fx_utils.py +61 -0
  81. vllm/compilation/inductor_pass.py +114 -0
  82. vllm/compilation/monitor.py +38 -0
  83. vllm/compilation/multi_output_match.py +108 -0
  84. vllm/compilation/noop_elimination.py +136 -0
  85. vllm/compilation/pass_manager.py +77 -0
  86. vllm/compilation/sequence_parallelism.py +267 -0
  87. vllm/compilation/torch25_custom_graph_pass.py +41 -0
  88. vllm/compilation/vllm_inductor_pass.py +66 -0
  89. vllm/compilation/wrapper.py +129 -0
  90. vllm/config.py +4600 -0
  91. vllm/connections.py +173 -0
  92. vllm/core/__init__.py +0 -0
  93. vllm/core/block/__init__.py +0 -0
  94. vllm/core/block/block_table.py +398 -0
  95. vllm/core/block/common.py +370 -0
  96. vllm/core/block/cpu_gpu_block_allocator.py +440 -0
  97. vllm/core/block/interfaces.py +318 -0
  98. vllm/core/block/naive_block.py +465 -0
  99. vllm/core/block/prefix_caching_block.py +1134 -0
  100. vllm/core/block/utils.py +27 -0
  101. vllm/core/block_manager.py +520 -0
  102. vllm/core/evictor.py +156 -0
  103. vllm/core/interfaces.py +134 -0
  104. vllm/core/placeholder_block_space_manager.py +99 -0
  105. vllm/core/scheduler.py +2092 -0
  106. vllm/device_allocator/__init__.py +0 -0
  107. vllm/device_allocator/cumem.py +280 -0
  108. vllm/distributed/__init__.py +5 -0
  109. vllm/distributed/communication_op.py +40 -0
  110. vllm/distributed/device_communicators/__init__.py +0 -0
  111. vllm/distributed/device_communicators/all2all.py +126 -0
  112. vllm/distributed/device_communicators/base_device_communicator.py +260 -0
  113. vllm/distributed/device_communicators/cpu_communicator.py +144 -0
  114. vllm/distributed/device_communicators/cuda_communicator.py +167 -0
  115. vllm/distributed/device_communicators/cuda_wrapper.py +179 -0
  116. vllm/distributed/device_communicators/custom_all_reduce.py +303 -0
  117. vllm/distributed/device_communicators/custom_all_reduce_utils.py +258 -0
  118. vllm/distributed/device_communicators/hpu_communicator.py +45 -0
  119. vllm/distributed/device_communicators/neuron_communicator.py +19 -0
  120. vllm/distributed/device_communicators/pynccl.py +217 -0
  121. vllm/distributed/device_communicators/pynccl_wrapper.py +340 -0
  122. vllm/distributed/device_communicators/shm_broadcast.py +541 -0
  123. vllm/distributed/device_communicators/tpu_communicator.py +102 -0
  124. vllm/distributed/device_communicators/xpu_communicator.py +54 -0
  125. vllm/distributed/kv_events.py +296 -0
  126. vllm/distributed/kv_transfer/README.md +29 -0
  127. vllm/distributed/kv_transfer/__init__.py +11 -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 +127 -0
  131. vllm/distributed/kv_transfer/kv_connector/factory.py +126 -0
  132. vllm/distributed/kv_transfer/kv_connector/lmcache_connector.py +98 -0
  133. vllm/distributed/kv_transfer/kv_connector/mooncake_store_connector.py +202 -0
  134. vllm/distributed/kv_transfer/kv_connector/simple_connector.py +328 -0
  135. vllm/distributed/kv_transfer/kv_connector/utils.py +91 -0
  136. vllm/distributed/kv_transfer/kv_connector/v1/__init__.py +5 -0
  137. vllm/distributed/kv_transfer/kv_connector/v1/base.py +259 -0
  138. vllm/distributed/kv_transfer/kv_connector/v1/lmcache_connector.py +133 -0
  139. vllm/distributed/kv_transfer/kv_connector/v1/multi_connector.py +189 -0
  140. vllm/distributed/kv_transfer/kv_connector/v1/nixl_connector.py +851 -0
  141. vllm/distributed/kv_transfer/kv_connector/v1/shared_storage_connector.py +383 -0
  142. vllm/distributed/kv_transfer/kv_connector_agent.py +76 -0
  143. vllm/distributed/kv_transfer/kv_lookup_buffer/__init__.py +0 -0
  144. vllm/distributed/kv_transfer/kv_lookup_buffer/base.py +174 -0
  145. vllm/distributed/kv_transfer/kv_lookup_buffer/mooncake_store.py +160 -0
  146. vllm/distributed/kv_transfer/kv_lookup_buffer/simple_buffer.py +236 -0
  147. vllm/distributed/kv_transfer/kv_pipe/__init__.py +0 -0
  148. vllm/distributed/kv_transfer/kv_pipe/base.py +66 -0
  149. vllm/distributed/kv_transfer/kv_pipe/mooncake_pipe.py +279 -0
  150. vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py +279 -0
  151. vllm/distributed/kv_transfer/kv_transfer_state.py +70 -0
  152. vllm/distributed/parallel_state.py +1294 -0
  153. vllm/distributed/utils.py +520 -0
  154. vllm/engine/__init__.py +0 -0
  155. vllm/engine/arg_utils.py +1649 -0
  156. vllm/engine/async_llm_engine.py +1274 -0
  157. vllm/engine/async_timeout.py +191 -0
  158. vllm/engine/llm_engine.py +2153 -0
  159. vllm/engine/metrics.py +717 -0
  160. vllm/engine/metrics_types.py +96 -0
  161. vllm/engine/multiprocessing/__init__.py +188 -0
  162. vllm/engine/multiprocessing/client.py +755 -0
  163. vllm/engine/multiprocessing/engine.py +459 -0
  164. vllm/engine/output_processor/__init__.py +0 -0
  165. vllm/engine/output_processor/interfaces.py +74 -0
  166. vllm/engine/output_processor/multi_step.py +215 -0
  167. vllm/engine/output_processor/single_step.py +144 -0
  168. vllm/engine/output_processor/stop_checker.py +130 -0
  169. vllm/engine/output_processor/util.py +27 -0
  170. vllm/engine/protocol.py +310 -0
  171. vllm/entrypoints/__init__.py +0 -0
  172. vllm/entrypoints/api_server.py +177 -0
  173. vllm/entrypoints/chat_utils.py +1298 -0
  174. vllm/entrypoints/cli/__init__.py +0 -0
  175. vllm/entrypoints/cli/benchmark/__init__.py +0 -0
  176. vllm/entrypoints/cli/benchmark/base.py +38 -0
  177. vllm/entrypoints/cli/benchmark/latency.py +29 -0
  178. vllm/entrypoints/cli/benchmark/main.py +53 -0
  179. vllm/entrypoints/cli/benchmark/serve.py +29 -0
  180. vllm/entrypoints/cli/benchmark/throughput.py +29 -0
  181. vllm/entrypoints/cli/collect_env.py +34 -0
  182. vllm/entrypoints/cli/main.py +62 -0
  183. vllm/entrypoints/cli/openai.py +204 -0
  184. vllm/entrypoints/cli/serve.py +141 -0
  185. vllm/entrypoints/cli/types.py +24 -0
  186. vllm/entrypoints/launcher.py +146 -0
  187. vllm/entrypoints/llm.py +1503 -0
  188. vllm/entrypoints/logger.py +49 -0
  189. vllm/entrypoints/openai/__init__.py +0 -0
  190. vllm/entrypoints/openai/api_server.py +1376 -0
  191. vllm/entrypoints/openai/cli_args.py +306 -0
  192. vllm/entrypoints/openai/logits_processors.py +89 -0
  193. vllm/entrypoints/openai/protocol.py +1890 -0
  194. vllm/entrypoints/openai/run_batch.py +439 -0
  195. vllm/entrypoints/openai/serving_chat.py +1192 -0
  196. vllm/entrypoints/openai/serving_classification.py +159 -0
  197. vllm/entrypoints/openai/serving_completion.py +590 -0
  198. vllm/entrypoints/openai/serving_embedding.py +200 -0
  199. vllm/entrypoints/openai/serving_engine.py +985 -0
  200. vllm/entrypoints/openai/serving_models.py +314 -0
  201. vllm/entrypoints/openai/serving_pooling.py +231 -0
  202. vllm/entrypoints/openai/serving_score.py +432 -0
  203. vllm/entrypoints/openai/serving_tokenization.py +151 -0
  204. vllm/entrypoints/openai/serving_transcription.py +421 -0
  205. vllm/entrypoints/openai/tool_parsers/__init__.py +22 -0
  206. vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py +163 -0
  207. vllm/entrypoints/openai/tool_parsers/deepseekv3_tool_parser.py +369 -0
  208. vllm/entrypoints/openai/tool_parsers/granite_20b_fc_tool_parser.py +258 -0
  209. vllm/entrypoints/openai/tool_parsers/granite_tool_parser.py +236 -0
  210. vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py +370 -0
  211. vllm/entrypoints/openai/tool_parsers/internlm2_tool_parser.py +215 -0
  212. vllm/entrypoints/openai/tool_parsers/jamba_tool_parser.py +307 -0
  213. vllm/entrypoints/openai/tool_parsers/llama4_pythonic_tool_parser.py +302 -0
  214. vllm/entrypoints/openai/tool_parsers/llama_tool_parser.py +266 -0
  215. vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py +342 -0
  216. vllm/entrypoints/openai/tool_parsers/phi4mini_tool_parser.py +111 -0
  217. vllm/entrypoints/openai/tool_parsers/pythonic_tool_parser.py +296 -0
  218. vllm/entrypoints/openai/tool_parsers/utils.py +123 -0
  219. vllm/entrypoints/score_utils.py +49 -0
  220. vllm/entrypoints/ssl.py +74 -0
  221. vllm/entrypoints/utils.py +219 -0
  222. vllm/env_override.py +34 -0
  223. vllm/envs.py +896 -0
  224. vllm/executor/__init__.py +0 -0
  225. vllm/executor/executor_base.py +400 -0
  226. vllm/executor/mp_distributed_executor.py +243 -0
  227. vllm/executor/msgspec_utils.py +29 -0
  228. vllm/executor/multiproc_worker_utils.py +312 -0
  229. vllm/executor/ray_distributed_executor.py +700 -0
  230. vllm/executor/ray_utils.py +398 -0
  231. vllm/executor/uniproc_executor.py +138 -0
  232. vllm/forward_context.py +147 -0
  233. vllm/inputs/__init__.py +40 -0
  234. vllm/inputs/data.py +330 -0
  235. vllm/inputs/parse.py +150 -0
  236. vllm/inputs/preprocess.py +908 -0
  237. vllm/inputs/registry.py +214 -0
  238. vllm/jsontree.py +79 -0
  239. vllm/logger.py +211 -0
  240. vllm/logging_utils/__init__.py +7 -0
  241. vllm/logging_utils/dump_input.py +84 -0
  242. vllm/logging_utils/formatter.py +17 -0
  243. vllm/logits_process.py +118 -0
  244. vllm/lora/__init__.py +0 -0
  245. vllm/lora/fully_sharded_layers.py +354 -0
  246. vllm/lora/layers.py +1284 -0
  247. vllm/lora/lora.py +198 -0
  248. vllm/lora/models.py +817 -0
  249. vllm/lora/ops/__init__.py +0 -0
  250. vllm/lora/ops/torch_ops/__init__.py +15 -0
  251. vllm/lora/ops/torch_ops/lora_ops.py +115 -0
  252. vllm/lora/ops/triton_ops/__init__.py +11 -0
  253. vllm/lora/ops/triton_ops/kernel_utils.py +242 -0
  254. vllm/lora/ops/triton_ops/lora_expand_op.py +289 -0
  255. vllm/lora/ops/triton_ops/lora_kernel_metadata.py +147 -0
  256. vllm/lora/ops/triton_ops/lora_shrink_op.py +243 -0
  257. vllm/lora/ops/triton_ops/utils.py +119 -0
  258. vllm/lora/ops/xla_ops/__init__.py +6 -0
  259. vllm/lora/ops/xla_ops/lora_ops.py +106 -0
  260. vllm/lora/ops/xla_ops/pallas.py +133 -0
  261. vllm/lora/peft_helper.py +135 -0
  262. vllm/lora/punica_wrapper/__init__.py +9 -0
  263. vllm/lora/punica_wrapper/punica_base.py +484 -0
  264. vllm/lora/punica_wrapper/punica_cpu.py +348 -0
  265. vllm/lora/punica_wrapper/punica_gpu.py +289 -0
  266. vllm/lora/punica_wrapper/punica_hpu.py +144 -0
  267. vllm/lora/punica_wrapper/punica_selector.py +19 -0
  268. vllm/lora/punica_wrapper/punica_tpu.py +325 -0
  269. vllm/lora/punica_wrapper/utils.py +163 -0
  270. vllm/lora/request.py +98 -0
  271. vllm/lora/resolver.py +84 -0
  272. vllm/lora/utils.py +239 -0
  273. vllm/lora/worker_manager.py +253 -0
  274. vllm/model_executor/__init__.py +15 -0
  275. vllm/model_executor/custom_op.py +151 -0
  276. vllm/model_executor/guided_decoding/__init__.py +180 -0
  277. vllm/model_executor/guided_decoding/guidance_decoding.py +62 -0
  278. vllm/model_executor/guided_decoding/guidance_logits_processors.py +103 -0
  279. vllm/model_executor/guided_decoding/guided_fields.py +42 -0
  280. vllm/model_executor/guided_decoding/lm_format_enforcer_decoding.py +66 -0
  281. vllm/model_executor/guided_decoding/outlines_decoding.py +154 -0
  282. vllm/model_executor/guided_decoding/outlines_logits_processors.py +283 -0
  283. vllm/model_executor/guided_decoding/utils.py +241 -0
  284. vllm/model_executor/guided_decoding/xgrammar_decoding.py +425 -0
  285. vllm/model_executor/layers/__init__.py +0 -0
  286. vllm/model_executor/layers/activation.py +368 -0
  287. vllm/model_executor/layers/fused_moe/__init__.py +53 -0
  288. vllm/model_executor/layers/fused_moe/configs/E=1,N=14336,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  289. vllm/model_executor/layers/fused_moe/configs/E=1,N=14336,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  290. vllm/model_executor/layers/fused_moe/configs/E=1,N=1792,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  291. vllm/model_executor/layers/fused_moe/configs/E=1,N=1792,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  292. vllm/model_executor/layers/fused_moe/configs/E=1,N=3072,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  293. vllm/model_executor/layers/fused_moe/configs/E=1,N=3072,device_name=NVIDIA_H100_80GB_HBM3,dtype=int8_w8a16.json +218 -0
  294. vllm/model_executor/layers/fused_moe/configs/E=1,N=3072,device_name=NVIDIA_H100_80GB_HBM3.json +218 -0
  295. vllm/model_executor/layers/fused_moe/configs/E=1,N=3584,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  296. vllm/model_executor/layers/fused_moe/configs/E=1,N=3584,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  297. vllm/model_executor/layers/fused_moe/configs/E=1,N=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  298. vllm/model_executor/layers/fused_moe/configs/E=1,N=7168,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  299. vllm/model_executor/layers/fused_moe/configs/E=128,N=1024,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  300. vllm/model_executor/layers/fused_moe/configs/E=128,N=1024,device_name=AMD_Instinct_MI300X.json +200 -0
  301. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  302. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  303. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_H20.json +146 -0
  304. vllm/model_executor/layers/fused_moe/configs/E=128,N=192,device_name=NVIDIA_H200.json +146 -0
  305. 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
  306. 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
  307. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=NVIDIA_H20.json +146 -0
  308. 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
  309. vllm/model_executor/layers/fused_moe/configs/E=128,N=384,device_name=NVIDIA_H200.json +146 -0
  310. vllm/model_executor/layers/fused_moe/configs/E=128,N=512,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  311. 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
  312. 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
  313. vllm/model_executor/layers/fused_moe/configs/E=128,N=768,device_name=NVIDIA_H20.json +146 -0
  314. 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
  315. vllm/model_executor/layers/fused_moe/configs/E=128,N=768,device_name=NVIDIA_H200.json +146 -0
  316. vllm/model_executor/layers/fused_moe/configs/E=128,N=96,device_name=NVIDIA_H20.json +146 -0
  317. vllm/model_executor/layers/fused_moe/configs/E=16,N=1024,device_name=AMD_Instinct_MI300X.json +200 -0
  318. vllm/model_executor/layers/fused_moe/configs/E=16,N=1024,device_name=NVIDIA_H100.json +146 -0
  319. vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
  320. vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  321. vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  322. vllm/model_executor/layers/fused_moe/configs/E=16,N=14336,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  323. vllm/model_executor/layers/fused_moe/configs/E=16,N=14336,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  324. vllm/model_executor/layers/fused_moe/configs/E=16,N=1792,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +218 -0
  325. vllm/model_executor/layers/fused_moe/configs/E=16,N=1792,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  326. vllm/model_executor/layers/fused_moe/configs/E=16,N=2688,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  327. vllm/model_executor/layers/fused_moe/configs/E=16,N=2688,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  328. vllm/model_executor/layers/fused_moe/configs/E=16,N=3072,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  329. vllm/model_executor/layers/fused_moe/configs/E=16,N=3072,device_name=NVIDIA_H100_80GB_HBM3,dtype=int8_w8a16.json +146 -0
  330. vllm/model_executor/layers/fused_moe/configs/E=16,N=3200,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +130 -0
  331. vllm/model_executor/layers/fused_moe/configs/E=16,N=3584,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  332. vllm/model_executor/layers/fused_moe/configs/E=16,N=3584,device_name=NVIDIA_A100-SXM4-80GB.json +218 -0
  333. vllm/model_executor/layers/fused_moe/configs/E=16,N=6400,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +130 -0
  334. vllm/model_executor/layers/fused_moe/configs/E=16,N=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a16.json +146 -0
  335. vllm/model_executor/layers/fused_moe/configs/E=16,N=7168,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  336. vllm/model_executor/layers/fused_moe/configs/E=16,N=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=int8_w8a16.json +146 -0
  337. vllm/model_executor/layers/fused_moe/configs/E=16,N=800,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +130 -0
  338. vllm/model_executor/layers/fused_moe/configs/E=160,N=192,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  339. vllm/model_executor/layers/fused_moe/configs/E=256,N=1024,device_name=AMD_Instinct_MI325X,block_shape=[128,128].json +200 -0
  340. 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
  341. 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
  342. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8.json +146 -0
  343. 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
  344. vllm/model_executor/layers/fused_moe/configs/E=256,N=128,device_name=NVIDIA_A800-SXM4-80GB,dtype=int8_w8a8.json +146 -0
  345. 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
  346. 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
  347. 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
  348. 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
  349. 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
  350. 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
  351. 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
  352. 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
  353. 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
  354. 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
  355. 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
  356. 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
  357. vllm/model_executor/layers/fused_moe/configs/E=256,N=64,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  358. vllm/model_executor/layers/fused_moe/configs/E=60,N=1408,device_name=AMD_Instinct_MI300X.json +200 -0
  359. vllm/model_executor/layers/fused_moe/configs/E=60,N=176,device_name=AMD_Instinct_MI300X.json +200 -0
  360. vllm/model_executor/layers/fused_moe/configs/E=60,N=352,device_name=AMD_Instinct_MI300X.json +200 -0
  361. vllm/model_executor/layers/fused_moe/configs/E=60,N=704,device_name=AMD_Instinct_MI300X.json +200 -0
  362. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  363. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  364. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  365. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  366. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  367. vllm/model_executor/layers/fused_moe/configs/E=64,N=1280,device_name=NVIDIA_H200.json +146 -0
  368. vllm/model_executor/layers/fused_moe/configs/E=64,N=2560,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  369. vllm/model_executor/layers/fused_moe/configs/E=64,N=2560,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  370. vllm/model_executor/layers/fused_moe/configs/E=64,N=2560,device_name=NVIDIA_H200.json +146 -0
  371. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  372. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  373. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  374. vllm/model_executor/layers/fused_moe/configs/E=64,N=320,device_name=NVIDIA_H200.json +146 -0
  375. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  376. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_A800-SXM4-80GB.json +146 -0
  377. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_GeForce_RTX_4090,dtype=fp8_w8a8.json +146 -0
  378. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  379. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  380. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  381. vllm/model_executor/layers/fused_moe/configs/E=64,N=640,device_name=NVIDIA_H200.json +146 -0
  382. vllm/model_executor/layers/fused_moe/configs/E=64,N=896,device_name=NVIDIA_H20.json +146 -0
  383. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  384. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI300X.json +200 -0
  385. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  386. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=AMD_Instinct_MI325X.json +200 -0
  387. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +138 -0
  388. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  389. vllm/model_executor/layers/fused_moe/configs/E=8,N=14336,device_name=NVIDIA_H200.json +146 -0
  390. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  391. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI300X.json +200 -0
  392. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  393. vllm/model_executor/layers/fused_moe/configs/E=8,N=16384,device_name=AMD_Instinct_MI325X.json +200 -0
  394. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  395. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI300X.json +200 -0
  396. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  397. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=AMD_Instinct_MI325X.json +200 -0
  398. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
  399. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  400. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  401. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  402. vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_H200.json +146 -0
  403. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  404. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI300X.json +200 -0
  405. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  406. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=AMD_Instinct_MI325X.json +200 -0
  407. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  408. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  409. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  410. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  411. vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H200.json +146 -0
  412. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  413. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI300X.json +200 -0
  414. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  415. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=AMD_Instinct_MI325X.json +200 -0
  416. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
  417. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  418. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_GeForce_RTX_4090,dtype=fp8_w8a8.json +146 -0
  419. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  420. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  421. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  422. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H200.json +146 -0
  423. vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_L40S.json +173 -0
  424. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  425. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI300X.json +200 -0
  426. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  427. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=AMD_Instinct_MI325X.json +200 -0
  428. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  429. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  430. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  431. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  432. vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H200.json +146 -0
  433. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  434. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI300X.json +200 -0
  435. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  436. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=AMD_Instinct_MI325X.json +200 -0
  437. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
  438. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  439. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
  440. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  441. vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H200.json +146 -0
  442. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +164 -0
  443. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI300X.json +200 -0
  444. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +164 -0
  445. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=AMD_Instinct_MI325X.json +200 -0
  446. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8.json +146 -0
  447. vllm/model_executor/layers/fused_moe/configs/E=8,N=8192,device_name=NVIDIA_H200,dtype=fp8_w8a8.json +146 -0
  448. vllm/model_executor/layers/fused_moe/configs/README +12 -0
  449. vllm/model_executor/layers/fused_moe/cutlass_moe.py +382 -0
  450. vllm/model_executor/layers/fused_moe/deep_gemm_moe.py +227 -0
  451. vllm/model_executor/layers/fused_moe/fused_batched_moe.py +755 -0
  452. vllm/model_executor/layers/fused_moe/fused_marlin_moe.py +231 -0
  453. vllm/model_executor/layers/fused_moe/fused_moe.py +1722 -0
  454. vllm/model_executor/layers/fused_moe/layer.py +1366 -0
  455. vllm/model_executor/layers/fused_moe/modular_kernel.py +364 -0
  456. vllm/model_executor/layers/fused_moe/moe_align_block_size.py +242 -0
  457. vllm/model_executor/layers/fused_moe/moe_pallas.py +83 -0
  458. vllm/model_executor/layers/fused_moe/moe_permute_unpermute.py +188 -0
  459. vllm/model_executor/layers/fused_moe/moe_torch_iterative.py +59 -0
  460. vllm/model_executor/layers/fused_moe/pplx_prepare_finalize.py +146 -0
  461. vllm/model_executor/layers/fused_moe/prepare_finalize.py +60 -0
  462. vllm/model_executor/layers/fused_moe/rocm_aiter_fused_moe.py +372 -0
  463. vllm/model_executor/layers/fused_moe/triton_deep_gemm_moe.py +112 -0
  464. vllm/model_executor/layers/fused_moe/utils.py +97 -0
  465. vllm/model_executor/layers/layernorm.py +287 -0
  466. vllm/model_executor/layers/lightning_attn.py +651 -0
  467. vllm/model_executor/layers/linear.py +1523 -0
  468. vllm/model_executor/layers/logits_processor.py +196 -0
  469. vllm/model_executor/layers/mamba/__init__.py +0 -0
  470. vllm/model_executor/layers/mamba/mamba2_metadata.py +124 -0
  471. vllm/model_executor/layers/mamba/mamba_mixer.py +244 -0
  472. vllm/model_executor/layers/mamba/mamba_mixer2.py +615 -0
  473. vllm/model_executor/layers/mamba/ops/__init__.py +0 -0
  474. vllm/model_executor/layers/mamba/ops/causal_conv1d.py +104 -0
  475. vllm/model_executor/layers/mamba/ops/mamba_ssm.py +413 -0
  476. vllm/model_executor/layers/mamba/ops/ssd_bmm.py +261 -0
  477. vllm/model_executor/layers/mamba/ops/ssd_chunk_scan.py +588 -0
  478. vllm/model_executor/layers/mamba/ops/ssd_chunk_state.py +750 -0
  479. vllm/model_executor/layers/mamba/ops/ssd_combined.py +231 -0
  480. vllm/model_executor/layers/mamba/ops/ssd_state_passing.py +205 -0
  481. vllm/model_executor/layers/pooler.py +343 -0
  482. vllm/model_executor/layers/quantization/__init__.py +156 -0
  483. vllm/model_executor/layers/quantization/aqlm.py +375 -0
  484. vllm/model_executor/layers/quantization/auto_round.py +308 -0
  485. vllm/model_executor/layers/quantization/awq.py +185 -0
  486. vllm/model_executor/layers/quantization/awq_marlin.py +518 -0
  487. vllm/model_executor/layers/quantization/awq_triton.py +319 -0
  488. vllm/model_executor/layers/quantization/base_config.py +150 -0
  489. vllm/model_executor/layers/quantization/bitblas.py +460 -0
  490. vllm/model_executor/layers/quantization/bitsandbytes.py +397 -0
  491. vllm/model_executor/layers/quantization/compressed_tensors/__init__.py +0 -0
  492. vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py +644 -0
  493. vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors_moe.py +1252 -0
  494. vllm/model_executor/layers/quantization/compressed_tensors/schemes/__init__.py +21 -0
  495. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_24.py +357 -0
  496. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_scheme.py +54 -0
  497. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w4a16_24.py +159 -0
  498. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w4a16_nvfp4.py +92 -0
  499. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a16_fp8.py +120 -0
  500. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a8_fp8.py +149 -0
  501. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a8_int8.py +110 -0
  502. vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa16.py +200 -0
  503. vllm/model_executor/layers/quantization/compressed_tensors/triton_scaled_mm.py +205 -0
  504. vllm/model_executor/layers/quantization/compressed_tensors/utils.py +214 -0
  505. vllm/model_executor/layers/quantization/deepspeedfp.py +194 -0
  506. vllm/model_executor/layers/quantization/experts_int8.py +195 -0
  507. vllm/model_executor/layers/quantization/fbgemm_fp8.py +171 -0
  508. vllm/model_executor/layers/quantization/fp8.py +876 -0
  509. vllm/model_executor/layers/quantization/gguf.py +564 -0
  510. vllm/model_executor/layers/quantization/gptq.py +277 -0
  511. vllm/model_executor/layers/quantization/gptq_bitblas.py +444 -0
  512. vllm/model_executor/layers/quantization/gptq_marlin.py +647 -0
  513. vllm/model_executor/layers/quantization/gptq_marlin_24.py +296 -0
  514. vllm/model_executor/layers/quantization/hqq_marlin.py +331 -0
  515. vllm/model_executor/layers/quantization/ipex_quant.py +249 -0
  516. vllm/model_executor/layers/quantization/kernels/__init__.py +0 -0
  517. vllm/model_executor/layers/quantization/kernels/mixed_precision/MPLinearKernel.py +89 -0
  518. vllm/model_executor/layers/quantization/kernels/mixed_precision/__init__.py +82 -0
  519. vllm/model_executor/layers/quantization/kernels/mixed_precision/allspark.py +115 -0
  520. vllm/model_executor/layers/quantization/kernels/mixed_precision/bitblas.py +299 -0
  521. vllm/model_executor/layers/quantization/kernels/mixed_precision/exllama.py +142 -0
  522. vllm/model_executor/layers/quantization/kernels/mixed_precision/machete.py +119 -0
  523. vllm/model_executor/layers/quantization/kernels/mixed_precision/marlin.py +130 -0
  524. vllm/model_executor/layers/quantization/kernels/scaled_mm/ScaledMMLinearKernel.py +66 -0
  525. vllm/model_executor/layers/quantization/kernels/scaled_mm/__init__.py +86 -0
  526. vllm/model_executor/layers/quantization/kernels/scaled_mm/aiter.py +119 -0
  527. vllm/model_executor/layers/quantization/kernels/scaled_mm/cutlass.py +136 -0
  528. vllm/model_executor/layers/quantization/kernels/scaled_mm/triton.py +40 -0
  529. vllm/model_executor/layers/quantization/kernels/scaled_mm/xla.py +104 -0
  530. vllm/model_executor/layers/quantization/kv_cache.py +138 -0
  531. vllm/model_executor/layers/quantization/marlin.py +260 -0
  532. vllm/model_executor/layers/quantization/modelopt.py +734 -0
  533. vllm/model_executor/layers/quantization/moe_wna16.py +448 -0
  534. vllm/model_executor/layers/quantization/neuron_quant.py +68 -0
  535. vllm/model_executor/layers/quantization/ptpc_fp8.py +126 -0
  536. vllm/model_executor/layers/quantization/qqq.py +274 -0
  537. vllm/model_executor/layers/quantization/quark/__init__.py +0 -0
  538. vllm/model_executor/layers/quantization/quark/quark.py +440 -0
  539. vllm/model_executor/layers/quantization/quark/quark_moe.py +236 -0
  540. vllm/model_executor/layers/quantization/quark/schemes/__init__.py +8 -0
  541. vllm/model_executor/layers/quantization/quark/schemes/quark_scheme.py +54 -0
  542. vllm/model_executor/layers/quantization/quark/schemes/quark_w4a4_mxfp4.py +125 -0
  543. vllm/model_executor/layers/quantization/quark/schemes/quark_w8a8_fp8.py +145 -0
  544. vllm/model_executor/layers/quantization/quark/schemes/quark_w8a8_int8.py +121 -0
  545. vllm/model_executor/layers/quantization/quark/utils.py +104 -0
  546. vllm/model_executor/layers/quantization/schema.py +85 -0
  547. vllm/model_executor/layers/quantization/torchao.py +143 -0
  548. vllm/model_executor/layers/quantization/tpu_int8.py +120 -0
  549. vllm/model_executor/layers/quantization/utils/__init__.py +5 -0
  550. vllm/model_executor/layers/quantization/utils/allspark_utils.py +51 -0
  551. vllm/model_executor/layers/quantization/utils/bitblas_utils.py +207 -0
  552. 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
  553. 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
  554. 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
  555. 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
  556. 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
  557. 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
  558. 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
  559. 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
  560. 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
  561. 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
  562. 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
  563. 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
  564. 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
  565. 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
  566. 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
  567. 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
  568. 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
  569. 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
  570. 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
  571. 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
  572. 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
  573. 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
  574. 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
  575. 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
  576. 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
  577. 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
  578. 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
  579. 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
  580. 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
  581. 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
  582. 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
  583. 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
  584. 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
  585. 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
  586. 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
  587. 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
  588. 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
  589. 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
  590. 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
  591. 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
  592. 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
  593. 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
  594. 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
  595. 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
  596. 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
  597. 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
  598. 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
  599. 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
  600. 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
  601. 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
  602. 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
  603. 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
  604. 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
  605. 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
  606. 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
  607. 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
  608. 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
  609. 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
  610. 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
  611. 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
  612. 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
  613. 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
  614. 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
  615. 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
  616. 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
  617. 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
  618. 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
  619. 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
  620. 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
  621. 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
  622. 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
  623. 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
  624. 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
  625. 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
  626. 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
  627. 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
  628. 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
  629. 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
  630. 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
  631. 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
  632. 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
  633. 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
  634. 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
  635. 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
  636. 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
  637. 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
  638. 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
  639. 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
  640. 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
  641. 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
  642. 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
  643. 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
  644. 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
  645. 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
  646. 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
  647. 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
  648. 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
  649. 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
  650. 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
  651. 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
  652. 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
  653. 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
  654. 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
  655. 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
  656. 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
  657. 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
  658. 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
  659. 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
  660. 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
  661. 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
  662. 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
  663. 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
  664. 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
  665. 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
  666. 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
  667. 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
  668. 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
  669. 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
  670. 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
  671. 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
  672. 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
  673. 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
  674. 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
  675. 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
  676. 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
  677. 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
  678. 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
  679. 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
  680. 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
  681. 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
  682. 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
  683. 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
  684. 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
  685. 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
  686. 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
  687. 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
  688. 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
  689. 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
  690. 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
  691. 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
  692. 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
  693. 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
  694. 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
  695. 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
  696. 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
  697. 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
  698. 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
  699. 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
  700. 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
  701. 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
  702. 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
  703. 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
  704. 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
  705. 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
  706. 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
  707. 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
  708. 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
  709. 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
  710. 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
  711. 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
  712. 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
  713. 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
  714. 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
  715. 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
  716. 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
  717. 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
  718. 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
  719. 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
  720. 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
  721. 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
  722. 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
  723. 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
  724. 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
  725. 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
  726. 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
  727. 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
  728. 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
  729. 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
  730. 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
  731. 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
  732. 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
  733. 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
  734. 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
  735. 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
  736. 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
  737. 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
  738. 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
  739. 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
  740. 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
  741. 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
  742. 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
  743. 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
  744. 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
  745. 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
  746. 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
  747. 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
  748. 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
  749. 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
  750. 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
  751. 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
  752. 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
  753. 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
  754. vllm/model_executor/layers/quantization/utils/fp8_utils.py +611 -0
  755. vllm/model_executor/layers/quantization/utils/gptq_utils.py +94 -0
  756. vllm/model_executor/layers/quantization/utils/int8_utils.py +484 -0
  757. vllm/model_executor/layers/quantization/utils/layer_utils.py +39 -0
  758. vllm/model_executor/layers/quantization/utils/machete_utils.py +32 -0
  759. vllm/model_executor/layers/quantization/utils/marlin_utils.py +475 -0
  760. vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py +277 -0
  761. vllm/model_executor/layers/quantization/utils/marlin_utils_fp8.py +324 -0
  762. vllm/model_executor/layers/quantization/utils/marlin_utils_test.py +164 -0
  763. vllm/model_executor/layers/quantization/utils/marlin_utils_test_24.py +463 -0
  764. vllm/model_executor/layers/quantization/utils/marlin_utils_test_qqq.py +125 -0
  765. vllm/model_executor/layers/quantization/utils/mxfp4_utils.py +44 -0
  766. vllm/model_executor/layers/quantization/utils/nvfp4_emulation_utils.py +61 -0
  767. vllm/model_executor/layers/quantization/utils/quant_utils.py +572 -0
  768. vllm/model_executor/layers/quantization/utils/w8a8_utils.py +404 -0
  769. vllm/model_executor/layers/rejection_sampler.py +405 -0
  770. vllm/model_executor/layers/resampler.py +269 -0
  771. vllm/model_executor/layers/rotary_embedding.py +1861 -0
  772. vllm/model_executor/layers/sampler.py +1203 -0
  773. vllm/model_executor/layers/spec_decode_base_sampler.py +258 -0
  774. vllm/model_executor/layers/typical_acceptance_sampler.py +165 -0
  775. vllm/model_executor/layers/utils.py +99 -0
  776. vllm/model_executor/layers/vocab_parallel_embedding.py +486 -0
  777. vllm/model_executor/model_loader/__init__.py +75 -0
  778. vllm/model_executor/model_loader/base_loader.py +24 -0
  779. vllm/model_executor/model_loader/bitsandbytes_loader.py +582 -0
  780. vllm/model_executor/model_loader/default_loader.py +295 -0
  781. vllm/model_executor/model_loader/dummy_loader.py +37 -0
  782. vllm/model_executor/model_loader/gguf_loader.py +113 -0
  783. vllm/model_executor/model_loader/neuron.py +475 -0
  784. vllm/model_executor/model_loader/neuronx_distributed.py +622 -0
  785. vllm/model_executor/model_loader/runai_streamer_loader.py +120 -0
  786. vllm/model_executor/model_loader/sharded_state_loader.py +211 -0
  787. vllm/model_executor/model_loader/tensorizer.py +632 -0
  788. vllm/model_executor/model_loader/tensorizer_loader.py +122 -0
  789. vllm/model_executor/model_loader/utils.py +301 -0
  790. vllm/model_executor/model_loader/weight_utils.py +781 -0
  791. vllm/model_executor/models/__init__.py +27 -0
  792. vllm/model_executor/models/adapters.py +247 -0
  793. vllm/model_executor/models/aimv2.py +199 -0
  794. vllm/model_executor/models/arctic.py +558 -0
  795. vllm/model_executor/models/aria.py +656 -0
  796. vllm/model_executor/models/aya_vision.py +461 -0
  797. vllm/model_executor/models/baichuan.py +473 -0
  798. vllm/model_executor/models/bamba.py +542 -0
  799. vllm/model_executor/models/bart.py +937 -0
  800. vllm/model_executor/models/bert.py +517 -0
  801. vllm/model_executor/models/bert_with_rope.py +714 -0
  802. vllm/model_executor/models/blip.py +338 -0
  803. vllm/model_executor/models/blip2.py +717 -0
  804. vllm/model_executor/models/bloom.py +372 -0
  805. vllm/model_executor/models/chameleon.py +1135 -0
  806. vllm/model_executor/models/chatglm.py +477 -0
  807. vllm/model_executor/models/clip.py +411 -0
  808. vllm/model_executor/models/commandr.py +471 -0
  809. vllm/model_executor/models/constant_size_cache.py +136 -0
  810. vllm/model_executor/models/dbrx.py +471 -0
  811. vllm/model_executor/models/deepseek.py +485 -0
  812. vllm/model_executor/models/deepseek_mtp.py +268 -0
  813. vllm/model_executor/models/deepseek_v2.py +842 -0
  814. vllm/model_executor/models/deepseek_vl2.py +647 -0
  815. vllm/model_executor/models/eagle.py +259 -0
  816. vllm/model_executor/models/exaone.py +550 -0
  817. vllm/model_executor/models/fairseq2_llama.py +153 -0
  818. vllm/model_executor/models/falcon.py +509 -0
  819. vllm/model_executor/models/falcon_h1.py +684 -0
  820. vllm/model_executor/models/florence2.py +1102 -0
  821. vllm/model_executor/models/fuyu.py +388 -0
  822. vllm/model_executor/models/gemma.py +424 -0
  823. vllm/model_executor/models/gemma2.py +424 -0
  824. vllm/model_executor/models/gemma3.py +532 -0
  825. vllm/model_executor/models/gemma3_mm.py +708 -0
  826. vllm/model_executor/models/glm.py +22 -0
  827. vllm/model_executor/models/glm4.py +304 -0
  828. vllm/model_executor/models/glm4v.py +647 -0
  829. vllm/model_executor/models/gpt2.py +327 -0
  830. vllm/model_executor/models/gpt_bigcode.py +334 -0
  831. vllm/model_executor/models/gpt_j.py +338 -0
  832. vllm/model_executor/models/gpt_neox.py +331 -0
  833. vllm/model_executor/models/granite.py +492 -0
  834. vllm/model_executor/models/granite_speech.py +778 -0
  835. vllm/model_executor/models/granitemoe.py +436 -0
  836. vllm/model_executor/models/granitemoehybrid.py +585 -0
  837. vllm/model_executor/models/granitemoeshared.py +340 -0
  838. vllm/model_executor/models/gritlm.py +223 -0
  839. vllm/model_executor/models/grok1.py +545 -0
  840. vllm/model_executor/models/h2ovl.py +545 -0
  841. vllm/model_executor/models/idefics2_vision_model.py +388 -0
  842. vllm/model_executor/models/idefics3.py +767 -0
  843. vllm/model_executor/models/interfaces.py +571 -0
  844. vllm/model_executor/models/interfaces_base.py +163 -0
  845. vllm/model_executor/models/intern_vit.py +475 -0
  846. vllm/model_executor/models/internlm2.py +454 -0
  847. vllm/model_executor/models/internlm2_ve.py +146 -0
  848. vllm/model_executor/models/internvl.py +1405 -0
  849. vllm/model_executor/models/jais.py +372 -0
  850. vllm/model_executor/models/jamba.py +591 -0
  851. vllm/model_executor/models/kimi_vl.py +576 -0
  852. vllm/model_executor/models/llama.py +643 -0
  853. vllm/model_executor/models/llama4.py +531 -0
  854. vllm/model_executor/models/llama_eagle.py +166 -0
  855. vllm/model_executor/models/llama_eagle3.py +257 -0
  856. vllm/model_executor/models/llava.py +865 -0
  857. vllm/model_executor/models/llava_next.py +585 -0
  858. vllm/model_executor/models/llava_next_video.py +470 -0
  859. vllm/model_executor/models/llava_onevision.py +955 -0
  860. vllm/model_executor/models/mamba.py +272 -0
  861. vllm/model_executor/models/mamba2.py +302 -0
  862. vllm/model_executor/models/mamba_cache.py +75 -0
  863. vllm/model_executor/models/medusa.py +218 -0
  864. vllm/model_executor/models/mimo.py +191 -0
  865. vllm/model_executor/models/mimo_mtp.py +284 -0
  866. vllm/model_executor/models/minicpm.py +590 -0
  867. vllm/model_executor/models/minicpm3.py +229 -0
  868. vllm/model_executor/models/minicpmo.py +758 -0
  869. vllm/model_executor/models/minicpmv.py +1286 -0
  870. vllm/model_executor/models/minimax_cache.py +35 -0
  871. vllm/model_executor/models/minimax_text_01.py +1303 -0
  872. vllm/model_executor/models/minimax_vl_01.py +363 -0
  873. vllm/model_executor/models/mistral3.py +603 -0
  874. vllm/model_executor/models/mixtral.py +487 -0
  875. vllm/model_executor/models/mixtral_quant.py +452 -0
  876. vllm/model_executor/models/mllama.py +1623 -0
  877. vllm/model_executor/models/mllama4.py +838 -0
  878. vllm/model_executor/models/mlp_speculator.py +205 -0
  879. vllm/model_executor/models/modernbert.py +329 -0
  880. vllm/model_executor/models/module_mapping.py +71 -0
  881. vllm/model_executor/models/molmo.py +1567 -0
  882. vllm/model_executor/models/moonvit.py +629 -0
  883. vllm/model_executor/models/mpt.py +330 -0
  884. vllm/model_executor/models/nemotron.py +507 -0
  885. vllm/model_executor/models/nemotron_nas.py +483 -0
  886. vllm/model_executor/models/nvlm_d.py +215 -0
  887. vllm/model_executor/models/olmo.py +388 -0
  888. vllm/model_executor/models/olmo2.py +413 -0
  889. vllm/model_executor/models/olmoe.py +446 -0
  890. vllm/model_executor/models/opt.py +411 -0
  891. vllm/model_executor/models/orion.py +348 -0
  892. vllm/model_executor/models/ovis.py +554 -0
  893. vllm/model_executor/models/paligemma.py +397 -0
  894. vllm/model_executor/models/persimmon.py +343 -0
  895. vllm/model_executor/models/phi.py +355 -0
  896. vllm/model_executor/models/phi3.py +18 -0
  897. vllm/model_executor/models/phi3_small.py +464 -0
  898. vllm/model_executor/models/phi3v.py +722 -0
  899. vllm/model_executor/models/phi4mm.py +1245 -0
  900. vllm/model_executor/models/phi4mm_audio.py +1232 -0
  901. vllm/model_executor/models/phi4mm_utils.py +1883 -0
  902. vllm/model_executor/models/phimoe.py +664 -0
  903. vllm/model_executor/models/pixtral.py +1315 -0
  904. vllm/model_executor/models/plamo2.py +737 -0
  905. vllm/model_executor/models/prithvi_geospatial_mae.py +231 -0
  906. vllm/model_executor/models/qwen.py +361 -0
  907. vllm/model_executor/models/qwen2.py +567 -0
  908. vllm/model_executor/models/qwen2_5_omni_thinker.py +903 -0
  909. vllm/model_executor/models/qwen2_5_vl.py +1171 -0
  910. vllm/model_executor/models/qwen2_audio.py +409 -0
  911. vllm/model_executor/models/qwen2_moe.py +539 -0
  912. vllm/model_executor/models/qwen2_rm.py +131 -0
  913. vllm/model_executor/models/qwen2_vl.py +1410 -0
  914. vllm/model_executor/models/qwen3.py +320 -0
  915. vllm/model_executor/models/qwen3_moe.py +534 -0
  916. vllm/model_executor/models/qwen_vl.py +784 -0
  917. vllm/model_executor/models/registry.py +618 -0
  918. vllm/model_executor/models/roberta.py +273 -0
  919. vllm/model_executor/models/siglip.py +523 -0
  920. vllm/model_executor/models/skyworkr1v.py +950 -0
  921. vllm/model_executor/models/smolvlm.py +51 -0
  922. vllm/model_executor/models/solar.py +505 -0
  923. vllm/model_executor/models/stablelm.py +342 -0
  924. vllm/model_executor/models/starcoder2.py +355 -0
  925. vllm/model_executor/models/telechat2.py +139 -0
  926. vllm/model_executor/models/teleflm.py +78 -0
  927. vllm/model_executor/models/transformers.py +507 -0
  928. vllm/model_executor/models/ultravox.py +655 -0
  929. vllm/model_executor/models/utils.py +730 -0
  930. vllm/model_executor/models/vision.py +146 -0
  931. vllm/model_executor/models/whisper.py +746 -0
  932. vllm/model_executor/models/zamba2.py +1008 -0
  933. vllm/model_executor/parameter.py +458 -0
  934. vllm/model_executor/pooling_metadata.py +71 -0
  935. vllm/model_executor/sampling_metadata.py +596 -0
  936. vllm/model_executor/utils.py +53 -0
  937. vllm/multimodal/__init__.py +32 -0
  938. vllm/multimodal/audio.py +105 -0
  939. vllm/multimodal/base.py +218 -0
  940. vllm/multimodal/hasher.py +117 -0
  941. vllm/multimodal/image.py +96 -0
  942. vllm/multimodal/inputs.py +872 -0
  943. vllm/multimodal/parse.py +460 -0
  944. vllm/multimodal/processing.py +1894 -0
  945. vllm/multimodal/profiling.py +273 -0
  946. vllm/multimodal/registry.py +330 -0
  947. vllm/multimodal/utils.py +392 -0
  948. vllm/multimodal/video.py +197 -0
  949. vllm/outputs.py +525 -0
  950. vllm/platforms/__init__.py +290 -0
  951. vllm/platforms/cpu.py +205 -0
  952. vllm/platforms/cuda.py +461 -0
  953. vllm/platforms/hpu.py +105 -0
  954. vllm/platforms/interface.py +492 -0
  955. vllm/platforms/neuron.py +152 -0
  956. vllm/platforms/rocm.py +388 -0
  957. vllm/platforms/tpu.py +215 -0
  958. vllm/platforms/xpu.py +155 -0
  959. vllm/plugins/__init__.py +86 -0
  960. vllm/plugins/lora_resolvers/README.md +15 -0
  961. vllm/plugins/lora_resolvers/__init__.py +0 -0
  962. vllm/plugins/lora_resolvers/filesystem_resolver.py +49 -0
  963. vllm/pooling_params.py +53 -0
  964. vllm/profiler/__init__.py +0 -0
  965. vllm/profiler/layerwise_profile.py +374 -0
  966. vllm/profiler/utils.py +147 -0
  967. vllm/prompt_adapter/__init__.py +0 -0
  968. vllm/prompt_adapter/layers.py +82 -0
  969. vllm/prompt_adapter/models.py +357 -0
  970. vllm/prompt_adapter/request.py +36 -0
  971. vllm/prompt_adapter/utils.py +97 -0
  972. vllm/prompt_adapter/worker_manager.py +178 -0
  973. vllm/py.typed +2 -0
  974. vllm/reasoning/__init__.py +14 -0
  975. vllm/reasoning/abs_reasoning_parsers.py +191 -0
  976. vllm/reasoning/deepseek_r1_reasoning_parser.py +172 -0
  977. vllm/reasoning/granite_reasoning_parser.py +362 -0
  978. vllm/reasoning/qwen3_reasoning_parser.py +150 -0
  979. vllm/sampling_params.py +590 -0
  980. vllm/scalar_type.py +346 -0
  981. vllm/scripts.py +14 -0
  982. vllm/sequence.py +1567 -0
  983. vllm/spec_decode/__init__.py +0 -0
  984. vllm/spec_decode/batch_expansion.py +505 -0
  985. vllm/spec_decode/draft_model_runner.py +349 -0
  986. vllm/spec_decode/interfaces.py +98 -0
  987. vllm/spec_decode/medusa_worker.py +137 -0
  988. vllm/spec_decode/metrics.py +212 -0
  989. vllm/spec_decode/mlp_speculator_worker.py +93 -0
  990. vllm/spec_decode/mqa_scorer.py +159 -0
  991. vllm/spec_decode/multi_step_worker.py +422 -0
  992. vllm/spec_decode/ngram_worker.py +195 -0
  993. vllm/spec_decode/proposer_worker_base.py +58 -0
  994. vllm/spec_decode/smaller_tp_proposer_worker.py +195 -0
  995. vllm/spec_decode/spec_decode_worker.py +1325 -0
  996. vllm/spec_decode/target_model_runner.py +44 -0
  997. vllm/spec_decode/top1_proposer.py +274 -0
  998. vllm/spec_decode/util.py +276 -0
  999. vllm/test_utils.py +129 -0
  1000. vllm/third_party/__init__.py +0 -0
  1001. vllm/third_party/pynvml.py +6139 -0
  1002. vllm/tracing.py +130 -0
  1003. vllm/transformers_utils/__init__.py +23 -0
  1004. vllm/transformers_utils/chat_templates/__init__.py +4 -0
  1005. vllm/transformers_utils/chat_templates/registry.py +59 -0
  1006. vllm/transformers_utils/chat_templates/template_basic.jinja +3 -0
  1007. vllm/transformers_utils/chat_templates/template_blip2.jinja +11 -0
  1008. vllm/transformers_utils/chat_templates/template_chatml.jinja +10 -0
  1009. vllm/transformers_utils/chat_templates/template_deepseek_vl2.jinja +23 -0
  1010. vllm/transformers_utils/chat_templates/template_fuyu.jinja +3 -0
  1011. vllm/transformers_utils/config.py +835 -0
  1012. vllm/transformers_utils/configs/__init__.py +58 -0
  1013. vllm/transformers_utils/configs/arctic.py +206 -0
  1014. vllm/transformers_utils/configs/chatglm.py +71 -0
  1015. vllm/transformers_utils/configs/cohere2.py +194 -0
  1016. vllm/transformers_utils/configs/dbrx.py +279 -0
  1017. vllm/transformers_utils/configs/deepseek_vl2.py +215 -0
  1018. vllm/transformers_utils/configs/eagle.py +84 -0
  1019. vllm/transformers_utils/configs/exaone.py +189 -0
  1020. vllm/transformers_utils/configs/falcon.py +89 -0
  1021. vllm/transformers_utils/configs/h2ovl.py +15 -0
  1022. vllm/transformers_utils/configs/internvl.py +53 -0
  1023. vllm/transformers_utils/configs/jais.py +237 -0
  1024. vllm/transformers_utils/configs/kimi_vl.py +36 -0
  1025. vllm/transformers_utils/configs/medusa.py +62 -0
  1026. vllm/transformers_utils/configs/minimax_text_01.py +69 -0
  1027. vllm/transformers_utils/configs/minimax_vl_01.py +70 -0
  1028. vllm/transformers_utils/configs/mllama.py +30 -0
  1029. vllm/transformers_utils/configs/mlp_speculator.py +67 -0
  1030. vllm/transformers_utils/configs/moonvit.py +32 -0
  1031. vllm/transformers_utils/configs/mpt.py +179 -0
  1032. vllm/transformers_utils/configs/nemotron.py +204 -0
  1033. vllm/transformers_utils/configs/nvlm_d.py +14 -0
  1034. vllm/transformers_utils/configs/ovis.py +183 -0
  1035. vllm/transformers_utils/configs/skyworkr1v.py +53 -0
  1036. vllm/transformers_utils/configs/solar.py +246 -0
  1037. vllm/transformers_utils/configs/telechat2.py +63 -0
  1038. vllm/transformers_utils/configs/ultravox.py +107 -0
  1039. vllm/transformers_utils/detokenizer.py +167 -0
  1040. vllm/transformers_utils/detokenizer_utils.py +188 -0
  1041. vllm/transformers_utils/processor.py +220 -0
  1042. vllm/transformers_utils/processors/__init__.py +7 -0
  1043. vllm/transformers_utils/processors/deepseek_vl2.py +362 -0
  1044. vllm/transformers_utils/processors/ovis.py +419 -0
  1045. vllm/transformers_utils/s3_utils.py +161 -0
  1046. vllm/transformers_utils/tokenizer.py +301 -0
  1047. vllm/transformers_utils/tokenizer_base.py +148 -0
  1048. vllm/transformers_utils/tokenizer_group.py +119 -0
  1049. vllm/transformers_utils/tokenizers/__init__.py +9 -0
  1050. vllm/transformers_utils/tokenizers/mistral.py +490 -0
  1051. vllm/transformers_utils/utils.py +98 -0
  1052. vllm/triton_utils/__init__.py +13 -0
  1053. vllm/triton_utils/importing.py +49 -0
  1054. vllm/usage/__init__.py +0 -0
  1055. vllm/usage/usage_lib.py +255 -0
  1056. vllm/utils.py +2844 -0
  1057. vllm/v1/__init__.py +0 -0
  1058. vllm/v1/attention/__init__.py +0 -0
  1059. vllm/v1/attention/backends/__init__.py +0 -0
  1060. vllm/v1/attention/backends/flash_attn.py +833 -0
  1061. vllm/v1/attention/backends/flashinfer.py +639 -0
  1062. vllm/v1/attention/backends/mla/__init__.py +0 -0
  1063. vllm/v1/attention/backends/mla/common.py +926 -0
  1064. vllm/v1/attention/backends/mla/flashmla.py +150 -0
  1065. vllm/v1/attention/backends/mla/rocm_aiter_mla.py +221 -0
  1066. vllm/v1/attention/backends/mla/triton_mla.py +118 -0
  1067. vllm/v1/attention/backends/pallas.py +235 -0
  1068. vllm/v1/attention/backends/triton_attn.py +279 -0
  1069. vllm/v1/attention/backends/utils.py +18 -0
  1070. vllm/v1/core/__init__.py +0 -0
  1071. vllm/v1/core/block_pool.py +328 -0
  1072. vllm/v1/core/encoder_cache_manager.py +149 -0
  1073. vllm/v1/core/kv_cache_manager.py +372 -0
  1074. vllm/v1/core/kv_cache_utils.py +748 -0
  1075. vllm/v1/core/sched/__init__.py +0 -0
  1076. vllm/v1/core/sched/interface.py +143 -0
  1077. vllm/v1/core/sched/output.py +153 -0
  1078. vllm/v1/core/sched/scheduler.py +1015 -0
  1079. vllm/v1/core/sched/utils.py +22 -0
  1080. vllm/v1/core/single_type_kv_cache_manager.py +358 -0
  1081. vllm/v1/engine/__init__.py +171 -0
  1082. vllm/v1/engine/async_llm.py +546 -0
  1083. vllm/v1/engine/core.py +801 -0
  1084. vllm/v1/engine/core_client.py +1020 -0
  1085. vllm/v1/engine/detokenizer.py +260 -0
  1086. vllm/v1/engine/exceptions.py +16 -0
  1087. vllm/v1/engine/llm_engine.py +316 -0
  1088. vllm/v1/engine/logprobs.py +198 -0
  1089. vllm/v1/engine/mm_input_cache.py +90 -0
  1090. vllm/v1/engine/output_processor.py +427 -0
  1091. vllm/v1/engine/parallel_sampling.py +132 -0
  1092. vllm/v1/engine/processor.py +398 -0
  1093. vllm/v1/executor/__init__.py +0 -0
  1094. vllm/v1/executor/abstract.py +112 -0
  1095. vllm/v1/executor/multiproc_executor.py +532 -0
  1096. vllm/v1/executor/ray_distributed_executor.py +61 -0
  1097. vllm/v1/kv_cache_interface.py +208 -0
  1098. vllm/v1/metrics/__init__.py +0 -0
  1099. vllm/v1/metrics/loggers.py +511 -0
  1100. vllm/v1/metrics/ray_wrappers.py +120 -0
  1101. vllm/v1/metrics/reader.py +245 -0
  1102. vllm/v1/metrics/stats.py +238 -0
  1103. vllm/v1/outputs.py +115 -0
  1104. vllm/v1/request.py +191 -0
  1105. vllm/v1/sample/__init__.py +0 -0
  1106. vllm/v1/sample/metadata.py +43 -0
  1107. vllm/v1/sample/ops/__init__.py +0 -0
  1108. vllm/v1/sample/ops/bad_words.py +38 -0
  1109. vllm/v1/sample/ops/penalties.py +58 -0
  1110. vllm/v1/sample/ops/topk_topp_sampler.py +292 -0
  1111. vllm/v1/sample/rejection_sampler.py +630 -0
  1112. vllm/v1/sample/sampler.py +270 -0
  1113. vllm/v1/sample/tpu/__init__.py +0 -0
  1114. vllm/v1/sample/tpu/metadata.py +123 -0
  1115. vllm/v1/sample/tpu/sampler.py +144 -0
  1116. vllm/v1/serial_utils.py +313 -0
  1117. vllm/v1/spec_decode/__init__.py +0 -0
  1118. vllm/v1/spec_decode/eagle.py +424 -0
  1119. vllm/v1/spec_decode/medusa.py +61 -0
  1120. vllm/v1/spec_decode/metadata.py +61 -0
  1121. vllm/v1/spec_decode/metrics.py +177 -0
  1122. vllm/v1/spec_decode/ngram_proposer.py +131 -0
  1123. vllm/v1/spec_decode/utils.py +45 -0
  1124. vllm/v1/structured_output/__init__.py +215 -0
  1125. vllm/v1/structured_output/backend_guidance.py +244 -0
  1126. vllm/v1/structured_output/backend_types.py +133 -0
  1127. vllm/v1/structured_output/backend_xgrammar.py +317 -0
  1128. vllm/v1/structured_output/request.py +85 -0
  1129. vllm/v1/structured_output/utils.py +174 -0
  1130. vllm/v1/utils.py +294 -0
  1131. vllm/v1/worker/__init__.py +0 -0
  1132. vllm/v1/worker/block_table.py +139 -0
  1133. vllm/v1/worker/gpu_input_batch.py +680 -0
  1134. vllm/v1/worker/gpu_model_runner.py +2084 -0
  1135. vllm/v1/worker/gpu_worker.py +373 -0
  1136. vllm/v1/worker/lora_model_runner_mixin.py +145 -0
  1137. vllm/v1/worker/tpu_model_runner.py +1510 -0
  1138. vllm/v1/worker/tpu_worker.py +276 -0
  1139. vllm/v1/worker/utils.py +74 -0
  1140. vllm/v1/worker/worker_base.py +64 -0
  1141. vllm/version.py +40 -0
  1142. vllm/vllm_flash_attn/.gitkeep +0 -0
  1143. vllm/worker/__init__.py +0 -0
  1144. vllm/worker/cache_engine.py +144 -0
  1145. vllm/worker/cpu_enc_dec_model_runner.py +326 -0
  1146. vllm/worker/cpu_model_runner.py +671 -0
  1147. vllm/worker/cpu_pooling_model_runner.py +125 -0
  1148. vllm/worker/cpu_worker.py +400 -0
  1149. vllm/worker/enc_dec_model_runner.py +555 -0
  1150. vllm/worker/hpu_model_runner.py +2319 -0
  1151. vllm/worker/hpu_worker.py +483 -0
  1152. vllm/worker/model_runner.py +2178 -0
  1153. vllm/worker/model_runner_base.py +281 -0
  1154. vllm/worker/multi_step_hpu_worker.py +122 -0
  1155. vllm/worker/multi_step_model_runner.py +910 -0
  1156. vllm/worker/multi_step_neuron_model_runner.py +84 -0
  1157. vllm/worker/multi_step_neuronx_distributed_model_runner.py +63 -0
  1158. vllm/worker/multi_step_tpu_worker.py +107 -0
  1159. vllm/worker/multi_step_worker.py +196 -0
  1160. vllm/worker/neuron_model_runner.py +418 -0
  1161. vllm/worker/neuron_worker.py +158 -0
  1162. vllm/worker/neuronx_distributed_model_runner.py +136 -0
  1163. vllm/worker/pooling_model_runner.py +211 -0
  1164. vllm/worker/tpu_model_runner.py +908 -0
  1165. vllm/worker/tpu_worker.py +336 -0
  1166. vllm/worker/utils.py +52 -0
  1167. vllm/worker/worker.py +574 -0
  1168. vllm/worker/worker_base.py +644 -0
  1169. vllm/worker/xpu_model_runner.py +606 -0
  1170. vllm/worker/xpu_worker.py +185 -0
  1171. vllm_cpu_avx512bf16-0.9.0.post2.dist-info/METADATA +335 -0
  1172. vllm_cpu_avx512bf16-0.9.0.post2.dist-info/RECORD +1175 -0
  1173. vllm_cpu_avx512bf16-0.9.0.post2.dist-info/WHEEL +5 -0
  1174. vllm_cpu_avx512bf16-0.9.0.post2.dist-info/entry_points.txt +5 -0
  1175. vllm_cpu_avx512bf16-0.9.0.post2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1861 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+
3
+ # Adapted from
4
+ # https://github.com/huggingface/transformers/blob/v4.33.2/src/transformers/models/llama/modeling_llama.py
5
+ # Copyright 2023 The vLLM team.
6
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
7
+ #
8
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
9
+ # and OPT implementations in this library. It has been modified from its
10
+ # original forms to accommodate minor architectural differences compared
11
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
12
+ #
13
+ # Licensed under the Apache License, Version 2.0 (the "License");
14
+ # you may not use this file except in compliance with the License.
15
+ # You may obtain a copy of the License at
16
+ #
17
+ # http://www.apache.org/licenses/LICENSE-2.0
18
+ #
19
+ # Unless required by applicable law or agreed to in writing, software
20
+ # distributed under the License is distributed on an "AS IS" BASIS,
21
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ # See the License for the specific language governing permissions and
23
+ # limitations under the License.
24
+ """Rotary Positional Embeddings."""
25
+ import math
26
+ from typing import Any, Optional, Union
27
+
28
+ import torch
29
+ import torch.nn as nn
30
+ from transformers import PretrainedConfig
31
+
32
+ from vllm.model_executor.custom_op import CustomOp
33
+ from vllm.platforms import current_platform
34
+
35
+ if current_platform.is_cuda():
36
+ from vllm.vllm_flash_attn.layers.rotary import apply_rotary_emb
37
+
38
+
39
+ def _rotate_neox(x: torch.Tensor) -> torch.Tensor:
40
+ x1 = x[..., :x.shape[-1] // 2]
41
+ x2 = x[..., x.shape[-1] // 2:]
42
+ return torch.cat((-x2, x1), dim=-1)
43
+
44
+
45
+ def _rotate_gptj(x: torch.Tensor) -> torch.Tensor:
46
+ x1 = x[..., ::2]
47
+ x2 = x[..., 1::2]
48
+ x = torch.stack((-x2, x1), dim=-1)
49
+ return x.flatten(-2)
50
+
51
+
52
+ def _apply_rotary_emb_torch(
53
+ x: torch.Tensor,
54
+ cos: torch.Tensor,
55
+ sin: torch.Tensor,
56
+ is_neox_style: bool,
57
+ ) -> torch.Tensor:
58
+ cos = cos.unsqueeze(-2).to(x.dtype)
59
+ sin = sin.unsqueeze(-2).to(x.dtype)
60
+ if is_neox_style:
61
+ x1, x2 = torch.chunk(x, 2, dim=-1)
62
+ else:
63
+ x1 = x[..., ::2]
64
+ x2 = x[..., 1::2]
65
+ o1 = x1 * cos - x2 * sin
66
+ o2 = x2 * cos + x1 * sin
67
+ if is_neox_style:
68
+ return torch.cat((o1, o2), dim=-1)
69
+ else:
70
+ return torch.stack((o1, o2), dim=-1).flatten(-2)
71
+
72
+
73
+ def _apply_rotary_emb(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor,
74
+ is_neox_style: bool) -> torch.Tensor:
75
+ """
76
+ Args:
77
+ x: [num_tokens, num_heads, head_size]
78
+ cos: [num_tokens, head_size // 2]
79
+ sin: [num_tokens, head_size // 2]
80
+ is_neox_style: Whether to use the Neox-style or GPT-J-style rotary
81
+ positional embeddings.
82
+ """
83
+ if current_platform.is_cuda():
84
+ return apply_rotary_emb(x.unsqueeze(0), cos, sin,
85
+ not is_neox_style).squeeze(0)
86
+ else:
87
+ return _apply_rotary_emb_torch(x, cos, sin, is_neox_style)
88
+
89
+
90
+ @CustomOp.register("rotary_embedding")
91
+ class RotaryEmbedding(CustomOp):
92
+ """Original rotary positional embedding."""
93
+
94
+ def __init__(
95
+ self,
96
+ head_size: int,
97
+ rotary_dim: int,
98
+ max_position_embeddings: int,
99
+ base: int,
100
+ is_neox_style: bool,
101
+ dtype: torch.dtype,
102
+ ) -> None:
103
+ super().__init__()
104
+ self.head_size = head_size
105
+ self.rotary_dim = rotary_dim
106
+ self.max_position_embeddings = max_position_embeddings
107
+ self.base = base
108
+ self.is_neox_style = is_neox_style
109
+ self.dtype = dtype
110
+
111
+ cache = self._compute_cos_sin_cache()
112
+ cache = cache.to(dtype)
113
+ self.cos_sin_cache: torch.Tensor
114
+ self.register_buffer("cos_sin_cache", cache, persistent=False)
115
+
116
+ def _compute_inv_freq(self, base: Union[int, float]) -> torch.Tensor:
117
+ """Compute the inverse frequency."""
118
+ # NOTE(woosuk): To exactly match the HF implementation, we need to
119
+ # use CPU to compute the cache and then move it to GPU. However, we
120
+ # create the cache on GPU for faster initialization. This may cause
121
+ # a slight numerical difference between the HF implementation and ours.
122
+ inv_freq = 1.0 / (base**(torch.arange(
123
+ 0, self.rotary_dim, 2, dtype=torch.float) / self.rotary_dim))
124
+ return inv_freq
125
+
126
+ def _compute_cos_sin_cache(self) -> torch.Tensor:
127
+ """Compute the cos and sin cache."""
128
+ inv_freq = self._compute_inv_freq(self.base)
129
+ t = torch.arange(self.max_position_embeddings, dtype=torch.float)
130
+
131
+ freqs = torch.einsum("i,j -> ij", t, inv_freq)
132
+ cos = freqs.cos()
133
+ sin = freqs.sin()
134
+ cache = torch.cat((cos, sin), dim=-1)
135
+ return cache
136
+
137
+ def forward_native(
138
+ self,
139
+ positions: torch.Tensor,
140
+ query: torch.Tensor,
141
+ key: Optional[torch.Tensor] = None,
142
+ offsets: Optional[torch.Tensor] = None,
143
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
144
+ """A PyTorch-native implementation of forward()."""
145
+ if offsets is not None:
146
+ positions = positions + offsets
147
+ positions = positions.flatten()
148
+ num_tokens = positions.shape[0]
149
+ cos_sin = self.cos_sin_cache.index_select(0, positions)
150
+ cos, sin = cos_sin.chunk(2, dim=-1)
151
+
152
+ query_shape = query.shape
153
+ query = query.view(num_tokens, -1, self.head_size)
154
+ query_rot = query[..., :self.rotary_dim]
155
+ query_pass = query[..., self.rotary_dim:]
156
+ query_rot = _apply_rotary_emb_torch(query_rot, cos, sin,
157
+ self.is_neox_style)
158
+ query = torch.cat((query_rot, query_pass), dim=-1).reshape(query_shape)
159
+
160
+ # key may be None in some cases, e.g. cross-layer KV sharing
161
+ if key is not None:
162
+ key_shape = key.shape
163
+ key = key.view(num_tokens, -1, self.head_size)
164
+ key_rot = key[..., :self.rotary_dim]
165
+ key_pass = key[..., self.rotary_dim:]
166
+ key_rot = _apply_rotary_emb_torch(key_rot, cos, sin,
167
+ self.is_neox_style)
168
+ key = torch.cat((key_rot, key_pass), dim=-1).reshape(key_shape)
169
+ return query, key
170
+
171
+ def forward_cuda(
172
+ self,
173
+ positions: torch.Tensor,
174
+ query: torch.Tensor,
175
+ key: Optional[torch.Tensor] = None,
176
+ offsets: Optional[torch.Tensor] = None,
177
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
178
+ from vllm import _custom_ops as ops
179
+
180
+ # __setattr__ in nn.Module (called by `self.cos_sin_cache = ...`)
181
+ # is expensive, so avoid calling it if possible
182
+ if self.cos_sin_cache.device != query.device or \
183
+ self.cos_sin_cache.dtype != query.dtype:
184
+ self.cos_sin_cache = self.cos_sin_cache.to(query.device,
185
+ dtype=query.dtype)
186
+
187
+ # ops.rotary_embedding()/batched_rotary_embedding()
188
+ # are in-place operations that update the query and key tensors.
189
+ if offsets is not None:
190
+ ops.batched_rotary_embedding(positions, query, key, self.head_size,
191
+ self.cos_sin_cache,
192
+ self.is_neox_style, self.rotary_dim,
193
+ offsets)
194
+ else:
195
+ ops.rotary_embedding(positions, query, key, self.head_size,
196
+ self.cos_sin_cache, self.is_neox_style)
197
+ return query, key
198
+
199
+ def forward_xpu(
200
+ self,
201
+ positions: torch.Tensor,
202
+ query: torch.Tensor,
203
+ key: Optional[torch.Tensor] = None,
204
+ offsets: Optional[torch.Tensor] = None,
205
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
206
+ from vllm._ipex_ops import ipex_ops as ops
207
+
208
+ self.cos_sin_cache = self.cos_sin_cache.to(positions.device,
209
+ dtype=query.dtype)
210
+ # ops.rotary_embedding()/batched_rotary_embedding()
211
+ # are in-place operations that update the query and key tensors.
212
+ if key is None:
213
+ # XPU kernel doesn't support key=None so fall back to native impl
214
+ # TODO(sarckk): add support for optional key in
215
+ # ipex.llm.functional.rotary_embedding_batched
216
+ return self.forward_native(positions, query, key, offsets)
217
+ else:
218
+ if offsets is not None:
219
+ ops.batched_rotary_embedding(positions, query, key,
220
+ self.head_size,
221
+ self.cos_sin_cache,
222
+ self.is_neox_style,
223
+ self.rotary_dim, offsets)
224
+ else:
225
+ ops.rotary_embedding(positions, query, key, self.head_size,
226
+ self.cos_sin_cache, self.is_neox_style)
227
+ return query, key
228
+
229
+ def forward_hpu(
230
+ self,
231
+ positions: torch.Tensor,
232
+ query: torch.Tensor,
233
+ key: Optional[torch.Tensor] = None,
234
+ offsets: Optional[torch.Tensor] = None,
235
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
236
+ from habana_frameworks.torch.hpex.kernels import (
237
+ RotaryPosEmbeddingMode, apply_rotary_pos_emb)
238
+ if offsets is not None:
239
+ offsets = offsets.view(positions.shape[0], -1)
240
+ positions = positions + offsets
241
+ positions = positions.flatten()
242
+ num_tokens = positions.shape[0]
243
+ cos_sin = self.cos_sin_cache.index_select(0, positions).view(
244
+ num_tokens, 1, -1)
245
+ cos, sin = cos_sin.chunk(2, dim=-1)
246
+ # HPU RoPE kernel requires hidden dimension for cos and sin to be equal
247
+ # to query hidden dimension, so the original tensors need to be
248
+ # expanded
249
+ # GPT-NeoX kernel requires position_ids = None, offset, mode = BLOCKWISE
250
+ # and expansion of cos/sin tensors via concatenation
251
+ # GPT-J kernel requires position_ids = None, offset = 0, mode = PAIRWISE
252
+ # and expansion of cos/sin tensors via repeat_interleave
253
+ rope_mode: RotaryPosEmbeddingMode
254
+ if self.is_neox_style:
255
+ rope_mode = RotaryPosEmbeddingMode.BLOCKWISE
256
+ cos = torch.cat((cos, cos), dim=-1)
257
+ sin = torch.cat((sin, sin), dim=-1)
258
+ else:
259
+ rope_mode = RotaryPosEmbeddingMode.PAIRWISE
260
+ sin = torch.repeat_interleave(sin,
261
+ 2,
262
+ dim=-1,
263
+ output_size=cos_sin.shape[-1])
264
+ cos = torch.repeat_interleave(cos,
265
+ 2,
266
+ dim=-1,
267
+ output_size=cos_sin.shape[-1])
268
+
269
+ query_shape = query.shape
270
+ query = query.view(num_tokens, -1, self.head_size)
271
+ query_rot = query[..., :self.rotary_dim]
272
+ query_pass = query[..., self.rotary_dim:]
273
+ query_rot = apply_rotary_pos_emb(query_rot, cos, sin, None, 0,
274
+ rope_mode)
275
+ query = torch.cat((query_rot, query_pass), dim=-1).reshape(query_shape)
276
+
277
+ if key is not None:
278
+ key_shape = key.shape
279
+ key = key.view(num_tokens, -1, self.head_size)
280
+ key_rot = key[..., :self.rotary_dim]
281
+ key_pass = key[..., self.rotary_dim:]
282
+ key_rot = apply_rotary_pos_emb(key_rot, cos, sin, None, 0,
283
+ rope_mode)
284
+ key = torch.cat((key_rot, key_pass), dim=-1).reshape(key_shape)
285
+ return query, key
286
+
287
+ def forward_neuron(
288
+ self,
289
+ positions: torch.Tensor,
290
+ query: torch.Tensor,
291
+ key: Optional[torch.Tensor] = None,
292
+ offsets: Optional[torch.Tensor] = None,
293
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
294
+
295
+ def _apply_rotary_emb_neuron(
296
+ x: torch.Tensor,
297
+ cos: torch.Tensor,
298
+ sin: torch.Tensor,
299
+ is_neox_style: bool,
300
+ ) -> torch.Tensor:
301
+ cos = cos.unsqueeze(-2).to(x.dtype)
302
+ sin = sin.unsqueeze(-2).to(x.dtype)
303
+ if is_neox_style:
304
+ x1, x2 = torch.chunk(x, 2, dim=-1)
305
+ else:
306
+ # x1 = x[..., ::2]
307
+
308
+ # x2 = x[..., 1::2]
309
+ d = x.shape[-1] // 2
310
+ x_reshaped = x.view(-1, x.shape[-1])
311
+ x1 = x_reshaped[:, ::2].view(*x.shape[:-1], d)
312
+ x2 = x_reshaped[:, 1::2].view(*x.shape[:-1], d)
313
+ o1 = x1 * cos - x2 * sin
314
+ o2 = x2 * cos + x1 * sin
315
+ if is_neox_style:
316
+ return torch.cat((o1, o2), dim=-1)
317
+ else:
318
+ return torch.stack((o1, o2), dim=-1).flatten(-2)
319
+
320
+ if offsets is not None:
321
+ positions = positions + offsets
322
+
323
+ self.cos_sin_cache = self.cos_sin_cache.to(query.device,
324
+ dtype=query.dtype)
325
+
326
+ positions = positions.flatten()
327
+ num_tokens = positions.shape[0]
328
+ cos_sin = self.cos_sin_cache.index_select(0, positions)
329
+ cos, sin = cos_sin.chunk(2, dim=-1)
330
+
331
+ query_shape = query.shape
332
+ query = query.view(num_tokens, -1, self.head_size)
333
+ if key is not None:
334
+ key_shape = key.shape
335
+ key = key.view(num_tokens, -1, self.head_size)
336
+
337
+ if self.rotary_dim == self.head_size:
338
+ query = _apply_rotary_emb(query, cos, sin, self.is_neox_style)
339
+ query = query.reshape(query_shape)
340
+ if key is not None:
341
+ key = _apply_rotary_emb(key, cos, sin, self.is_neox_style)
342
+ key = key.reshape(key_shape)
343
+ else:
344
+ head_size = query.shape[-1]
345
+ query_reshaped = query.view(-1, head_size)
346
+ query_pass = query_reshaped[:, self.rotary_dim:].view(
347
+ *query.shape[:-1], head_size - self.rotary_dim)
348
+ query_rot = query_reshaped[:, :self.rotary_dim].view(
349
+ *query.shape[:-1], self.rotary_dim)
350
+ query_rot = _apply_rotary_emb_neuron(query_rot, cos, sin,
351
+ self.is_neox_style)
352
+ query = torch.cat((query_rot, query_pass),
353
+ dim=-1).reshape(query_shape)
354
+
355
+ if key is not None:
356
+ key_reshaped = key.view(-1, head_size)
357
+ key_pass = key_reshaped[:, self.rotary_dim:].view(
358
+ *key.shape[:-1], head_size - self.rotary_dim)
359
+ key_rot = key_reshaped[:, :self.rotary_dim].view(
360
+ *key.shape[:-1], self.rotary_dim)
361
+ key_rot = _apply_rotary_emb_neuron(key_rot, cos, sin,
362
+ self.is_neox_style)
363
+ key = torch.cat((key_rot, key_pass), dim=-1).reshape(key_shape)
364
+ return query, key
365
+
366
+ def extra_repr(self) -> str:
367
+ s = f"head_size={self.head_size}, rotary_dim={self.rotary_dim}"
368
+ s += f", max_position_embeddings={self.max_position_embeddings}"
369
+ s += f", base={self.base}, is_neox_style={self.is_neox_style}"
370
+ return s
371
+
372
+
373
+ class LinearScalingRotaryEmbedding(RotaryEmbedding):
374
+ """RotaryEmbedding extended with linear scaling.
375
+
376
+ It supports multiple scaling factors. Since multiple LoRA adapters may have
377
+ different scaling factors, we need multiple cos/sin caches. In this way,
378
+ instead of running rotary embedding kernel per lora, we can run multiple
379
+ lora in a batched way.
380
+
381
+ In addition to that, we also keep the cos/sin cache for the scaling factor
382
+ of 1 (default) at all times.
383
+
384
+ Exemplary for two scaling factors x=1, y and z with embeddings
385
+ [[x11, x12, ... x1m], ..., [xn1, xn2, ..., xnm]] and
386
+ [[y11, y12, ... y1o], ..., [yn1, yn2, ..., yno]], and
387
+ [[z11, z12, ... z1p], ..., [zn1, zn2, ..., znp]],
388
+
389
+ we construct the cos/sin cache as follows:
390
+ [[x11, x12, ... x1m, y11, y12, ... y1o, z11, z12, ... z1p],
391
+ ...
392
+ [xn1, xn2, ... xnm, yn1, yn2, ... yno, zn1, zn2, ... znp]]
393
+
394
+ We then use offsets to index into the cos/sin cache for
395
+ the respective scaling factors.
396
+
397
+ The offset to cache can be accessed via `scaling_factor_to_offset` API.
398
+
399
+ Credits to the Reddit user /u/kaiokendev
400
+ """
401
+
402
+ def __init__(
403
+ self,
404
+ head_size: int,
405
+ rotary_dim: int,
406
+ max_position_embeddings: int,
407
+ base: int,
408
+ is_neox_style: bool,
409
+ scaling_factors: Union[list[float], float],
410
+ dtype: torch.dtype,
411
+ ) -> None:
412
+ if isinstance(scaling_factors, float):
413
+ scaling_factors = [scaling_factors]
414
+ self.scaling_factors: list[float] = scaling_factors # noqa
415
+ super().__init__(head_size, rotary_dim, max_position_embeddings, base,
416
+ is_neox_style, dtype)
417
+ # Lazy initialized.
418
+ self._scaling_factor_to_offset: dict[float, int]
419
+
420
+ def _compute_cos_sin_cache(self) -> torch.Tensor:
421
+ inv_freq = self._compute_inv_freq(self.base)
422
+ cache_list: list[torch.Tensor] = []
423
+ # offsets to the next cache in a tensor.
424
+ # Each offset corresponds to the same index in scaling_factors.
425
+ offsets: list[int] = []
426
+ for scaling_factor in self.scaling_factors:
427
+ # NOTE(woosuk): self.max_position_embeddings is the original
428
+ # maximum length before applying the rope scaling.
429
+ # Thus, the maximum length after applying the rope scaling is
430
+ # self.max_position_embeddings * self.scaling_factor.
431
+ max_len = self.max_position_embeddings * scaling_factor
432
+ t = torch.arange(max_len, dtype=torch.float)
433
+ t = t / scaling_factor
434
+
435
+ freqs = torch.einsum("i,j -> ij", t, inv_freq)
436
+ cos = freqs.cos()
437
+ sin = freqs.sin()
438
+ cache = torch.cat((cos, sin), dim=-1)
439
+ if not cache_list:
440
+ offset = 0
441
+ else:
442
+ last_offset = offsets[-1]
443
+ next_max_len = cache_list[-1].shape[0]
444
+ offset = last_offset + next_max_len
445
+ offsets.append(offset)
446
+ cache_list.append(cache)
447
+ self._scaling_factor_to_offset = {
448
+ float(scaling_factor): offsets[i]
449
+ for i, scaling_factor in enumerate(self.scaling_factors)
450
+ }
451
+ assert len(self.scaling_factors) == len(offsets)
452
+ return torch.cat(cache_list, dim=0)
453
+
454
+ @property
455
+ def scaling_factor_to_offset(self) -> dict[float, int]:
456
+ return self._scaling_factor_to_offset
457
+
458
+
459
+ class NTKScalingRotaryEmbedding(RotaryEmbedding):
460
+ """RotaryEmbedding extended with fixed and mixed NTK scaling.
461
+ https://kexue.fm/archives/9706 """
462
+
463
+ def __init__(self,
464
+ head_size: int,
465
+ rotary_dim: int,
466
+ max_position_embeddings: int,
467
+ base: int,
468
+ is_neox_style: bool,
469
+ scaling_factor: float,
470
+ dtype: torch.dtype,
471
+ mixed_b: Optional[float] = None) -> None:
472
+ self.scaling_factor = scaling_factor
473
+ self.mixed_b = mixed_b
474
+ super().__init__(head_size, rotary_dim, max_position_embeddings, base,
475
+ is_neox_style, dtype)
476
+
477
+ def _compute_inv_freq(self, base: Union[int, float]) -> torch.Tensor:
478
+ base = self.base * (self.scaling_factor if self.mixed_b is None else 1)
479
+ inv_freq = super()._compute_inv_freq(base)
480
+
481
+ if self.mixed_b is None:
482
+ inv_freq = inv_freq / self.scaling_factor**(2 / self.rotary_dim)
483
+ else:
484
+ a = torch.tensor(self.scaling_factor).log() / (self.rotary_dim /
485
+ 2)**self.mixed_b
486
+ lambda_1_m = (a * torch.arange(
487
+ 1, self.rotary_dim // 2 + 1).float()**self.mixed_b).exp()
488
+ inv_freq = inv_freq / lambda_1_m
489
+
490
+ return inv_freq
491
+
492
+
493
+ class DynamicNTKScalingRotaryEmbedding(RotaryEmbedding):
494
+ """RotaryEmbedding extended with Dynamic NTK scaling.
495
+
496
+ Credits to the Reddit users /u/bloc97 and /u/emozilla
497
+ """
498
+
499
+ def __init__(
500
+ self,
501
+ head_size: int,
502
+ rotary_dim: int,
503
+ max_position_embeddings: int,
504
+ base: int,
505
+ is_neox_style: bool,
506
+ scaling_factor: float,
507
+ dtype: torch.dtype,
508
+ ) -> None:
509
+ self.scaling_factor = scaling_factor
510
+ super().__init__(head_size, rotary_dim, max_position_embeddings, base,
511
+ is_neox_style, dtype)
512
+
513
+ def _compute_cos_sin_cache(self) -> torch.Tensor:
514
+ # NOTE(woosuk): self.max_position_embeddings is the original
515
+ # maximum length before applying the rope scaling.
516
+ # Thus, the maximum length after applying the rope scaling is
517
+ # self.max_position_embeddings * self.scaling_factor.
518
+ max_len = self.max_position_embeddings * self.scaling_factor
519
+ base = self.base * (
520
+ (self.scaling_factor * max_len / self.max_position_embeddings) -
521
+ (self.scaling_factor - 1))**(self.rotary_dim /
522
+ (self.rotary_dim - 2))
523
+ inv_freq = self._compute_inv_freq(base)
524
+ t = torch.arange(max_len, dtype=torch.float)
525
+
526
+ freqs = torch.einsum("i,j -> ij", t, inv_freq)
527
+ cos = freqs.cos()
528
+ sin = freqs.sin()
529
+ cache = torch.cat((cos, sin), dim=-1)
530
+ return cache
531
+
532
+
533
+ # Inverse dim formula to find dim based on number of rotations
534
+ def _yarn_find_correction_dim(num_rotations: int,
535
+ dim: int,
536
+ base: float = 10000,
537
+ max_position_embeddings: int = 2048) -> float:
538
+ return (dim * math.log(max_position_embeddings /
539
+ (num_rotations * 2 * math.pi))) / (2 *
540
+ math.log(base))
541
+
542
+
543
+ # Find dim range bounds based on rotations
544
+ def _yarn_find_correction_range(
545
+ low_rot: int,
546
+ high_rot: int,
547
+ dim: int,
548
+ base: float = 10000,
549
+ max_position_embeddings: int = 2048) -> tuple[int, int]:
550
+ low = math.floor(
551
+ _yarn_find_correction_dim(low_rot, dim, base, max_position_embeddings))
552
+ high = math.ceil(
553
+ _yarn_find_correction_dim(high_rot, dim, base,
554
+ max_position_embeddings))
555
+ return max(low, 0), min(high, dim - 1) # Clamp values just in case
556
+
557
+
558
+ def _yarn_linear_ramp_mask(low: float, high: float, dim: int,
559
+ dtype: torch.dtype) -> torch.Tensor:
560
+ if low == high:
561
+ high += 0.001 # Prevent singularity
562
+
563
+ linear_func = (torch.arange(dim, dtype=dtype) - low) / (high - low)
564
+ ramp_func = torch.clamp(linear_func, 0, 1)
565
+ return ramp_func
566
+
567
+
568
+ def _yarn_get_mscale(scale: float = 1) -> float:
569
+ if scale <= 1:
570
+ return 1.0
571
+ return 0.1 * math.log(scale) + 1.0
572
+
573
+
574
+ class YaRNScalingRotaryEmbedding(RotaryEmbedding):
575
+ """RotaryEmbedding extended with YaRN method.
576
+
577
+ Credits to Peng et al. github.com/jquesnelle/yarn
578
+ """
579
+
580
+ def __init__(
581
+ self,
582
+ head_size: int,
583
+ rotary_dim: int,
584
+ max_position_embeddings: int,
585
+ base: int,
586
+ is_neox_style: bool,
587
+ scaling_factor: float,
588
+ dtype: torch.dtype,
589
+ *,
590
+ extrapolation_factor: float = 1,
591
+ attn_factor: float = 1,
592
+ beta_fast: int = 32,
593
+ beta_slow: int = 1,
594
+ ) -> None:
595
+ self.scaling_factor = scaling_factor
596
+ self.extrapolation_factor = extrapolation_factor
597
+ self.attn_factor = attn_factor
598
+ self.beta_fast = beta_fast
599
+ self.beta_slow = beta_slow
600
+ # Get n-d magnitude scaling corrected for interpolation
601
+ self.mscale = float(
602
+ _yarn_get_mscale(self.scaling_factor) * attn_factor)
603
+ super().__init__(head_size, rotary_dim, max_position_embeddings, base,
604
+ is_neox_style, dtype)
605
+
606
+ def _compute_inv_freq(self, scaling_factor: float) -> torch.Tensor:
607
+ pos_freqs = self.base**(
608
+ torch.arange(0, self.rotary_dim, 2, dtype=torch.float) /
609
+ self.rotary_dim)
610
+ inv_freq_extrapolation = 1.0 / pos_freqs
611
+ inv_freq_interpolation = 1.0 / (scaling_factor * pos_freqs)
612
+
613
+ low, high = _yarn_find_correction_range(self.beta_fast, self.beta_slow,
614
+ self.rotary_dim, self.base,
615
+ self.max_position_embeddings)
616
+ # Get n-d rotational scaling corrected for extrapolation
617
+ inv_freq_mask = (1 - _yarn_linear_ramp_mask(
618
+ low, high, self.rotary_dim // 2,
619
+ dtype=torch.float)) * self.extrapolation_factor
620
+ inv_freq = inv_freq_interpolation * (
621
+ 1 - inv_freq_mask) + inv_freq_extrapolation * inv_freq_mask
622
+ return inv_freq
623
+
624
+ def _compute_cos_sin_cache(self) -> torch.Tensor:
625
+ inv_freq = self._compute_inv_freq(self.scaling_factor)
626
+ t = torch.arange(self.max_position_embeddings * self.scaling_factor,
627
+ dtype=torch.float32)
628
+ freqs = torch.einsum("i,j -> ij", t, inv_freq)
629
+ cos = (freqs.cos() * self.mscale)
630
+ sin = (freqs.sin() * self.mscale)
631
+ cache = torch.cat((cos, sin), dim=-1)
632
+ return cache
633
+
634
+
635
+ class Phi3LongRoPEScaledRotaryEmbedding(nn.Module):
636
+ """Phi3 family of models scaled rotary embedding.
637
+
638
+ Based on the original RotaryEmbedding implementation.
639
+ """
640
+
641
+ def __init__(
642
+ self,
643
+ head_size: int,
644
+ rotary_dim: int,
645
+ max_position_embeddings: int,
646
+ original_max_position_embeddings: int,
647
+ base: int,
648
+ is_neox_style: bool,
649
+ dtype: torch.dtype,
650
+ short_factor: list[float],
651
+ long_factor: list[float],
652
+ short_mscale: Optional[float] = None,
653
+ long_mscale: Optional[float] = None,
654
+ ):
655
+ super().__init__()
656
+
657
+ if is_neox_style is False:
658
+ raise ValueError(
659
+ "`Phi3LongRoPEScaledRotaryEmbedding` only supports neox_style."
660
+ )
661
+
662
+ self.rotary_dim = rotary_dim
663
+ self.head_size = head_size
664
+ self.max_position_embeddings = max_position_embeddings
665
+ self.original_max_position_embeddings = original_max_position_embeddings
666
+ self.base = base
667
+ self.short_factor = short_factor
668
+ self.long_factor = long_factor
669
+
670
+ scale = self.max_position_embeddings / \
671
+ self.original_max_position_embeddings
672
+ if scale <= 1.0:
673
+ scaling_factor = 1.0
674
+ else:
675
+ scaling_factor = math.sqrt(
676
+ 1 + math.log(scale) /
677
+ math.log(self.original_max_position_embeddings))
678
+ if short_mscale is None:
679
+ short_mscale = scaling_factor
680
+ if long_mscale is None:
681
+ long_mscale = scaling_factor
682
+
683
+ self.short_mscale = short_mscale
684
+ self.long_mscale = long_mscale
685
+
686
+ short_cache = self._compute_cos_sin_cache(
687
+ original_max_position_embeddings, short_factor, short_mscale)
688
+ short_cache = short_cache.to(dtype)
689
+
690
+ long_cache = self._compute_cos_sin_cache(max_position_embeddings,
691
+ long_factor, long_mscale)
692
+ long_cache = long_cache.to(dtype)
693
+
694
+ long_short_cache = torch.cat([short_cache, long_cache], dim=0)
695
+ self.register_buffer("long_short_cos_sin_cache",
696
+ long_short_cache,
697
+ persistent=False)
698
+
699
+ def _compute_inv_freq(self, rescale_factors: list[float]) -> torch.Tensor:
700
+ rescale_factors = torch.tensor(rescale_factors, dtype=torch.float32)
701
+ inv_freq = 1.0 / (rescale_factors * (self.base**(torch.arange(
702
+ 0, self.rotary_dim, 2, dtype=torch.float) / self.rotary_dim)))
703
+ return inv_freq
704
+
705
+ def _compute_cos_sin_cache(
706
+ self,
707
+ max_position_embeddings: int,
708
+ rescale_factors: list[float],
709
+ mscale: float,
710
+ ) -> torch.Tensor:
711
+ inv_freq = self._compute_inv_freq(rescale_factors)
712
+ t = torch.arange(max_position_embeddings, dtype=torch.float)
713
+ freqs = torch.einsum("i,j -> ij", t, inv_freq)
714
+ cos = freqs.cos() * mscale
715
+ sin = freqs.sin() * mscale
716
+ cache = torch.cat((cos, sin), dim=-1)
717
+ return cache
718
+
719
+ def forward(
720
+ self,
721
+ positions: torch.Tensor,
722
+ query: torch.Tensor,
723
+ key: Optional[torch.Tensor] = None,
724
+ offsets: Optional[torch.Tensor] = None,
725
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
726
+ assert key is not None
727
+ query = query.view(*query.shape[:-1], -1, self.head_size)
728
+ key = key.view(*key.shape[:-1], -1, self.head_size)
729
+
730
+ k = self.original_max_position_embeddings
731
+ long_prompt_offset = (torch.any(positions > k).float() *
732
+ torch.full_like(positions, k)).long()
733
+ idx = (torch.add(positions, long_prompt_offset)
734
+ if long_prompt_offset is not None else positions)
735
+ idx = torch.add(idx, offsets) if offsets is not None else idx
736
+ cos_sin = torch.index_select(self.long_short_cos_sin_cache, 0, idx)
737
+
738
+ cos, sin = cos_sin.chunk(2, dim=-1)
739
+ cos = cos.repeat(1, 2).unsqueeze(-2)
740
+ sin = sin.repeat(1, 2).unsqueeze(-2)
741
+
742
+ query_rot = query[..., :self.rotary_dim]
743
+ query_pass = query[..., self.rotary_dim:]
744
+ query_rot = query_rot * cos + _rotate_neox(query_rot) * sin
745
+ query = torch.cat((query_rot, query_pass), dim=-1)
746
+
747
+ key_rot = key[..., :self.rotary_dim]
748
+ key_pass = key[..., self.rotary_dim:]
749
+ key_rot = key_rot * cos + _rotate_neox(key_rot) * sin
750
+ key = torch.cat((key_rot, key_pass), dim=-1)
751
+
752
+ return query.flatten(-2), key.flatten(-2)
753
+
754
+
755
+ def yarn_get_mscale(scale: float = 1, mscale: float = 1) -> float:
756
+ if scale <= 1:
757
+ return 1.0
758
+ return 0.1 * mscale * math.log(scale) + 1.0
759
+
760
+
761
+ class DeepseekScalingRotaryEmbedding(RotaryEmbedding):
762
+ """RotaryEmbedding extended with YaRN method.
763
+
764
+ Credits to Peng et al. github.com/jquesnelle/yarn
765
+ """
766
+
767
+ def __init__(
768
+ self,
769
+ head_size: int,
770
+ rotary_dim: int,
771
+ max_position_embeddings: int,
772
+ base: int,
773
+ is_neox_style: bool,
774
+ scaling_factor: float,
775
+ dtype: torch.dtype,
776
+ *,
777
+ extrapolation_factor: float = 1,
778
+ attn_factor: float = 1,
779
+ beta_fast: int = 32,
780
+ beta_slow: int = 1,
781
+ mscale: float = 1,
782
+ mscale_all_dim: float = 0,
783
+ ) -> None:
784
+ self.scaling_factor = scaling_factor
785
+ self.extrapolation_factor = extrapolation_factor
786
+ self.attn_factor = attn_factor
787
+ self.beta_fast = beta_fast
788
+ self.beta_slow = beta_slow
789
+ # Get n-d magnitude scaling corrected for interpolation.
790
+ self.mscale = float(
791
+ yarn_get_mscale(self.scaling_factor, float(mscale)) /
792
+ yarn_get_mscale(self.scaling_factor, float(mscale_all_dim)) *
793
+ attn_factor)
794
+ super().__init__(head_size, rotary_dim, max_position_embeddings, base,
795
+ is_neox_style, dtype)
796
+
797
+ def _compute_inv_freq(self, scaling_factor: float) -> torch.Tensor:
798
+ pos_freqs = self.base**(
799
+ torch.arange(0,
800
+ self.rotary_dim,
801
+ 2,
802
+ dtype=torch.float,
803
+ device=current_platform.device_type) /
804
+ self.rotary_dim)
805
+ inv_freq_extrapolation = 1.0 / pos_freqs
806
+ inv_freq_interpolation = 1.0 / (scaling_factor * pos_freqs)
807
+
808
+ low, high = _yarn_find_correction_range(self.beta_fast, self.beta_slow,
809
+ self.rotary_dim, self.base,
810
+ self.max_position_embeddings)
811
+ # Get n-d rotational scaling corrected for extrapolation
812
+ inv_freq_mask = (1 - _yarn_linear_ramp_mask(
813
+ low, high, self.rotary_dim // 2,
814
+ dtype=torch.float)) * self.extrapolation_factor
815
+ inv_freq = inv_freq_interpolation * (
816
+ 1 - inv_freq_mask) + inv_freq_extrapolation * inv_freq_mask
817
+ return inv_freq
818
+
819
+ def _compute_cos_sin_cache(self) -> torch.Tensor:
820
+ inv_freq = self._compute_inv_freq(self.scaling_factor)
821
+ t = torch.arange(self.max_position_embeddings * self.scaling_factor,
822
+ device=current_platform.device_type,
823
+ dtype=torch.float32)
824
+ freqs = torch.einsum("i,j -> ij", t, inv_freq)
825
+ cos = (freqs.cos() * self.mscale)
826
+ sin = (freqs.sin() * self.mscale)
827
+ cache = torch.cat((cos, sin), dim=-1)
828
+ return cache
829
+
830
+ def forward(
831
+ self,
832
+ positions: torch.Tensor,
833
+ query: torch.Tensor,
834
+ key: Optional[torch.Tensor] = None,
835
+ offsets: Optional[torch.Tensor] = None,
836
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
837
+ """PyTorch-native implementation equivalent to forward()."""
838
+ assert key is not None
839
+ query_rot = query[..., :self.rotary_dim]
840
+ key_rot = key[..., :self.rotary_dim]
841
+ if self.rotary_dim < self.head_size:
842
+ query_pass = query[..., self.rotary_dim:]
843
+ key_pass = key[..., self.rotary_dim:]
844
+
845
+ if self.cos_sin_cache.device != positions.device:
846
+ self.cos_sin_cache: torch.Tensor = self.cos_sin_cache.to(
847
+ positions.device)
848
+ cos_sin = self.cos_sin_cache[torch.add(positions, offsets)
849
+ if offsets is not None else positions]
850
+ cos, sin = cos_sin.chunk(2, dim=-1)
851
+ if self.is_neox_style:
852
+ # NOTE(woosuk): Here we assume that the positions tensor has the
853
+ # shape [batch_size, seq_len].
854
+ cos = cos.repeat(1, 1, 2).unsqueeze(-2)
855
+ sin = sin.repeat(1, 1, 2).unsqueeze(-2)
856
+ else:
857
+ cos = cos.repeat_interleave(2, dim=-1).unsqueeze(-2)
858
+ sin = sin.repeat_interleave(2, dim=-1).unsqueeze(-2)
859
+
860
+ rotate_fn = _rotate_neox if self.is_neox_style else _rotate_gptj
861
+ query_rot = query_rot * cos + rotate_fn(query_rot) * sin
862
+ key_rot = key_rot * cos + rotate_fn(key_rot) * sin
863
+
864
+ if self.rotary_dim < self.head_size:
865
+ query = torch.cat((query_rot, query_pass), dim=-1)
866
+ key = torch.cat((key_rot, key_pass), dim=-1)
867
+ else:
868
+ query = query_rot
869
+ key = key_rot
870
+ return query, key
871
+
872
+
873
+ class Llama3RotaryEmbedding(RotaryEmbedding):
874
+
875
+ def __init__(
876
+ self,
877
+ head_size: int,
878
+ rotary_dim: int,
879
+ max_position_embeddings: int,
880
+ base: int,
881
+ is_neox_style: bool,
882
+ dtype: torch.dtype,
883
+ scaling_factor: float,
884
+ low_freq_factor: float,
885
+ high_freq_factor: float,
886
+ orig_max_position: int,
887
+ ) -> None:
888
+ self.scaling_factor = scaling_factor
889
+ self.low_freq_factor = low_freq_factor
890
+ self.high_freq_factor = high_freq_factor
891
+ self.orig_max_position = orig_max_position
892
+ super().__init__(head_size, rotary_dim, max_position_embeddings, base,
893
+ is_neox_style, dtype)
894
+
895
+ def _compute_inv_freq(self, base: Union[int, float]) -> torch.Tensor:
896
+ inv_freqs = super()._compute_inv_freq(base)
897
+ low_freq_wavelen = self.orig_max_position / self.low_freq_factor
898
+ high_freq_wavelen = self.orig_max_position / self.high_freq_factor
899
+
900
+ wave_len = 2 * math.pi / inv_freqs
901
+ if self.low_freq_factor != self.high_freq_factor:
902
+ smooth = (self.orig_max_position / wave_len - self.low_freq_factor
903
+ ) / (self.high_freq_factor - self.low_freq_factor)
904
+ else:
905
+ smooth = 0
906
+ new_freqs = torch.where(
907
+ wave_len < high_freq_wavelen,
908
+ inv_freqs,
909
+ torch.where(
910
+ wave_len > low_freq_wavelen,
911
+ inv_freqs / self.scaling_factor,
912
+ (1 - smooth) * inv_freqs / self.scaling_factor +
913
+ smooth * inv_freqs,
914
+ ),
915
+ )
916
+ return new_freqs
917
+
918
+
919
+ class Llama4VisionRotaryEmbedding(RotaryEmbedding):
920
+
921
+ def __init__(
922
+ self,
923
+ head_size: int,
924
+ rotary_dim: int,
925
+ max_position_embeddings: int,
926
+ base: int,
927
+ is_neox_style: bool,
928
+ dtype: torch.dtype,
929
+ ):
930
+ super().__init__(head_size, rotary_dim, max_position_embeddings, base,
931
+ is_neox_style, dtype)
932
+
933
+ def _compute_inv_freq(self, base: Union[int, float]) -> torch.Tensor:
934
+ inv_freqs = super()._compute_inv_freq(base)
935
+ inv_freqs = inv_freqs[:(self.rotary_dim // 2)]
936
+ return inv_freqs
937
+
938
+ def _compute_cos_sin_cache(self) -> torch.Tensor:
939
+ inv_freq = self._compute_inv_freq(self.base)
940
+
941
+ # self.max_position_embeddings here is number of image patches
942
+ # i.e. (image_size // patch_size) ** 2
943
+ num_patches = self.max_position_embeddings
944
+ img_idx = torch.arange(num_patches,
945
+ dtype=torch.int32) \
946
+ .reshape(num_patches, 1)
947
+ img_idx = torch.cat([img_idx, img_idx[:1]], dim=0)
948
+ img_idx[-1, -1] = -2 # set to ID_CLS_TOKEN
949
+ num_patches_single_dim = int(math.sqrt(num_patches))
950
+ frequencies_x = img_idx % num_patches_single_dim
951
+ frequencies_y = img_idx // num_patches_single_dim
952
+ freqs_x = ((frequencies_x + 1)[..., None] *
953
+ inv_freq[None, None, :]).repeat_interleave(2, dim=-1)
954
+ freqs_y = ((frequencies_y + 1)[..., None] *
955
+ inv_freq[None, None, :]).repeat_interleave(2, dim=-1)
956
+ freqs = torch.cat([freqs_x, freqs_y],
957
+ dim=-1).float().contiguous()[..., ::2]
958
+ freqs = freqs.masked_fill(img_idx.reshape(-1, 1, 1) < 0, 0)
959
+ cache = torch.view_as_complex(
960
+ torch.stack([torch.cos(freqs), torch.sin(freqs)], dim=-1))
961
+ return cache
962
+
963
+ def forward(
964
+ self,
965
+ query: torch.Tensor,
966
+ key: Optional[torch.Tensor] = None,
967
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
968
+ assert key is not None
969
+ self.cos_sin_cache: torch.Tensor = self.cos_sin_cache.to(query.device)
970
+ query_ = torch.view_as_complex(query.float().reshape(
971
+ *query.shape[:-1], -1, 2))
972
+ key_ = torch.view_as_complex(key.float().reshape(
973
+ *key.shape[:-1], -1, 2))
974
+ broadcast_shape = [
975
+ d if i == 1 or i == (query_.ndim - 1) else 1
976
+ for i, d in enumerate(query_.shape)
977
+ ]
978
+ freqs_ci = self.cos_sin_cache.view(*broadcast_shape)
979
+ query_out = torch.view_as_real(query_ * freqs_ci).flatten(3)
980
+ key_out = torch.view_as_real(key_ * freqs_ci).flatten(3)
981
+ return query_out.type_as(query), key_out.type_as(key)
982
+
983
+
984
+ class MRotaryEmbedding(RotaryEmbedding):
985
+ """Rotary Embedding with Multimodal Sections."""
986
+
987
+ def __init__(
988
+ self,
989
+ head_size: int,
990
+ rotary_dim: int,
991
+ max_position_embeddings: int,
992
+ base: int,
993
+ is_neox_style: bool,
994
+ dtype: torch.dtype,
995
+ mrope_section: Optional[list[int]] = None,
996
+ ) -> None:
997
+ # In Qwen2.5-VL, the maximum index value is related to the duration of
998
+ # the input video. We enlarge max_position_embeddings to 4 times to get
999
+ # a larger the cos and sin cache.
1000
+ self.cache_max_position_num = max_position_embeddings * 4
1001
+ super().__init__(head_size, rotary_dim, self.cache_max_position_num,
1002
+ base, is_neox_style, dtype)
1003
+
1004
+ self.mrope_section = mrope_section
1005
+ if self.mrope_section:
1006
+ assert sum(self.mrope_section) == rotary_dim // 2
1007
+
1008
+ def forward(
1009
+ self,
1010
+ positions: torch.Tensor,
1011
+ query: torch.Tensor,
1012
+ key: Optional[torch.Tensor] = None,
1013
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
1014
+ """PyTorch-native implementation equivalent to forward().
1015
+
1016
+ Args:
1017
+ positions:
1018
+ [num_tokens,] (text only) or
1019
+ [3, num_tokens] (T/H/W positions with multimodal inputs)
1020
+ query: [num_tokens, num_heads * head_size]
1021
+ key: [num_tokens, num_kv_heads * head_size]
1022
+ """
1023
+ assert positions.ndim == 1 or positions.ndim == 2
1024
+ assert key is not None
1025
+
1026
+ num_tokens = positions.shape[-1]
1027
+ cos_sin = self.cos_sin_cache[positions]
1028
+ cos, sin = cos_sin.chunk(2, dim=-1)
1029
+ if positions.ndim == 2:
1030
+ assert self.mrope_section
1031
+
1032
+ cos = torch.cat([
1033
+ m[i]
1034
+ for i, m in enumerate(cos.split(self.mrope_section, dim=-1))
1035
+ ],
1036
+ dim=-1)
1037
+ sin = torch.cat([
1038
+ m[i]
1039
+ for i, m in enumerate(sin.split(self.mrope_section, dim=-1))
1040
+ ],
1041
+ dim=-1)
1042
+
1043
+ query_shape = query.shape
1044
+ query = query.view(num_tokens, -1, self.head_size)
1045
+ query_rot = query[..., :self.rotary_dim]
1046
+ query_pass = query[..., self.rotary_dim:]
1047
+ query_rot = _apply_rotary_emb(query_rot, cos, sin, self.is_neox_style)
1048
+ query = torch.cat((query_rot, query_pass), dim=-1).reshape(query_shape)
1049
+
1050
+ key_shape = key.shape
1051
+ key = key.view(num_tokens, -1, self.head_size)
1052
+ key_rot = key[..., :self.rotary_dim]
1053
+ key_pass = key[..., self.rotary_dim:]
1054
+ key_rot = _apply_rotary_emb(key_rot, cos, sin, self.is_neox_style)
1055
+ key = torch.cat((key_rot, key_pass), dim=-1).reshape(key_shape)
1056
+ return query, key
1057
+
1058
+ @classmethod
1059
+ def get_input_positions(
1060
+ cls,
1061
+ input_tokens: list[int],
1062
+ hf_config: PretrainedConfig,
1063
+ image_grid_thw: Optional[Union[list[list[int]], torch.Tensor]],
1064
+ video_grid_thw: Optional[Union[list[list[int]], torch.Tensor]],
1065
+ second_per_grid_ts: Optional[list[float]],
1066
+ context_len: int = 0,
1067
+ seq_len: Optional[int] = None,
1068
+ audio_feature_lengths: Optional[torch.Tensor] = None,
1069
+ use_audio_in_video: bool = False,
1070
+ ) -> tuple[list[list[int]], int]:
1071
+ """Get mrope input positions and delta value."""
1072
+
1073
+ image_grid_thw = [] if image_grid_thw is None else image_grid_thw
1074
+ video_grid_thw = [] if video_grid_thw is None else video_grid_thw
1075
+ second_per_grid_ts = [] if second_per_grid_ts is None else \
1076
+ second_per_grid_ts
1077
+
1078
+ llm_positions, mrope_position_delta = \
1079
+ cls.get_input_positions_tensor(
1080
+ input_tokens=input_tokens,
1081
+ hf_config=hf_config,
1082
+ image_grid_thw=image_grid_thw,
1083
+ video_grid_thw=video_grid_thw,
1084
+ second_per_grid_ts=second_per_grid_ts,
1085
+ context_len=context_len,
1086
+ seq_len=seq_len,
1087
+ audio_feature_lengths=audio_feature_lengths,
1088
+ use_audio_in_video=use_audio_in_video,
1089
+ )
1090
+
1091
+ return llm_positions.tolist(), mrope_position_delta
1092
+
1093
+ @classmethod
1094
+ def get_input_positions_tensor(
1095
+ cls,
1096
+ input_tokens: list[int],
1097
+ hf_config: PretrainedConfig,
1098
+ image_grid_thw: Union[list[list[int]], torch.Tensor],
1099
+ video_grid_thw: Union[list[list[int]], torch.Tensor],
1100
+ second_per_grid_ts: list[float],
1101
+ context_len: int = 0,
1102
+ seq_len: Optional[int] = None,
1103
+ audio_feature_lengths: Optional[torch.Tensor] = None,
1104
+ use_audio_in_video: bool = False,
1105
+ ) -> tuple[torch.Tensor, int]:
1106
+ from vllm.transformers_utils.config import thinker_uses_mrope
1107
+ if thinker_uses_mrope(hf_config):
1108
+ return cls._omni_get_input_positions_tensor(
1109
+ input_tokens=input_tokens,
1110
+ hf_config=hf_config,
1111
+ image_grid_thw=image_grid_thw,
1112
+ video_grid_thw=video_grid_thw,
1113
+ second_per_grid_ts=second_per_grid_ts,
1114
+ context_len=context_len,
1115
+ seq_len=seq_len,
1116
+ audio_feature_lengths=audio_feature_lengths,
1117
+ use_audio_in_video=use_audio_in_video,
1118
+ )
1119
+ else:
1120
+ return cls._vl_get_input_positions_tensor(
1121
+ input_tokens=input_tokens,
1122
+ hf_config=hf_config,
1123
+ image_grid_thw=image_grid_thw,
1124
+ video_grid_thw=video_grid_thw,
1125
+ second_per_grid_ts=second_per_grid_ts,
1126
+ context_len=context_len,
1127
+ seq_len=seq_len,
1128
+ )
1129
+
1130
+ @classmethod
1131
+ def _vl_get_input_positions_tensor(
1132
+ cls,
1133
+ input_tokens: list[int],
1134
+ hf_config: PretrainedConfig,
1135
+ image_grid_thw: Union[list[list[int]], torch.Tensor],
1136
+ video_grid_thw: Union[list[list[int]], torch.Tensor],
1137
+ second_per_grid_ts: list[float],
1138
+ context_len: int = 0,
1139
+ seq_len: Optional[int] = None,
1140
+ ) -> tuple[torch.Tensor, int]:
1141
+ """Get mrope input positions and delta value."""
1142
+
1143
+ image_token_id = hf_config.image_token_id
1144
+ video_token_id = hf_config.video_token_id
1145
+ vision_start_token_id = hf_config.vision_start_token_id
1146
+ spatial_merge_size = hf_config.vision_config.spatial_merge_size
1147
+ tokens_per_second = getattr(hf_config.vision_config,
1148
+ "tokens_per_second", 1.0)
1149
+
1150
+ input_tokens_tensor = torch.tensor(input_tokens)
1151
+ vision_start_indices = torch.argwhere(
1152
+ input_tokens_tensor == vision_start_token_id).squeeze(1)
1153
+ vision_tokens = input_tokens_tensor[vision_start_indices + 1]
1154
+ image_nums = (vision_tokens == image_token_id).sum()
1155
+ video_nums = (vision_tokens == video_token_id).sum()
1156
+ llm_pos_ids_list: list = []
1157
+
1158
+ st = 0
1159
+ remain_images, remain_videos = image_nums, video_nums
1160
+
1161
+ image_index, video_index = 0, 0
1162
+ for _ in range(image_nums + video_nums):
1163
+ video_second_per_grid_t = 0.0
1164
+ if image_token_id in input_tokens and remain_images > 0:
1165
+ ed_image = input_tokens.index(image_token_id, st)
1166
+ else:
1167
+ ed_image = len(input_tokens) + 1
1168
+ if video_token_id in input_tokens and remain_videos > 0:
1169
+ ed_video = input_tokens.index(video_token_id, st)
1170
+ else:
1171
+ ed_video = len(input_tokens) + 1
1172
+ if ed_image < ed_video:
1173
+ t, h, w = (
1174
+ image_grid_thw[image_index][0],
1175
+ image_grid_thw[image_index][1],
1176
+ image_grid_thw[image_index][2],
1177
+ )
1178
+ image_index += 1
1179
+ remain_images -= 1
1180
+ ed = ed_image
1181
+ else:
1182
+ t, h, w = (
1183
+ video_grid_thw[video_index][0],
1184
+ video_grid_thw[video_index][1],
1185
+ video_grid_thw[video_index][2],
1186
+ )
1187
+ video_second_per_grid_t = 1.0
1188
+ if second_per_grid_ts:
1189
+ video_second_per_grid_t = second_per_grid_ts[video_index]
1190
+ video_index += 1
1191
+ remain_videos -= 1
1192
+ ed = ed_video
1193
+
1194
+ llm_grid_t, llm_grid_h, llm_grid_w = \
1195
+ t, h // spatial_merge_size, w // spatial_merge_size
1196
+ text_len = ed - st
1197
+
1198
+ st_idx = llm_pos_ids_list[-1].max() + 1 if len(
1199
+ llm_pos_ids_list) > 0 else 0
1200
+ llm_pos_ids_list.append(
1201
+ torch.arange(text_len).view(1, -1).expand(3, -1) + st_idx)
1202
+
1203
+ t_index = (torch.arange(llm_grid_t).view(-1, 1).expand(
1204
+ -1, llm_grid_h * llm_grid_w) * video_second_per_grid_t *
1205
+ tokens_per_second).long().flatten()
1206
+
1207
+ h_index = torch.arange(llm_grid_h).view(1, -1, 1).expand(
1208
+ llm_grid_t, -1, llm_grid_w).flatten()
1209
+ w_index = torch.arange(llm_grid_w).view(1, 1, -1).expand(
1210
+ llm_grid_t, llm_grid_h, -1).flatten()
1211
+ llm_pos_ids_list.append(
1212
+ torch.stack([t_index, h_index, w_index]) + text_len + st_idx)
1213
+ st = ed + llm_grid_t * llm_grid_h * llm_grid_w
1214
+
1215
+ if st < len(input_tokens):
1216
+ st_idx = llm_pos_ids_list[-1].max() + 1 if len(
1217
+ llm_pos_ids_list) > 0 else 0
1218
+ text_len = len(input_tokens) - st
1219
+ llm_pos_ids_list.append(
1220
+ torch.arange(text_len).view(1, -1).expand(3, -1) + st_idx)
1221
+
1222
+ llm_positions = torch.cat(llm_pos_ids_list, dim=1).reshape(3, -1)
1223
+ mrope_position_delta = (llm_positions.max() + 1 -
1224
+ len(input_tokens)).item()
1225
+ llm_positions = llm_positions[:, context_len:seq_len]
1226
+
1227
+ return llm_positions, mrope_position_delta
1228
+
1229
+ @classmethod
1230
+ def _omni_get_input_positions_tensor(
1231
+ cls,
1232
+ input_tokens: list[int],
1233
+ hf_config: PretrainedConfig,
1234
+ image_grid_thw: Union[list[list[int]], torch.Tensor],
1235
+ video_grid_thw: Union[list[list[int]], torch.Tensor],
1236
+ second_per_grid_ts: Optional[list[float]] = None,
1237
+ context_len: int = 0,
1238
+ seq_len: Optional[int] = None,
1239
+ audio_feature_lengths: Optional[torch.Tensor] = None,
1240
+ use_audio_in_video: bool = False,
1241
+ ) -> tuple[torch.Tensor, int]:
1242
+ """Get mrope input positions and delta value (Qwen2.5-Omni version).
1243
+
1244
+ Differences from MRotaryEmbedding:
1245
+ 1. Add audio support (and related `audio_feature_lengths`).
1246
+ 2. Add `use_audio_in_video` option to read audio from video inputs.
1247
+ In this case, audio and vision position ids will be split into
1248
+ chunks and interleaved.
1249
+
1250
+ Example:
1251
+
1252
+ (V_i are vision position ids, A_i are audio position ids)
1253
+
1254
+ |V_1 ... V_n|A_1 ... A_n|V_n+1 ... V_2n|A_n+1 ... A_2n|...
1255
+ |vision chunk 1|audio chunk 1|vision chunk 2|audio chunk 2 |...
1256
+ """
1257
+
1258
+ # TODO(fyabc): refactor and share more code with
1259
+ # _vl_get_input_positions_tensor.
1260
+
1261
+ thinker_config = hf_config.thinker_config
1262
+ audio_token_id = thinker_config.audio_token_index
1263
+ image_token_id = thinker_config.image_token_index
1264
+ video_token_id = thinker_config.video_token_index
1265
+ audio_start_token_id = thinker_config.audio_start_token_id
1266
+ audio_end_token_id = thinker_config.audio_end_token_id
1267
+ vision_start_token_id = thinker_config.vision_start_token_id
1268
+ vision_end_token_id = thinker_config.vision_end_token_id
1269
+ seconds_per_chunk = thinker_config.seconds_per_chunk
1270
+ spatial_merge_size = thinker_config.vision_config.spatial_merge_size
1271
+ tokens_per_second = getattr(thinker_config.vision_config,
1272
+ "tokens_per_second", 25)
1273
+
1274
+ if isinstance(image_grid_thw, list):
1275
+ image_grid_thw = torch.tensor(image_grid_thw)
1276
+ if isinstance(video_grid_thw, list):
1277
+ video_grid_thw = torch.tensor(video_grid_thw)
1278
+
1279
+ src_item = input_tokens
1280
+ audio_seqlens = audio_feature_lengths
1281
+ if not second_per_grid_ts:
1282
+ second_per_grid_ts = [1] * video_grid_thw.shape[0]
1283
+ audio_idx = 0
1284
+ video_idx = 0
1285
+ image_idx = 0
1286
+ new_src_item: list[int] = []
1287
+ llm_pos_ids_list: list[torch.Tensor] = []
1288
+
1289
+ idx = 0
1290
+ while idx < len(src_item):
1291
+ new_src_item_len = len(new_src_item)
1292
+ start_idx = llm_pos_ids_list[-1].max() + 1 if len(
1293
+ llm_pos_ids_list) > 0 else 0
1294
+ if src_item[idx] not in [
1295
+ audio_token_id, video_token_id, image_token_id
1296
+ ]:
1297
+ if use_audio_in_video and idx > 0:
1298
+ if src_item[idx] == vision_end_token_id and \
1299
+ src_item[idx - 1] == audio_end_token_id:
1300
+ # processing the <|audio_eos|> before <|vision_eos|>
1301
+ start_idx -= 1
1302
+ elif src_item[idx] == audio_start_token_id and \
1303
+ src_item[idx - 1] == vision_start_token_id:
1304
+ # processing the <|audio_bos|> after <|vision_eos|>
1305
+ start_idx -= 1
1306
+ new_src_item.append(src_item[idx])
1307
+ llm_pos_ids = torch.tensor([start_idx],
1308
+ dtype=torch.long).expand(3, -1)
1309
+ llm_pos_ids_list.append(llm_pos_ids)
1310
+ elif src_item[idx] == audio_token_id:
1311
+ assert audio_seqlens is not None
1312
+ audio_seqlen = audio_seqlens[audio_idx]
1313
+ place_num = (((audio_seqlen - 1) // 2 + 1 - 2) // 2 + 1)
1314
+ new_src_item.extend([audio_token_id] * place_num)
1315
+ llm_pos_ids = torch.arange(place_num).expand(3, -1) + start_idx
1316
+ llm_pos_ids_list.append(llm_pos_ids)
1317
+ audio_idx += 1
1318
+ elif src_item[idx] == image_token_id:
1319
+ grid_t = image_grid_thw[image_idx][0]
1320
+ grid_hs = image_grid_thw[:, 1]
1321
+ grid_ws = image_grid_thw[:, 2]
1322
+ t_index = (torch.arange(grid_t) * 1 * tokens_per_second).long()
1323
+ llm_pos_ids = cls._get_llm_pos_ids_for_vision(
1324
+ start_idx, image_idx, spatial_merge_size, t_index, grid_hs,
1325
+ grid_ws)
1326
+ llm_pos_ids_list.append(llm_pos_ids)
1327
+ vision_seqlen = image_grid_thw[image_idx].prod() // (
1328
+ spatial_merge_size**2)
1329
+ new_src_item.extend([image_token_id] * vision_seqlen)
1330
+ image_idx += 1
1331
+ elif src_item[idx] == video_token_id and not use_audio_in_video:
1332
+ grid_t = video_grid_thw[video_idx][0]
1333
+ grid_hs = video_grid_thw[:, 1]
1334
+ grid_ws = video_grid_thw[:, 2]
1335
+ t_index = (torch.arange(grid_t) *
1336
+ second_per_grid_ts[video_idx] *
1337
+ tokens_per_second).long()
1338
+ llm_pos_ids = cls._get_llm_pos_ids_for_vision(
1339
+ start_idx, video_idx, spatial_merge_size, t_index, grid_hs,
1340
+ grid_ws)
1341
+ llm_pos_ids_list.append(llm_pos_ids)
1342
+ vision_seqlen = video_grid_thw[video_idx].prod() // (
1343
+ spatial_merge_size**2)
1344
+ new_src_item.extend([video_token_id] * vision_seqlen)
1345
+ video_idx += 1
1346
+ else:
1347
+ # read audio from video
1348
+ assert audio_seqlens is not None
1349
+ audio_seqlen = audio_seqlens[audio_idx]
1350
+ vision_seqlen = video_grid_thw[video_idx].prod() // (
1351
+ spatial_merge_size**2)
1352
+ grid_t = video_grid_thw[video_idx][0]
1353
+ grid_h = video_grid_thw[video_idx][1]
1354
+ grid_w = video_grid_thw[video_idx][2]
1355
+ grid_hs = video_grid_thw[:, 1]
1356
+ grid_ws = video_grid_thw[:, 2]
1357
+ t_ntoken_per_chunk = int(tokens_per_second * seconds_per_chunk)
1358
+ t_index = (torch.arange(grid_t) *
1359
+ second_per_grid_ts[video_idx] *
1360
+ tokens_per_second).long()
1361
+ t_index_split_chunk = cls._split_list_into_ranges(
1362
+ t_index, t_ntoken_per_chunk)
1363
+ place_num = (((audio_seqlen - 1) // 2 + 1 - 2) // 2 + 1) + 2
1364
+ pure_audio_len = place_num - 2
1365
+ added_audio_len = 0
1366
+ audio_llm_pos_ids_list: list[torch.Tensor] = []
1367
+ for t_chunk in t_index_split_chunk:
1368
+ vision_ntoken_per_chunk = len(
1369
+ t_chunk) * grid_h * grid_w // (spatial_merge_size**2)
1370
+ new_src_item.extend([video_token_id] *
1371
+ vision_ntoken_per_chunk)
1372
+ vision_llm_pos_ids_list = cls._get_llm_pos_ids_for_vision(
1373
+ start_idx, video_idx, spatial_merge_size, t_chunk,
1374
+ grid_hs, grid_ws).split(1, dim=1)
1375
+ llm_pos_ids_list.extend(vision_llm_pos_ids_list)
1376
+ new_src_item.extend(
1377
+ min(t_ntoken_per_chunk, pure_audio_len -
1378
+ added_audio_len) * [audio_token_id])
1379
+ audio_start_idx = start_idx if len(
1380
+ audio_llm_pos_ids_list
1381
+ ) == 0 else audio_llm_pos_ids_list[-1][0].item() + 1
1382
+ if min(t_ntoken_per_chunk,
1383
+ pure_audio_len - added_audio_len) > 0:
1384
+ audio_llm_pos_ids_list = (torch.arange(
1385
+ min(t_ntoken_per_chunk, pure_audio_len -
1386
+ added_audio_len)).expand(3, -1) +
1387
+ audio_start_idx).split(1,
1388
+ dim=1)
1389
+ else:
1390
+ audio_llm_pos_ids_list = []
1391
+ added_audio_len += min(t_ntoken_per_chunk,
1392
+ pure_audio_len - added_audio_len)
1393
+ llm_pos_ids_list.extend(audio_llm_pos_ids_list)
1394
+ if added_audio_len < pure_audio_len:
1395
+ new_src_item.extend(
1396
+ (pure_audio_len - added_audio_len) * [audio_token_id])
1397
+ audio_llm_pos_ids_list = (
1398
+ torch.arange(pure_audio_len - added_audio_len).expand(
1399
+ 3, -1) + llm_pos_ids_list[-1].max() + 1).split(
1400
+ 1, dim=1)
1401
+ llm_pos_ids_list.extend(audio_llm_pos_ids_list)
1402
+ audio_idx += 1
1403
+ video_idx += 1
1404
+ # move to the next token
1405
+ idx += len(new_src_item) - new_src_item_len
1406
+
1407
+ llm_positions = torch.cat(llm_pos_ids_list, dim=1)
1408
+ mrope_position_delta = torch.cat(llm_pos_ids_list,
1409
+ dim=1).max() + 1 - len(src_item)
1410
+ llm_positions = llm_positions[:, context_len:seq_len]
1411
+
1412
+ return llm_positions, mrope_position_delta
1413
+
1414
+ @staticmethod
1415
+ def _get_llm_pos_ids_for_vision(
1416
+ start_idx: int,
1417
+ vision_idx: int,
1418
+ spatial_merge_size: int,
1419
+ t_index: list[int],
1420
+ grid_hs: torch.Tensor,
1421
+ grid_ws: torch.Tensor,
1422
+ ) -> torch.Tensor:
1423
+ llm_pos_ids_list = []
1424
+ llm_grid_h = grid_hs[vision_idx] // spatial_merge_size
1425
+ llm_grid_w = grid_ws[vision_idx] // spatial_merge_size
1426
+ h_index = (torch.arange(llm_grid_h).view(1, -1, 1).expand(
1427
+ len(t_index), -1, llm_grid_w).flatten())
1428
+ w_index = (torch.arange(llm_grid_w).view(1, 1, -1).expand(
1429
+ len(t_index), llm_grid_h, -1).flatten())
1430
+ t_index_tensor = torch.Tensor(t_index).to(llm_grid_h.device).view(
1431
+ -1, 1).expand(-1, llm_grid_h * llm_grid_w).long().flatten()
1432
+ _llm_pos_ids = torch.stack([t_index_tensor, h_index, w_index])
1433
+ llm_pos_ids_list.append(_llm_pos_ids + start_idx)
1434
+ llm_pos_ids = torch.cat(llm_pos_ids_list, dim=1)
1435
+ return llm_pos_ids
1436
+
1437
+ @staticmethod
1438
+ def _split_list_into_ranges(lst: torch.Tensor,
1439
+ interval: int) -> list[list[int]]:
1440
+ ranges: list[list[int]] = [[]
1441
+ for _ in range((max(lst) // interval) + 1)]
1442
+ for num in lst:
1443
+ index = num // interval
1444
+ ranges[index].append(num)
1445
+ return ranges
1446
+
1447
+ @staticmethod
1448
+ def get_next_input_positions(
1449
+ mrope_position_delta: int,
1450
+ context_len: int,
1451
+ seq_len: int,
1452
+ ) -> list[list[int]]:
1453
+ return [
1454
+ list(
1455
+ range(context_len + mrope_position_delta,
1456
+ seq_len + mrope_position_delta)) for _ in range(3)
1457
+ ]
1458
+
1459
+ @staticmethod
1460
+ def get_next_input_positions_tensor(
1461
+ mrope_position_delta: int,
1462
+ context_len: int,
1463
+ seq_len: int,
1464
+ ) -> torch.Tensor:
1465
+ return torch.arange(
1466
+ mrope_position_delta + context_len,
1467
+ mrope_position_delta + seq_len,
1468
+ ).expand(3, -1)
1469
+
1470
+ @classmethod
1471
+ def omni_get_updates_use_audio_in_video(
1472
+ cls,
1473
+ thinker_config: PretrainedConfig,
1474
+ audio_len: int,
1475
+ video_grid_thw: Union[list[int], torch.Tensor],
1476
+ video_second_per_grid_t: float,
1477
+ ) -> list[int]:
1478
+ """Get video prompt updates when `use_audio_in_video` is True.
1479
+
1480
+ In this case, audio and vision update ids will be split into
1481
+ chunks and interleaved (details in `_omni_get_input_positions_tensor`).
1482
+
1483
+ <|video_bos|><|VIDEO|><|video_eos|> =>
1484
+ <|video_bos|><|audio_bos|>(... chunks ...)<|audio_eos|><|video_eos|>
1485
+ """
1486
+
1487
+ audio_token_id = thinker_config.audio_token_index
1488
+ video_token_id = thinker_config.video_token_index
1489
+ audio_start_token_id = thinker_config.audio_start_token_id
1490
+ audio_end_token_id = thinker_config.audio_end_token_id
1491
+ seconds_per_chunk = thinker_config.seconds_per_chunk
1492
+ spatial_merge_size = thinker_config.vision_config.spatial_merge_size
1493
+ tokens_per_second = getattr(thinker_config.vision_config,
1494
+ "tokens_per_second", 25)
1495
+
1496
+ grid_t = video_grid_thw[0]
1497
+ grid_h = video_grid_thw[1]
1498
+ grid_w = video_grid_thw[2]
1499
+ t_ntoken_per_chunk = int(tokens_per_second * seconds_per_chunk)
1500
+ t_index = (torch.arange(grid_t) * video_second_per_grid_t *
1501
+ tokens_per_second).long()
1502
+ t_index_split_chunk = cls._split_list_into_ranges(
1503
+ t_index, t_ntoken_per_chunk)
1504
+
1505
+ updates = [audio_start_token_id]
1506
+ added_audio_len = 0
1507
+ for t_chunk in t_index_split_chunk:
1508
+ vision_ntoken_per_chunk = len(t_chunk) * grid_h * grid_w // (
1509
+ spatial_merge_size**2)
1510
+ updates.extend([video_token_id] * vision_ntoken_per_chunk)
1511
+
1512
+ audio_chunk_size = min(t_ntoken_per_chunk,
1513
+ audio_len - added_audio_len)
1514
+ updates.extend(audio_chunk_size * [audio_token_id])
1515
+ added_audio_len += audio_chunk_size
1516
+ if added_audio_len < audio_len:
1517
+ updates.extend((audio_len - added_audio_len) * [audio_token_id])
1518
+ updates.extend([audio_end_token_id])
1519
+
1520
+ return updates
1521
+
1522
+
1523
+ @CustomOp.register("dual_chunk_rotary_embedding")
1524
+ class DualChunkRotaryEmbedding(CustomOp):
1525
+ """Rotary positional embedding for Dual Chunk Attention."""
1526
+
1527
+ def __init__(
1528
+ self,
1529
+ head_size: int,
1530
+ rotary_dim: int,
1531
+ max_position_embeddings: int,
1532
+ base: int,
1533
+ is_neox_style: bool,
1534
+ dtype: torch.dtype,
1535
+ chunk_size: int,
1536
+ local_size: int,
1537
+ ) -> None:
1538
+ super().__init__()
1539
+ self.head_size = head_size
1540
+ self.rotary_dim = rotary_dim
1541
+ self.max_position_embeddings = max_position_embeddings
1542
+ self.base = base
1543
+ self.is_neox_style = is_neox_style
1544
+ self.chunk_size = chunk_size
1545
+ self.local_size = local_size
1546
+ self.dtype = dtype
1547
+ self.device = torch.device(f"cuda:{torch.cuda.current_device()}")
1548
+ (q_cache, qc_cache, k_cache, qc_no_clamp_cache,
1549
+ q_inter_cache) = self._compute_cos_sin_cache()
1550
+
1551
+ self.register_buffer("cos_sin_q_cache", q_cache, persistent=False)
1552
+ self.register_buffer("cos_sin_qc_cache", qc_cache, persistent=False)
1553
+ self.register_buffer("cos_sin_k_cache", k_cache, persistent=False)
1554
+ self.register_buffer("cos_sin_qc_no_clamp_cache",
1555
+ qc_no_clamp_cache,
1556
+ persistent=False)
1557
+ self.register_buffer("cos_sin_q_inter_cache",
1558
+ q_inter_cache,
1559
+ persistent=False)
1560
+
1561
+ def _compute_inv_freq(self, base: Union[int, float]) -> torch.Tensor:
1562
+ """Compute the inverse frequency."""
1563
+ # NOTE(woosuk): The HF implementation uses `torch.arange(...).float()`.
1564
+ # However, we use `torch.arange(..., dtype=torch.float)` instead to
1565
+ # avoid numerical issues with large base values (e.g., 10000000).
1566
+ # This may cause a slight numerical difference between the HF
1567
+ # implementation and ours.
1568
+ # NOTE(woosuk): To exactly match the HF implementation, we need to
1569
+ # use CPU to compute the cache and then move it to GPU. However, we
1570
+ # create the cache on GPU for faster initialization. This may cause
1571
+ # a slight numerical difference between the HF implementation and ours.
1572
+ inv_freq = 1.0 / (base**(torch.arange(
1573
+ 0, self.rotary_dim, 2, dtype=torch.float) / self.rotary_dim))
1574
+ return inv_freq
1575
+
1576
+ def _compute_cos_sin_cache(self) -> torch.Tensor:
1577
+ """Compute the cos and sin cache."""
1578
+ inv_freq = self._compute_inv_freq(self.base)
1579
+ chunk_len = self.chunk_size - self.local_size
1580
+ q_t = torch.arange(chunk_len, dtype=torch.float)
1581
+ qc_t = (torch.arange(chunk_len, dtype=torch.float) +
1582
+ chunk_len).clamp(max=self.chunk_size)
1583
+ k_t = torch.arange(self.max_position_embeddings,
1584
+ dtype=torch.float) % chunk_len
1585
+
1586
+ # count from chunk_len, no clamp(self.chunk_size) restriction
1587
+ qc_no_clamp_t = torch.arange(chunk_len, dtype=torch.float) + chunk_len
1588
+ # count from self.chunk_size for q_inter's rope
1589
+ q_inter_t = torch.arange(chunk_len,
1590
+ dtype=torch.float) + self.chunk_size
1591
+
1592
+ q_freqs = torch.outer(q_t, inv_freq)
1593
+ qc_freqs = torch.outer(qc_t, inv_freq)
1594
+ k_freqs = torch.outer(k_t, inv_freq)
1595
+ qc_no_clamp_freqs = torch.outer(qc_no_clamp_t, inv_freq)
1596
+ q_inter_freqs = torch.outer(q_inter_t, inv_freq)
1597
+
1598
+ q_cos = q_freqs.cos()
1599
+ q_sin = q_freqs.sin()
1600
+ qc_cos = qc_freqs.cos()
1601
+ qc_sin = qc_freqs.sin()
1602
+ k_cos = k_freqs.cos()
1603
+ k_sin = k_freqs.sin()
1604
+
1605
+ qc_no_clamp_cos = qc_no_clamp_freqs.cos()
1606
+ qc_no_clamp_sin = qc_no_clamp_freqs.sin()
1607
+ q_inter_cos = q_inter_freqs.cos()
1608
+ q_inter_sin = q_inter_freqs.sin()
1609
+
1610
+ q_cache = torch.cat((q_cos, q_sin), dim=-1).to(dtype=self.dtype,
1611
+ device=self.device)
1612
+ qc_cache = torch.cat((qc_cos, qc_sin), dim=-1).to(dtype=self.dtype,
1613
+ device=self.device)
1614
+ k_cache = torch.cat((k_cos, k_sin), dim=-1).to(dtype=self.dtype,
1615
+ device=self.device)
1616
+ qc_no_clamp_cache = torch.cat((qc_no_clamp_cos, qc_no_clamp_sin),
1617
+ dim=-1).to(dtype=self.dtype,
1618
+ device=self.device)
1619
+ q_inter_cache = torch.cat((q_inter_cos, q_inter_sin),
1620
+ dim=-1).to(dtype=self.dtype,
1621
+ device=self.device)
1622
+ return q_cache, qc_cache, k_cache, qc_no_clamp_cache, q_inter_cache
1623
+
1624
+ def forward(
1625
+ self,
1626
+ positions: torch.Tensor,
1627
+ query: torch.Tensor,
1628
+ key: torch.Tensor,
1629
+ offsets: Optional[torch.Tensor] = None,
1630
+ ) -> tuple[torch.Tensor, torch.Tensor]:
1631
+ query = query.view(*query.shape[:-1], -1, self.head_size)
1632
+ key = key.view(*key.shape[:-1], -1, self.head_size)
1633
+ query_rot = query[..., :self.rotary_dim]
1634
+ key_rot = key[..., :self.rotary_dim]
1635
+ if self.rotary_dim < self.head_size:
1636
+ query_pass = query[..., self.rotary_dim:]
1637
+ key_pass = key[..., self.rotary_dim:]
1638
+ else:
1639
+ query_pass = None
1640
+ key_pass = None
1641
+
1642
+ positions_with_offsets = (torch.add(positions, offsets)
1643
+ if offsets is not None else positions)
1644
+ key = self._apply_rotary_embedding(
1645
+ self.cos_sin_k_cache[positions_with_offsets], key_rot, key_pass)
1646
+ chunk_len = self.chunk_size - self.local_size
1647
+ query = self._apply_rotary_embedding(
1648
+ self.cos_sin_q_cache[positions_with_offsets % chunk_len],
1649
+ query_rot, query_pass)
1650
+ query_succ = self._apply_rotary_embedding(
1651
+ self.cos_sin_qc_cache[positions_with_offsets % chunk_len],
1652
+ query_rot, query_pass)
1653
+ query_inter = self._apply_rotary_embedding(
1654
+ self.cos_sin_qc_cache[chunk_len - 1].repeat(positions.shape[0], 1),
1655
+ query_rot, query_pass)
1656
+ query_succ_critical = self._apply_rotary_embedding(
1657
+ self.cos_sin_qc_no_clamp_cache[positions_with_offsets % chunk_len],
1658
+ query_rot, query_pass)
1659
+ query_inter_critical = self._apply_rotary_embedding(
1660
+ self.cos_sin_q_inter_cache[positions_with_offsets % chunk_len],
1661
+ query_rot, query_pass)
1662
+
1663
+ # merge query into one tensor to simplify the interfaces
1664
+ query = torch.cat((
1665
+ query,
1666
+ query_succ,
1667
+ query_inter,
1668
+ query_succ_critical,
1669
+ query_inter_critical,
1670
+ ),
1671
+ dim=-1)
1672
+ return query, key
1673
+
1674
+ def _apply_rotary_embedding(self, cos_sin, hidden_rot, hidden_pass):
1675
+ cos, sin = cos_sin.chunk(2, dim=-1)
1676
+ if self.is_neox_style:
1677
+ # NOTE(woosuk): Here we assume that the positions tensor has the
1678
+ # shape [batch_size, seq_len].
1679
+ cos = cos.repeat(1, 1, 2).unsqueeze(-2)
1680
+ sin = sin.repeat(1, 1, 2).unsqueeze(-2)
1681
+ else:
1682
+ cos = cos.repeat_interleave(2, dim=-1).unsqueeze(-2)
1683
+ sin = sin.repeat_interleave(2, dim=-1).unsqueeze(-2)
1684
+ rotate_fn = _rotate_neox if self.is_neox_style else _rotate_gptj
1685
+ hidden_rot = hidden_rot * cos + rotate_fn(hidden_rot) * sin
1686
+
1687
+ if self.rotary_dim < self.head_size:
1688
+ hidden = torch.cat((hidden_rot, hidden_pass), dim=-1)
1689
+ else:
1690
+ hidden = hidden_rot
1691
+ return hidden.flatten(-2).squeeze(0)
1692
+
1693
+ def extra_repr(self) -> str:
1694
+ s = f"head_size={self.head_size}, rotary_dim={self.rotary_dim}"
1695
+ s += f", max_position_embeddings={self.max_position_embeddings}"
1696
+ s += f", base={self.base}, is_neox_style={self.is_neox_style}"
1697
+ s += f", chunk_size={self.chunk_size}, local_size={self.local_size}"
1698
+ return s
1699
+
1700
+
1701
+ _ROPE_DICT: dict[tuple, RotaryEmbedding] = {}
1702
+
1703
+
1704
+ def get_rope(
1705
+ head_size: int,
1706
+ rotary_dim: int,
1707
+ max_position: int,
1708
+ base: int,
1709
+ is_neox_style: bool = True,
1710
+ rope_scaling: Optional[dict[str, Any]] = None,
1711
+ dtype: Optional[torch.dtype] = None,
1712
+ partial_rotary_factor: float = 1.0,
1713
+ dual_chunk_attention_config: Optional[dict[str, Any]] = None,
1714
+ ) -> RotaryEmbedding:
1715
+ if dtype is None:
1716
+ dtype = torch.get_default_dtype()
1717
+ if rope_scaling is not None:
1718
+ # Transforms every value that is a list into a tuple for caching calls
1719
+ rope_scaling_tuple = {
1720
+ k: tuple(v) if isinstance(v, list) else v
1721
+ for k, v in rope_scaling.items()
1722
+ }
1723
+ rope_scaling_args = tuple(rope_scaling_tuple.items())
1724
+ else:
1725
+ rope_scaling_args = None
1726
+
1727
+ if dual_chunk_attention_config is not None:
1728
+ dual_chunk_attention_tuple = {
1729
+ k: tuple(v) if isinstance(v, list) else v
1730
+ for k, v in dual_chunk_attention_config.items()
1731
+ if k != "sparse_attention_config"
1732
+ }
1733
+ dual_chunk_attention_args = tuple(dual_chunk_attention_tuple.items())
1734
+ else:
1735
+ dual_chunk_attention_args = None
1736
+
1737
+ if partial_rotary_factor < 1.0:
1738
+ rotary_dim = int(rotary_dim * partial_rotary_factor)
1739
+ key = (head_size, rotary_dim, max_position, base, is_neox_style,
1740
+ rope_scaling_args, dual_chunk_attention_args, dtype)
1741
+ if key in _ROPE_DICT:
1742
+ return _ROPE_DICT[key]
1743
+
1744
+ if dual_chunk_attention_config is not None:
1745
+ extra_kwargs = {
1746
+ k: v
1747
+ for k, v in dual_chunk_attention_config.items()
1748
+ if k in ("chunk_size", "local_size")
1749
+ }
1750
+ rotary_emb = DualChunkRotaryEmbedding(head_size, rotary_dim,
1751
+ max_position, base,
1752
+ is_neox_style, dtype,
1753
+ **extra_kwargs)
1754
+ elif not rope_scaling:
1755
+ rotary_emb = RotaryEmbedding(head_size, rotary_dim, max_position, base,
1756
+ is_neox_style, dtype)
1757
+ else:
1758
+ scaling_type = rope_scaling["rope_type"]
1759
+
1760
+ if scaling_type == "llama3":
1761
+ scaling_factor = rope_scaling["factor"]
1762
+ low_freq_factor = rope_scaling["low_freq_factor"]
1763
+ high_freq_factor = rope_scaling["high_freq_factor"]
1764
+ original_max_position = rope_scaling[
1765
+ "original_max_position_embeddings"]
1766
+ rotary_emb = Llama3RotaryEmbedding(head_size, rotary_dim,
1767
+ max_position, base,
1768
+ is_neox_style, dtype,
1769
+ scaling_factor, low_freq_factor,
1770
+ high_freq_factor,
1771
+ original_max_position)
1772
+ elif scaling_type == "mllama4":
1773
+ rotary_emb = Llama4VisionRotaryEmbedding(head_size, rotary_dim,
1774
+ max_position, base,
1775
+ is_neox_style, dtype)
1776
+ elif scaling_type == "default":
1777
+ if "mrope_section" in rope_scaling:
1778
+ rotary_emb = MRotaryEmbedding(
1779
+ head_size,
1780
+ rotary_dim,
1781
+ max_position,
1782
+ base,
1783
+ is_neox_style,
1784
+ dtype,
1785
+ mrope_section=rope_scaling["mrope_section"],
1786
+ )
1787
+ else:
1788
+ rotary_emb = RotaryEmbedding(
1789
+ head_size,
1790
+ rotary_dim,
1791
+ max_position,
1792
+ base,
1793
+ is_neox_style,
1794
+ dtype,
1795
+ )
1796
+ elif scaling_type == "linear":
1797
+ scaling_factor = rope_scaling["factor"]
1798
+ rotary_emb = LinearScalingRotaryEmbedding(head_size, rotary_dim,
1799
+ max_position, base,
1800
+ is_neox_style,
1801
+ scaling_factor, dtype)
1802
+ elif scaling_type == "ntk":
1803
+ scaling_factor = rope_scaling["factor"]
1804
+ mixed_b = rope_scaling.get('mixed_b', None)
1805
+ rotary_emb = NTKScalingRotaryEmbedding(head_size, rotary_dim,
1806
+ max_position, base,
1807
+ is_neox_style,
1808
+ scaling_factor, dtype,
1809
+ mixed_b)
1810
+ elif scaling_type == "dynamic":
1811
+ scaling_factor = rope_scaling["factor"]
1812
+ rotary_emb = DynamicNTKScalingRotaryEmbedding(
1813
+ head_size, rotary_dim, max_position, base, is_neox_style,
1814
+ scaling_factor, dtype)
1815
+ elif scaling_type == "yarn":
1816
+ scaling_factor = rope_scaling["factor"]
1817
+ original_max_position = rope_scaling[
1818
+ "original_max_position_embeddings"]
1819
+ extra_kwargs = {
1820
+ k: v
1821
+ for k, v in rope_scaling.items()
1822
+ if k in ("extrapolation_factor", "attn_factor", "beta_fast",
1823
+ "beta_slow")
1824
+ }
1825
+ rotary_emb = YaRNScalingRotaryEmbedding(head_size, rotary_dim,
1826
+ original_max_position,
1827
+ base, is_neox_style,
1828
+ scaling_factor, dtype,
1829
+ **extra_kwargs)
1830
+ elif scaling_type == "deepseek_yarn":
1831
+ scaling_factor = rope_scaling["factor"]
1832
+ original_max_position = rope_scaling[
1833
+ "original_max_position_embeddings"]
1834
+ # assert max_position == original_max_position * scaling_factor
1835
+ extra_kwargs = {
1836
+ k: v
1837
+ for k, v in rope_scaling.items()
1838
+ if k in ("extrapolation_factor", "attn_factor", "beta_fast",
1839
+ "beta_slow", "mscale", "mscale_all_dim")
1840
+ }
1841
+ rotary_emb = DeepseekScalingRotaryEmbedding(
1842
+ head_size, rotary_dim, original_max_position, base,
1843
+ is_neox_style, scaling_factor, dtype, **extra_kwargs)
1844
+ elif scaling_type == "longrope":
1845
+ short_factor = rope_scaling["short_factor"]
1846
+ long_factor = rope_scaling["long_factor"]
1847
+ original_max_position = rope_scaling[
1848
+ "original_max_position_embeddings"]
1849
+ extra_kwargs = {
1850
+ k: v
1851
+ for k, v in rope_scaling.items()
1852
+ if k in ("short_mscale", "long_mscale")
1853
+ }
1854
+ rotary_emb = Phi3LongRoPEScaledRotaryEmbedding(
1855
+ head_size, rotary_dim, max_position, original_max_position,
1856
+ base, is_neox_style, dtype, short_factor, long_factor,
1857
+ **extra_kwargs)
1858
+ else:
1859
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
1860
+ _ROPE_DICT[key] = rotary_emb
1861
+ return rotary_emb