sglang 0.4.7.post1__py3-none-any.whl → 0.4.8__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 (106) hide show
  1. sglang/bench_one_batch.py +8 -6
  2. sglang/srt/_custom_ops.py +2 -2
  3. sglang/srt/code_completion_parser.py +2 -44
  4. sglang/srt/constants.py +3 -0
  5. sglang/srt/conversation.py +13 -3
  6. sglang/srt/custom_op.py +5 -1
  7. sglang/srt/disaggregation/decode.py +22 -28
  8. sglang/srt/disaggregation/decode_schedule_batch_mixin.py +4 -3
  9. sglang/srt/disaggregation/mini_lb.py +34 -4
  10. sglang/srt/disaggregation/mooncake/conn.py +12 -16
  11. sglang/srt/disaggregation/prefill.py +17 -13
  12. sglang/srt/disaggregation/utils.py +46 -18
  13. sglang/srt/distributed/parallel_state.py +12 -4
  14. sglang/srt/entrypoints/engine.py +22 -28
  15. sglang/srt/entrypoints/http_server.py +149 -79
  16. sglang/srt/entrypoints/http_server_engine.py +0 -3
  17. sglang/srt/entrypoints/openai/__init__.py +0 -0
  18. sglang/srt/{openai_api → entrypoints/openai}/protocol.py +67 -29
  19. sglang/srt/entrypoints/openai/serving_base.py +149 -0
  20. sglang/srt/entrypoints/openai/serving_chat.py +921 -0
  21. sglang/srt/entrypoints/openai/serving_completions.py +424 -0
  22. sglang/srt/entrypoints/openai/serving_embedding.py +169 -0
  23. sglang/srt/entrypoints/openai/serving_rerank.py +102 -0
  24. sglang/srt/entrypoints/openai/serving_score.py +61 -0
  25. sglang/srt/entrypoints/openai/usage_processor.py +81 -0
  26. sglang/srt/entrypoints/openai/utils.py +72 -0
  27. sglang/srt/function_call/base_format_detector.py +7 -4
  28. sglang/srt/function_call/deepseekv3_detector.py +1 -1
  29. sglang/srt/function_call/ebnf_composer.py +64 -10
  30. sglang/srt/function_call/function_call_parser.py +6 -6
  31. sglang/srt/function_call/llama32_detector.py +1 -1
  32. sglang/srt/function_call/mistral_detector.py +1 -1
  33. sglang/srt/function_call/pythonic_detector.py +1 -1
  34. sglang/srt/function_call/qwen25_detector.py +1 -1
  35. sglang/srt/{openai_api/utils.py → jinja_template_utils.py} +6 -5
  36. sglang/srt/layers/activation.py +21 -3
  37. sglang/srt/layers/attention/aiter_backend.py +5 -2
  38. sglang/srt/layers/attention/base_attn_backend.py +1 -1
  39. sglang/srt/layers/attention/cutlass_mla_backend.py +1 -0
  40. sglang/srt/layers/attention/flashattention_backend.py +19 -9
  41. sglang/srt/layers/attention/flashinfer_backend.py +9 -6
  42. sglang/srt/layers/attention/flashinfer_mla_backend.py +7 -4
  43. sglang/srt/layers/attention/flashmla_backend.py +5 -2
  44. sglang/srt/layers/attention/tbo_backend.py +3 -3
  45. sglang/srt/layers/attention/triton_backend.py +19 -11
  46. sglang/srt/layers/communicator.py +5 -5
  47. sglang/srt/layers/dp_attention.py +11 -2
  48. sglang/srt/layers/layernorm.py +29 -2
  49. sglang/srt/layers/logits_processor.py +2 -2
  50. sglang/srt/layers/moe/ep_moe/kernels.py +159 -2
  51. sglang/srt/layers/moe/ep_moe/layer.py +207 -1
  52. sglang/srt/layers/moe/fused_moe_triton/configs/triton_3_3_1/E=128,N=384,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128, 128].json +146 -0
  53. sglang/srt/layers/moe/fused_moe_triton/fused_moe.py +6 -0
  54. sglang/srt/layers/moe/fused_moe_triton/layer.py +75 -12
  55. sglang/srt/layers/moe/topk.py +91 -4
  56. sglang/srt/layers/quantization/compressed_tensors/compressed_tensors_moe.py +6 -2
  57. sglang/srt/layers/quantization/fp8.py +25 -17
  58. sglang/srt/layers/quantization/modelopt_quant.py +62 -8
  59. sglang/srt/layers/quantization/utils.py +5 -2
  60. sglang/srt/layers/rotary_embedding.py +42 -2
  61. sglang/srt/layers/sampler.py +1 -1
  62. sglang/srt/lora/lora_manager.py +173 -74
  63. sglang/srt/lora/mem_pool.py +49 -45
  64. sglang/srt/lora/utils.py +1 -1
  65. sglang/srt/managers/cache_controller.py +33 -15
  66. sglang/srt/managers/io_struct.py +9 -12
  67. sglang/srt/managers/schedule_batch.py +40 -31
  68. sglang/srt/managers/schedule_policy.py +70 -56
  69. sglang/srt/managers/scheduler.py +147 -62
  70. sglang/srt/managers/template_manager.py +226 -0
  71. sglang/srt/managers/tokenizer_manager.py +11 -8
  72. sglang/srt/managers/tp_worker.py +12 -2
  73. sglang/srt/managers/tp_worker_overlap_thread.py +11 -0
  74. sglang/srt/mem_cache/{paged_allocator.py → allocator.py} +125 -34
  75. sglang/srt/mem_cache/base_prefix_cache.py +52 -8
  76. sglang/srt/mem_cache/chunk_cache.py +11 -16
  77. sglang/srt/mem_cache/hiradix_cache.py +34 -23
  78. sglang/srt/mem_cache/memory_pool.py +118 -114
  79. sglang/srt/mem_cache/radix_cache.py +20 -16
  80. sglang/srt/model_executor/cuda_graph_runner.py +76 -45
  81. sglang/srt/model_executor/forward_batch_info.py +18 -5
  82. sglang/srt/model_executor/model_runner.py +22 -6
  83. sglang/srt/model_loader/loader.py +8 -1
  84. sglang/srt/model_loader/weight_utils.py +11 -2
  85. sglang/srt/models/deepseek_nextn.py +29 -27
  86. sglang/srt/models/deepseek_v2.py +108 -26
  87. sglang/srt/models/glm4.py +312 -0
  88. sglang/srt/models/mimo_mtp.py +2 -18
  89. sglang/srt/reasoning_parser.py +21 -11
  90. sglang/srt/server_args.py +36 -8
  91. sglang/srt/speculative/eagle_draft_cuda_graph_runner.py +131 -10
  92. sglang/srt/speculative/eagle_draft_extend_cuda_graph_runner.py +125 -12
  93. sglang/srt/speculative/eagle_utils.py +80 -8
  94. sglang/srt/speculative/eagle_worker.py +124 -41
  95. sglang/srt/torch_memory_saver_adapter.py +19 -15
  96. sglang/srt/utils.py +177 -11
  97. sglang/test/test_block_fp8_ep.py +1 -0
  98. sglang/test/test_utils.py +1 -0
  99. sglang/version.py +1 -1
  100. {sglang-0.4.7.post1.dist-info → sglang-0.4.8.dist-info}/METADATA +4 -10
  101. {sglang-0.4.7.post1.dist-info → sglang-0.4.8.dist-info}/RECORD +104 -93
  102. sglang/srt/entrypoints/verl_engine.py +0 -179
  103. sglang/srt/openai_api/adapter.py +0 -2148
  104. {sglang-0.4.7.post1.dist-info → sglang-0.4.8.dist-info}/WHEEL +0 -0
  105. {sglang-0.4.7.post1.dist-info → sglang-0.4.8.dist-info}/licenses/LICENSE +0 -0
  106. {sglang-0.4.7.post1.dist-info → sglang-0.4.8.dist-info}/top_level.txt +0 -0
