sglang 0.4.3.post1__py3-none-any.whl → 0.4.3.post3__py3-none-any.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 (219) hide show
  1. sglang/api.py +1 -1
  2. sglang/bench_offline_throughput.py +19 -0
  3. sglang/bench_one_batch.py +2 -2
  4. sglang/bench_serving.py +123 -79
  5. sglang/global_config.py +8 -3
  6. sglang/lang/backend/runtime_endpoint.py +1 -1
  7. sglang/lang/ir.py +1 -1
  8. sglang/srt/_custom_ops.py +83 -91
  9. sglang/srt/configs/load_config.py +4 -1
  10. sglang/srt/configs/model_config.py +48 -2
  11. sglang/srt/configs/qwen2_5_vl_config.py +5 -2
  12. sglang/srt/constrained/base_grammar_backend.py +117 -15
  13. sglang/srt/constrained/llguidance_backend.py +151 -0
  14. sglang/srt/constrained/outlines_backend.py +24 -33
  15. sglang/srt/constrained/xgrammar_backend.py +69 -38
  16. sglang/srt/distributed/device_communicators/custom_all_reduce.py +225 -80
  17. sglang/srt/distributed/parallel_state.py +48 -3
  18. sglang/srt/entrypoints/engine.py +67 -9
  19. sglang/srt/entrypoints/http_server.py +190 -41
  20. sglang/srt/entrypoints/verl_engine.py +147 -0
  21. sglang/srt/function_call_parser.py +0 -1
  22. sglang/srt/layers/activation.py +11 -0
  23. sglang/srt/layers/attention/{__init__.py → base_attn_backend.py} +14 -6
  24. sglang/srt/layers/attention/double_sparsity_backend.py +1 -1
  25. sglang/srt/layers/attention/flashinfer_backend.py +208 -295
  26. sglang/srt/layers/attention/flashinfer_mla_backend.py +582 -0
  27. sglang/srt/layers/attention/torch_native_backend.py +1 -1
  28. sglang/srt/layers/attention/triton_backend.py +9 -6
  29. sglang/srt/layers/attention/triton_ops/decode_attention.py +3 -0
  30. sglang/srt/layers/attention/triton_ops/extend_attention.py +20 -4
  31. sglang/srt/layers/attention/triton_ops/rocm_mla_decode_rope.py +439 -0
  32. sglang/srt/layers/attention/utils.py +39 -0
  33. sglang/srt/layers/attention/vision.py +60 -63
  34. sglang/srt/layers/dp_attention.py +142 -1
  35. sglang/srt/layers/layernorm.py +1 -1
  36. sglang/srt/layers/linear.py +3 -1
  37. sglang/srt/layers/logits_processor.py +281 -45
  38. sglang/srt/layers/moe/ep_moe/kernels.py +126 -8
  39. sglang/srt/layers/moe/ep_moe/layer.py +140 -28
  40. sglang/srt/layers/moe/fused_moe_native.py +2 -0
  41. sglang/srt/layers/moe/fused_moe_triton/configs/E=256,N=128,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  42. sglang/srt/layers/moe/fused_moe_triton/configs/E=256,N=128,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +146 -0
  43. sglang/srt/layers/moe/fused_moe_triton/configs/E=256,N=256,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8,block_shape=[128, 128].json +50 -50
  44. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=14336,device_name=AMD_Instinct_MI300X.json +18 -18
  45. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=14336,device_name=AMD_Instinct_MI325X.json +18 -18
  46. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=14336,device_name=AMD_Radeon_Graphics.json +18 -18
  47. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=1792,device_name=AMD_Instinct_MI300X.json +18 -18
  48. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=1792,device_name=AMD_Instinct_MI325X.json +18 -18
  49. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=1792,device_name=AMD_Radeon_Graphics.json +18 -18
  50. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=3584,device_name=AMD_Instinct_MI300X.json +18 -18
  51. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=3584,device_name=AMD_Instinct_MI325X.json +18 -18
  52. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=3584,device_name=AMD_Radeon_Graphics.json +18 -18
  53. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=4096,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +16 -16
  54. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=4096,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +16 -16
  55. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=4096,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8.json +16 -16
  56. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=7168,device_name=AMD_Instinct_MI300X.json +18 -18
  57. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=7168,device_name=AMD_Instinct_MI325X.json +18 -18
  58. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=7168,device_name=AMD_Radeon_Graphics.json +18 -18
  59. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=8192,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +15 -15
  60. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=8192,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +15 -15
  61. sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=8192,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8.json +15 -15
  62. sglang/srt/layers/moe/fused_moe_triton/fused_moe.py +88 -20
  63. sglang/srt/layers/moe/fused_moe_triton/layer.py +34 -13
  64. sglang/srt/layers/moe/topk.py +13 -4
  65. sglang/srt/layers/quantization/__init__.py +111 -7
  66. sglang/srt/layers/quantization/blockwise_int8.py +409 -0
  67. sglang/srt/layers/quantization/configs/N=1536,K=1536,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  68. sglang/srt/layers/quantization/configs/N=1536,K=1536,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  69. sglang/srt/layers/quantization/configs/N=1536,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  70. sglang/srt/layers/quantization/configs/N=1536,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  71. sglang/srt/layers/quantization/configs/N=2048,K=512,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  72. sglang/srt/layers/quantization/configs/N=2048,K=512,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  73. sglang/srt/layers/quantization/configs/N=2304,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  74. sglang/srt/layers/quantization/configs/N=2304,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  75. sglang/srt/layers/quantization/configs/N=24576,K=1536,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  76. sglang/srt/layers/quantization/configs/N=24576,K=1536,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  77. sglang/srt/layers/quantization/configs/N=24576,K=1536,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  78. sglang/srt/layers/quantization/configs/N=24576,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  79. sglang/srt/layers/quantization/configs/N=24576,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  80. sglang/srt/layers/quantization/configs/N=256,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  81. sglang/srt/layers/quantization/configs/N=256,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  82. sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  83. sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  84. sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  85. sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  86. sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  87. sglang/srt/layers/quantization/configs/N=576,K=7168,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  88. sglang/srt/layers/quantization/configs/N=576,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  89. sglang/srt/layers/quantization/configs/N=7168,K=1024,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  90. sglang/srt/layers/quantization/configs/N=7168,K=1024,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  91. sglang/srt/layers/quantization/configs/N=7168,K=1152,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  92. sglang/srt/layers/quantization/configs/N=7168,K=1152,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  93. sglang/srt/layers/quantization/configs/N=7168,K=128,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  94. sglang/srt/layers/quantization/configs/N=7168,K=128,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  95. sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  96. sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  97. sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
  98. sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  99. sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  100. sglang/srt/layers/quantization/configs/N=7168,K=18432,device_name=NVIDIA_A100-SXM4-80GB,dtype=int8_w8a8,block_shape=[128, 128].json +146 -0
  101. sglang/srt/layers/quantization/configs/N=7168,K=18432,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
  102. sglang/srt/layers/quantization/fp8.py +69 -28
  103. sglang/srt/layers/quantization/fp8_utils.py +17 -1
  104. sglang/srt/layers/quantization/gptq.py +416 -0
  105. sglang/srt/layers/quantization/int8_kernel.py +327 -0
  106. sglang/srt/layers/quantization/int8_utils.py +73 -0
  107. sglang/srt/layers/quantization/modelopt_quant.py +18 -1
  108. sglang/srt/layers/radix_attention.py +1 -0
  109. sglang/srt/layers/rotary_embedding.py +0 -1
  110. sglang/srt/layers/sampler.py +76 -31
  111. sglang/srt/layers/vocab_parallel_embedding.py +14 -13
  112. sglang/srt/lora/lora.py +17 -1
  113. sglang/srt/lora/lora_config.py +5 -0
  114. sglang/srt/lora/lora_manager.py +1 -3
  115. sglang/srt/managers/cache_controller.py +193 -62
  116. sglang/srt/managers/configure_logging.py +2 -1
  117. sglang/srt/managers/data_parallel_controller.py +6 -2
  118. sglang/srt/managers/detokenizer_manager.py +124 -102
  119. sglang/srt/managers/image_processor.py +2 -1
  120. sglang/srt/managers/io_struct.py +143 -6
  121. sglang/srt/managers/schedule_batch.py +238 -197
  122. sglang/srt/managers/schedule_policy.py +29 -29
  123. sglang/srt/managers/scheduler.py +681 -259
  124. sglang/srt/managers/session_controller.py +6 -2
  125. sglang/srt/managers/tokenizer_manager.py +224 -68
  126. sglang/srt/managers/tp_worker.py +15 -4
  127. sglang/srt/managers/tp_worker_overlap_thread.py +3 -4
  128. sglang/srt/mem_cache/chunk_cache.py +18 -11
  129. sglang/srt/mem_cache/hiradix_cache.py +394 -0
  130. sglang/srt/mem_cache/memory_pool.py +44 -18
  131. sglang/srt/mem_cache/radix_cache.py +58 -47
  132. sglang/srt/metrics/collector.py +94 -36
  133. sglang/srt/model_executor/cuda_graph_runner.py +55 -24
  134. sglang/srt/model_executor/forward_batch_info.py +49 -16
  135. sglang/srt/model_executor/model_runner.py +209 -28
  136. sglang/srt/model_loader/loader.py +3 -3
  137. sglang/srt/model_loader/weight_utils.py +36 -14
  138. sglang/srt/models/baichuan.py +31 -6
  139. sglang/srt/models/chatglm.py +39 -7
  140. sglang/srt/models/commandr.py +29 -5
  141. sglang/srt/models/dbrx.py +31 -5
  142. sglang/srt/models/deepseek.py +43 -6
  143. sglang/srt/models/deepseek_nextn.py +32 -19
  144. sglang/srt/models/deepseek_v2.py +265 -29
  145. sglang/srt/models/exaone.py +19 -9
  146. sglang/srt/models/gemma.py +22 -8
  147. sglang/srt/models/gemma2.py +25 -12
  148. sglang/srt/models/gemma2_reward.py +5 -1
  149. sglang/srt/models/gpt2.py +28 -13
  150. sglang/srt/models/gpt_bigcode.py +27 -5
  151. sglang/srt/models/granite.py +21 -9
  152. sglang/srt/models/grok.py +21 -4
  153. sglang/srt/models/internlm2.py +36 -6
  154. sglang/srt/models/internlm2_reward.py +5 -1
  155. sglang/srt/models/llama.py +26 -9
  156. sglang/srt/models/llama_classification.py +5 -1
  157. sglang/srt/models/llama_eagle.py +17 -4
  158. sglang/srt/models/llama_embedding.py +5 -1
  159. sglang/srt/models/llama_reward.py +7 -2
  160. sglang/srt/models/llava.py +19 -3
  161. sglang/srt/models/llavavid.py +10 -1
  162. sglang/srt/models/minicpm.py +26 -2
  163. sglang/srt/models/minicpm3.py +39 -3
  164. sglang/srt/models/minicpmv.py +45 -14
  165. sglang/srt/models/mixtral.py +20 -9
  166. sglang/srt/models/mixtral_quant.py +50 -8
  167. sglang/srt/models/mllama.py +57 -11
  168. sglang/srt/models/olmo.py +34 -6
  169. sglang/srt/models/olmo2.py +34 -13
  170. sglang/srt/models/olmoe.py +26 -4
  171. sglang/srt/models/phi3_small.py +29 -10
  172. sglang/srt/models/qwen.py +26 -3
  173. sglang/srt/models/qwen2.py +26 -4
  174. sglang/srt/models/qwen2_5_vl.py +46 -8
  175. sglang/srt/models/qwen2_eagle.py +17 -5
  176. sglang/srt/models/qwen2_moe.py +44 -6
  177. sglang/srt/models/qwen2_rm.py +78 -0
  178. sglang/srt/models/qwen2_vl.py +39 -8
  179. sglang/srt/models/stablelm.py +32 -5
  180. sglang/srt/models/torch_native_llama.py +5 -2
  181. sglang/srt/models/xverse.py +21 -9
  182. sglang/srt/models/xverse_moe.py +45 -7
  183. sglang/srt/models/yivl.py +2 -1
  184. sglang/srt/openai_api/adapter.py +109 -24
  185. sglang/srt/openai_api/protocol.py +17 -1
  186. sglang/srt/reasoning_parser.py +154 -0
  187. sglang/srt/sampling/penaltylib/__init__.py +4 -6
  188. sglang/srt/sampling/penaltylib/frequency_penalty.py +66 -0
  189. sglang/srt/sampling/penaltylib/{penalizers/min_new_tokens.py → min_new_tokens.py} +15 -23
  190. sglang/srt/sampling/penaltylib/orchestrator.py +39 -188
  191. sglang/srt/sampling/penaltylib/presence_penalty.py +66 -0
  192. sglang/srt/sampling/sampling_batch_info.py +79 -157
  193. sglang/srt/sampling/sampling_params.py +16 -13
  194. sglang/srt/server_args.py +136 -52
  195. sglang/srt/speculative/build_eagle_tree.py +2 -8
  196. sglang/srt/speculative/eagle_draft_cuda_graph_runner.py +0 -1
  197. sglang/srt/speculative/eagle_utils.py +92 -58
  198. sglang/srt/speculative/eagle_worker.py +186 -94
  199. sglang/srt/speculative/spec_info.py +1 -13
  200. sglang/srt/utils.py +43 -17
  201. sglang/srt/warmup.py +47 -0
  202. sglang/test/few_shot_gsm8k.py +4 -1
  203. sglang/test/runners.py +389 -126
  204. sglang/test/send_one.py +88 -0
  205. sglang/test/test_block_fp8_ep.py +361 -0
  206. sglang/test/test_programs.py +1 -1
  207. sglang/test/test_utils.py +138 -84
  208. sglang/utils.py +50 -60
  209. sglang/version.py +1 -1
  210. {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/METADATA +21 -15
  211. {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/RECORD +214 -166
  212. {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/WHEEL +1 -1
  213. sglang/bench_latency.py +0 -1
  214. sglang/srt/sampling/penaltylib/penalizers/frequency_penalty.py +0 -75
  215. sglang/srt/sampling/penaltylib/penalizers/presence_penalty.py +0 -74
  216. sglang/srt/sampling/penaltylib/penalizers/repetition_penalty.py +0 -85
  217. sglang/test/srt/sampling/penaltylib/utils.py +0 -344
  218. {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/LICENSE +0 -0
  219. {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,147 @@
1
+ # Copyright 2023-2024 SGLang Team
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # ==============================================================================
14
+ import os
15
+ from typing import Dict, List, Optional, Tuple, Union
16
+
17
+ import torch
18
+ import torch.distributed as dist
19
+ from torch.distributed.tensor import DeviceMesh, DTensor
20
+
21
+ from sglang.srt.model_executor.model_runner import LocalSerializedTensor
22
+ from sglang.srt.server import Engine
23
+ from sglang.srt.utils import MultiprocessingSerializer, broadcast_pyobj
24
+
25
+
26
+ class VerlEngine:
27
+ def __init__(
28
+ self,
29
+ device_mesh_cpu: DeviceMesh,
30
+ nnodes: int = 1,
31
+ **kwargs,
32
+ ):
33
+ self._device_mesh_cpu = device_mesh_cpu
34
+ self._tp_rank = device_mesh_cpu.get_local_rank()
35
+ self._tp_size = device_mesh_cpu.size()
36
+ tp_size_per_node = self._tp_size // nnodes
37
+ node_rank = self._tp_rank // tp_size_per_node
38
+ first_rank_in_node = self._tp_rank % tp_size_per_node == 0
39
+
40
+ if first_rank_in_node:
41
+ os.environ["SGLANG_BLOCK_NONZERO_RANK_CHILDREN"] = "0"
42
+ self._engine = Engine(
43
+ **kwargs, tp_size=self._tp_size, node_rank=node_rank, nnodes=nnodes
44
+ )
45
+ else:
46
+ self._engine = None
47
+
48
+ dist.barrier(group=self._device_mesh_cpu.get_group())
49
+
50
+ def generate(
51
+ self,
52
+ # The input prompt. It can be a single prompt or a batch of prompts.
53
+ prompt: Optional[Union[List[str], str]] = None,
54
+ sampling_params: Optional[Union[List[Dict], Dict]] = None,
55
+ # The token ids for text; one can either specify text or input_ids.
56
+ input_ids: Optional[Union[List[List[int]], List[int]]] = None,
57
+ # The image input. It can be a file name, a url, or base64 encoded string.
58
+ # See also python/sglang/srt/utils.py:load_image.
59
+ image_data: Optional[Union[List[str], str]] = None,
60
+ return_logprob: Optional[Union[List[bool], bool]] = False,
61
+ logprob_start_len: Optional[Union[List[int], int]] = None,
62
+ top_logprobs_num: Optional[Union[List[int], int]] = None,
63
+ token_ids_logprob: Optional[Union[List[List[int]], List[int]]] = None,
64
+ lora_path: Optional[List[Optional[str]]] = None,
65
+ custom_logit_processor: Optional[Union[List[str], str]] = None,
66
+ ) -> Dict:
67
+ """
68
+ The arguments of this function is the same as `sglang/srt/managers/io_struct.py::GenerateReqInput`.
69
+ Please refer to `GenerateReqInput` for the documentation.
70
+ """
71
+ if self._tp_rank == 0:
72
+ output = self._engine.generate(
73
+ prompt=prompt,
74
+ sampling_params=sampling_params,
75
+ input_ids=input_ids,
76
+ image_data=image_data,
77
+ return_logprob=return_logprob,
78
+ logprob_start_len=logprob_start_len,
79
+ top_logprobs_num=top_logprobs_num,
80
+ token_ids_logprob=token_ids_logprob,
81
+ lora_path=lora_path,
82
+ custom_logit_processor=custom_logit_processor,
83
+ )
84
+ else:
85
+ output = None
86
+
87
+ # Most naive implementation, can extract tensor and send via gloo if too slow
88
+ [output] = broadcast_pyobj(
89
+ data=[output],
90
+ rank=self._tp_rank,
91
+ dist_group=self._device_mesh_cpu.get_group(),
92
+ src=self._device_mesh_cpu.mesh[0].item(),
93
+ )
94
+
95
+ return output
96
+
97
+ def update_weights_from_tensor(
98
+ self,
99
+ named_tensors: List[Tuple[str, torch.Tensor]],
100
+ load_format: Optional[str] = None,
101
+ ):
102
+ # Most naive implementation, can optimize a lot if it is bottleneck
103
+ for tensor_index, (name, tensor) in enumerate(named_tensors):
104
+ serialized_tensor = MultiprocessingSerializer.serialize(
105
+ _preprocess_tensor_for_update_weights(tensor)
106
+ )
107
+
108
+ if self._tp_rank == 0:
109
+ gathered_serialized_tensors = [None for _ in range(self._tp_size)]
110
+ else:
111
+ gathered_serialized_tensors = None
112
+ dist.gather_object(
113
+ obj=serialized_tensor,
114
+ object_gather_list=gathered_serialized_tensors,
115
+ dst=self._device_mesh_cpu.mesh.tolist()[0],
116
+ group=self._device_mesh_cpu.get_group(),
117
+ )
118
+
119
+ if self._tp_rank == 0:
120
+ self._engine.update_weights_from_tensor(
121
+ named_tensors=[
122
+ (
123
+ name,
124
+ LocalSerializedTensor(values=gathered_serialized_tensors),
125
+ )
126
+ ],
127
+ load_format=load_format,
128
+ flush_cache=tensor_index == len(named_tensors) - 1,
129
+ )
130
+
131
+ def release_memory_occupation(self):
132
+ if self._tp_rank == 0:
133
+ self._engine.release_memory_occupation()
134
+
135
+ def resume_memory_occupation(self):
136
+ if self._tp_rank == 0:
137
+ self._engine.resume_memory_occupation()
138
+
139
+ def shutdown(self):
140
+ if self._engine is not None:
141
+ self._engine.shutdown()
142
+
143
+
144
+ def _preprocess_tensor_for_update_weights(tensor: torch.Tensor):
145
+ if isinstance(tensor, DTensor):
146
+ return tensor.full_tensor()
147
+ return tensor
@@ -1,7 +1,6 @@
1
1
  import json
2
2
  import logging
3
3
  import re
4
- from abc import ABC, abstractmethod
5
4
  from json import JSONDecodeError, JSONDecoder
6
5
  from typing import Any, Dict, List, Optional, Tuple
7
6
 
@@ -14,6 +14,7 @@
14
14
  """Fused operators for activation layers."""
15
15
 
16
16
  import logging
17
+ import math
17
18
  from typing import Optional
18
19
 
19
20
  import torch
@@ -72,6 +73,16 @@ class GeluAndMul(CustomOp):
72
73
  return out
73
74
 
74
75
 
76
+ class NewGELU(CustomOp):
77
+ def forward_native(self, x: torch.Tensor) -> torch.Tensor:
78
+ c = math.sqrt(2.0 / math.pi)
79
+ return 0.5 * x * (1.0 + torch.tanh(c * (x + 0.044715 * torch.pow(x, 3.0))))
80
+
81
+ def forward_cuda(self, x: torch.Tensor) -> torch.Tensor:
82
+ # TODO: Implement the CUDA kernel for NewGELU in sgl-kernel
83
+ return self.forward_native(x)
84
+
85
+
75
86
  class QuickGELU(CustomOp):
76
87
  def forward_native(self, x: torch.Tensor) -> torch.Tensor:
77
88
  return x * torch.sigmoid(1.702 * x)
@@ -1,14 +1,14 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING, Optional, Union
5
5
 
6
6
  import torch
7
7
 
8
8
  if TYPE_CHECKING:
9
9
  from sglang.srt.layers.radix_attention import RadixAttention
10
10
  from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
11
- from sglang.srt.speculative.spec_info import SpecInfo
11
+ from sglang.srt.speculative.eagle_utils import EagleDraftInput, EagleVerifyInput
12
12
 
13
13
 
14
14
  class AttentionBackend(ABC):
@@ -31,7 +31,7 @@ class AttentionBackend(ABC):
31
31
  seq_lens: torch.Tensor,
32
32
  encoder_lens: Optional[torch.Tensor],
33
33
  forward_mode: ForwardMode,
34
- spec_info: Optional[SpecInfo],
34
+ spec_info: Optional[Union[EagleDraftInput, EagleVerifyInput]],
35
35
  ):
36
36
  """Init the metadata for a forward pass for capturing a cuda graph."""
37
37
  raise NotImplementedError()
@@ -44,7 +44,8 @@ class AttentionBackend(ABC):
44
44
  seq_lens_sum: int,
45
45
  encoder_lens: Optional[torch.Tensor],
46
46
  forward_mode: ForwardMode,
47
- spec_info: Optional[SpecInfo],
47
+ spec_info: Optional[Union[EagleDraftInput, EagleVerifyInput]],
48
+ seq_lens_cpu: Optional[torch.Tensor],
48
49
  ):
49
50
  """Init the metadata for a forward pass for replying a cuda graph."""
50
51
  raise NotImplementedError()
@@ -64,7 +65,14 @@ class AttentionBackend(ABC):
64
65
  ):
65
66
  """Run forward on an attention layer."""
66
67
  if forward_batch.forward_mode.is_decode():
67
- return self.forward_decode(q, k, v, layer, forward_batch, save_kv_cache)
68
+ return self.forward_decode(
69
+ q,
70
+ k,
71
+ v,
72
+ layer,
73
+ forward_batch,
74
+ save_kv_cache=save_kv_cache,
75
+ )
68
76
  else:
69
77
  return self.forward_extend(
70
78
  q,
@@ -72,7 +80,7 @@ class AttentionBackend(ABC):
72
80
  v,
73
81
  layer,
74
82
  forward_batch,
75
- save_kv_cache,
83
+ save_kv_cache=save_kv_cache,
76
84
  )
77
85
 
78
86
  def forward_decode(
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
4
4
 
5
5
  import torch
6
6
 
7
- from sglang.srt.layers.attention import AttentionBackend
7
+ from sglang.srt.layers.attention.base_attn_backend import AttentionBackend
8
8
  from sglang.srt.managers.schedule_batch import global_server_args_dict
9
9
  from sglang.srt.model_executor.forward_batch_info import ForwardBatch
10
10