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