@@ -1,179 +0,0 @@
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, Iterable, List, Literal, Optional, Tuple, Union
16
-
17
- import torch
18
- import torch.distributed as dist
19
- from PIL.Image import Image
20
- from torch.distributed.tensor import DeviceMesh, DTensor
21
-
22
- from sglang.srt.entrypoints.engine import Engine
23
- from sglang.srt.entrypoints.http_server_engine import HttpServerEngineAdapter
24
- from sglang.srt.model_executor.model_runner import LocalSerializedTensor
25
- from sglang.srt.patch_torch import monkey_patch_torch_reductions
26
- from sglang.srt.utils import MultiprocessingSerializer, broadcast_pyobj
27
-
28
-
29
- class VerlEngine:
30
- def __init__(
31
- self,
32
- device_mesh_cpu: DeviceMesh,
33
- nnodes: int = 1,
34
- backend: Literal["engine", "server"] = "engine",
35
- **kwargs,
36
- ):
37
- monkey_patch_torch_reductions()
38
- self._device_mesh_cpu = device_mesh_cpu
39
- self._tp_rank = device_mesh_cpu.get_local_rank()
40
- self._rank = device_mesh_cpu.get_rank()
41
- self._tp_size = device_mesh_cpu.size()
42
- tp_size_per_node = self._tp_size // nnodes
43
- node_rank = self._tp_rank // tp_size_per_node
44
- first_rank_in_node = self._tp_rank % tp_size_per_node == 0
45
-
46
- # Common engine keyword arguments
47
- engine_kwargs = dict(
48
- **kwargs, tp_size=self._tp_size, node_rank=node_rank, nnodes=nnodes
49
- )
50
-
51
- if backend == "engine":
52
- if first_rank_in_node:
53
- os.environ["SGLANG_BLOCK_NONZERO_RANK_CHILDREN"] = "0"
54
- self._engine = Engine(**engine_kwargs)
55
- else:
56
- self._engine = None
57
-
58
- elif backend == "server":
59
- if self._tp_rank == 0:
60
- self._engine = HttpServerEngineAdapter(**engine_kwargs)
61
- else:
62
- self._engine = None
63
- else:
64
- raise ValueError(f"Unsupported backend: {backend}")
65
-
66
- dist.barrier(group=self._device_mesh_cpu.get_group())
67
-
68
- def generate(
69
- self,
70
- # The input prompt. It can be a single prompt or a batch of prompts.
71
- prompt: Optional[Union[List[str], str]] = None,
72
- sampling_params: Optional[Union[List[Dict], Dict]] = None,
73
- # The token ids for text; one can either specify text or input_ids.
74
- input_ids: Optional[Union[List[List[int]], List[int]]] = None,
75
- # The image input. It can be an image instance, file name, URL, or base64 encoded string.
76
- # Can be formatted as:
77
- # - Single image for a single request
78
- # - List of images (one per request in a batch)
79
- # - List of lists of images (multiple images per request)
80
- # See also python/sglang/srt/utils.py:load_image for more details.
81
- image_data: Optional[
82
- Union[
83
- List[List[Union[Image, str]]],
84
- List[Union[Image, str]],
85
- Union[Image, str],
86
- ]
87
- ] = None,
88
- return_logprob: Optional[Union[List[bool], bool]] = False,
89
- logprob_start_len: Optional[Union[List[int], int]] = None,
90
- top_logprobs_num: Optional[Union[List[int], int]] = None,
91
- token_ids_logprob: Optional[Union[List[List[int]], List[int]]] = None,
92
- lora_path: Optional[List[Optional[str]]] = None,
93
- custom_logit_processor: Optional[Union[List[str], str]] = None,
94
- ) -> Dict:
95
- """
96
- The arguments of this function is the same as `sglang/srt/managers/io_struct.py::GenerateReqInput`.
97
- Please refer to `GenerateReqInput` for the documentation.
98
- """
99
- if self._tp_rank == 0:
100
- output = self._engine.generate(
101
- prompt=prompt,
102
- sampling_params=sampling_params,
103
- input_ids=input_ids,
104
- image_data=image_data,
105
- return_logprob=return_logprob,
106
- logprob_start_len=logprob_start_len,
107
- top_logprobs_num=top_logprobs_num,
108
- token_ids_logprob=token_ids_logprob,
109
- lora_path=lora_path,
110
- custom_logit_processor=custom_logit_processor,
111
- )
112
- else:
113
- output = None
114
-
115
- # Most naive implementation, can extract tensor and send via gloo if too slow
116
- [output] = broadcast_pyobj(
117
- data=[output],
118
- rank=self._rank,
119
- dist_group=self._device_mesh_cpu.get_group(),
120
- src=self._device_mesh_cpu.mesh[0].item(),
121
- force_cpu_device=False,
122
- )
123
-
124
- return output
125
-
126
- def update_weights_from_tensor(
127
- self,
128
- named_tensors: Iterable[Tuple[str, torch.Tensor]],
129
- load_format: Optional[str] = None,
130
- ):
131
- # Most naive implementation, can optimize a lot if it is bottleneck
132
- for tensor_index, (name, tensor) in enumerate(named_tensors):
133
- serialized_tensor = MultiprocessingSerializer.serialize(
134
- _preprocess_tensor_for_update_weights(tensor)
135
- )
136
-
137
- if self._tp_rank == 0:
138
- gathered_serialized_tensors = [None for _ in range(self._tp_size)]
139
- else:
140
- gathered_serialized_tensors = None
141
- dist.gather_object(
142
- obj=serialized_tensor,
143
- object_gather_list=gathered_serialized_tensors,
144
- dst=self._device_mesh_cpu.mesh.tolist()[0],
145
- group=self._device_mesh_cpu.get_group(),
146
- )
147
-
148
- if self._tp_rank == 0:
149
- self._engine.update_weights_from_tensor(
150
- named_tensors=[
151
- (
152
- name,
153
- LocalSerializedTensor(values=gathered_serialized_tensors),
154
- )
155
- ],
156
- load_format=load_format,
157
- flush_cache=False,
158
- )
159
-
160
- if self._tp_rank == 0:
161
- self._engine.flush_cache()
162
-
163
- def release_memory_occupation(self):
164
- if self._tp_rank == 0:
165
- self._engine.release_memory_occupation()
166
-
167
- def resume_memory_occupation(self):
168
- if self._tp_rank == 0:
169
- self._engine.resume_memory_occupation()
170
-
171
- def shutdown(self):
172
- if self._engine is not None:
173
- self._engine.shutdown()
174
-
175
-
176
- def _preprocess_tensor_for_update_weights(tensor: torch.Tensor):
177
- if isinstance(tensor, DTensor):
178
- return tensor.full_tensor()
179
- return tensor