sglang 0.4.7__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.
- sglang/__init__.py +2 -0
- sglang/api.py +7 -0
- sglang/bench_one_batch.py +8 -6
- sglang/bench_serving.py +1 -1
- sglang/lang/interpreter.py +40 -1
- sglang/lang/ir.py +27 -0
- sglang/math_utils.py +8 -0
- sglang/srt/_custom_ops.py +2 -2
- sglang/srt/code_completion_parser.py +2 -44
- sglang/srt/configs/model_config.py +6 -0
- sglang/srt/constants.py +3 -0
- sglang/srt/conversation.py +19 -3
- sglang/srt/custom_op.py +5 -1
- sglang/srt/disaggregation/base/__init__.py +1 -1
- sglang/srt/disaggregation/base/conn.py +25 -11
- sglang/srt/disaggregation/common/__init__.py +5 -1
- sglang/srt/disaggregation/common/utils.py +42 -0
- sglang/srt/disaggregation/decode.py +211 -72
- sglang/srt/disaggregation/decode_schedule_batch_mixin.py +4 -3
- sglang/srt/disaggregation/fake/__init__.py +1 -1
- sglang/srt/disaggregation/fake/conn.py +15 -9
- sglang/srt/disaggregation/mini_lb.py +34 -4
- sglang/srt/disaggregation/mooncake/__init__.py +1 -1
- sglang/srt/disaggregation/mooncake/conn.py +30 -29
- sglang/srt/disaggregation/nixl/__init__.py +6 -1
- sglang/srt/disaggregation/nixl/conn.py +17 -12
- sglang/srt/disaggregation/prefill.py +144 -55
- sglang/srt/disaggregation/utils.py +155 -123
- sglang/srt/distributed/parallel_state.py +12 -4
- sglang/srt/entrypoints/engine.py +37 -29
- sglang/srt/entrypoints/http_server.py +153 -72
- sglang/srt/entrypoints/http_server_engine.py +0 -3
- sglang/srt/entrypoints/openai/__init__.py +0 -0
- sglang/srt/{openai_api → entrypoints/openai}/protocol.py +84 -10
- sglang/srt/entrypoints/openai/serving_base.py +149 -0
- sglang/srt/entrypoints/openai/serving_chat.py +921 -0
- sglang/srt/entrypoints/openai/serving_completions.py +424 -0
- sglang/srt/entrypoints/openai/serving_embedding.py +169 -0
- sglang/srt/entrypoints/openai/serving_rerank.py +102 -0
- sglang/srt/entrypoints/openai/serving_score.py +61 -0
- sglang/srt/entrypoints/openai/usage_processor.py +81 -0
- sglang/srt/entrypoints/openai/utils.py +72 -0
- sglang/srt/eplb_simulator/__init__.py +1 -0
- sglang/srt/eplb_simulator/reader.py +51 -0
- sglang/srt/function_call/base_format_detector.py +7 -4
- sglang/srt/function_call/deepseekv3_detector.py +1 -1
- sglang/srt/function_call/ebnf_composer.py +64 -10
- sglang/srt/function_call/function_call_parser.py +6 -6
- sglang/srt/function_call/llama32_detector.py +1 -1
- sglang/srt/function_call/mistral_detector.py +1 -1
- sglang/srt/function_call/pythonic_detector.py +1 -1
- sglang/srt/function_call/qwen25_detector.py +1 -1
- sglang/srt/{openai_api/utils.py → jinja_template_utils.py} +6 -5
- sglang/srt/layers/activation.py +40 -3
- sglang/srt/layers/attention/aiter_backend.py +20 -4
- sglang/srt/layers/attention/base_attn_backend.py +1 -1
- sglang/srt/layers/attention/cutlass_mla_backend.py +39 -15
- sglang/srt/layers/attention/flashattention_backend.py +71 -72
- sglang/srt/layers/attention/flashinfer_backend.py +10 -8
- sglang/srt/layers/attention/flashinfer_mla_backend.py +29 -28
- sglang/srt/layers/attention/flashmla_backend.py +7 -12
- sglang/srt/layers/attention/tbo_backend.py +3 -3
- sglang/srt/layers/attention/triton_backend.py +138 -130
- sglang/srt/layers/attention/triton_ops/decode_attention.py +2 -7
- sglang/srt/layers/attention/vision.py +51 -24
- sglang/srt/layers/communicator.py +28 -10
- sglang/srt/layers/dp_attention.py +11 -2
- sglang/srt/layers/layernorm.py +29 -2
- sglang/srt/layers/linear.py +0 -4
- sglang/srt/layers/logits_processor.py +2 -14
- sglang/srt/layers/moe/ep_moe/kernels.py +165 -7
- sglang/srt/layers/moe/ep_moe/layer.py +249 -33
- sglang/srt/layers/moe/ep_moe/token_dispatcher.py +11 -37
- 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
- sglang/srt/layers/moe/fused_moe_triton/fused_moe.py +7 -4
- sglang/srt/layers/moe/fused_moe_triton/layer.py +75 -12
- sglang/srt/layers/moe/topk.py +107 -12
- sglang/srt/layers/pooler.py +56 -0
- sglang/srt/layers/quantization/compressed_tensors/compressed_tensors_moe.py +6 -2
- sglang/srt/layers/quantization/deep_gemm_wrapper/__init__.py +1 -0
- sglang/srt/layers/quantization/{deep_gemm.py → deep_gemm_wrapper/compile_utils.py} +23 -80
- sglang/srt/layers/quantization/deep_gemm_wrapper/configurer.py +32 -0
- sglang/srt/layers/quantization/deep_gemm_wrapper/entrypoint.py +110 -0
- sglang/srt/layers/quantization/fp8.py +25 -17
- sglang/srt/layers/quantization/fp8_kernel.py +44 -15
- sglang/srt/layers/quantization/fp8_utils.py +87 -22
- sglang/srt/layers/quantization/modelopt_quant.py +62 -8
- sglang/srt/layers/quantization/utils.py +5 -2
- sglang/srt/layers/radix_attention.py +2 -3
- sglang/srt/layers/rotary_embedding.py +42 -2
- sglang/srt/layers/sampler.py +1 -1
- sglang/srt/lora/lora_manager.py +249 -105
- sglang/srt/lora/mem_pool.py +53 -50
- sglang/srt/lora/utils.py +1 -1
- sglang/srt/managers/cache_controller.py +33 -14
- sglang/srt/managers/io_struct.py +31 -10
- sglang/srt/managers/multimodal_processors/base_processor.py +2 -2
- sglang/srt/managers/multimodal_processors/vila.py +85 -0
- sglang/srt/managers/schedule_batch.py +79 -37
- sglang/srt/managers/schedule_policy.py +70 -56
- sglang/srt/managers/scheduler.py +220 -79
- sglang/srt/managers/template_manager.py +226 -0
- sglang/srt/managers/tokenizer_manager.py +40 -10
- sglang/srt/managers/tp_worker.py +12 -2
- sglang/srt/managers/tp_worker_overlap_thread.py +11 -0
- sglang/srt/mem_cache/{paged_allocator.py → allocator.py} +125 -34
- sglang/srt/mem_cache/base_prefix_cache.py +52 -8
- sglang/srt/mem_cache/chunk_cache.py +11 -15
- sglang/srt/mem_cache/hiradix_cache.py +38 -25
- sglang/srt/mem_cache/memory_pool.py +213 -505
- sglang/srt/mem_cache/memory_pool_host.py +380 -0
- sglang/srt/mem_cache/radix_cache.py +56 -28
- sglang/srt/model_executor/cuda_graph_runner.py +198 -100
- sglang/srt/model_executor/forward_batch_info.py +32 -10
- sglang/srt/model_executor/model_runner.py +28 -12
- sglang/srt/model_loader/loader.py +16 -2
- sglang/srt/model_loader/weight_utils.py +11 -2
- sglang/srt/models/bert.py +113 -13
- sglang/srt/models/deepseek_nextn.py +29 -27
- sglang/srt/models/deepseek_v2.py +213 -173
- sglang/srt/models/glm4.py +312 -0
- sglang/srt/models/internvl.py +46 -102
- sglang/srt/models/mimo_mtp.py +2 -18
- sglang/srt/models/roberta.py +117 -9
- sglang/srt/models/vila.py +305 -0
- sglang/srt/reasoning_parser.py +21 -11
- sglang/srt/sampling/sampling_batch_info.py +24 -0
- sglang/srt/sampling/sampling_params.py +2 -0
- sglang/srt/server_args.py +351 -238
- sglang/srt/speculative/build_eagle_tree.py +1 -1
- sglang/srt/speculative/eagle_draft_cuda_graph_runner.py +131 -9
- sglang/srt/speculative/eagle_draft_extend_cuda_graph_runner.py +130 -14
- sglang/srt/speculative/eagle_utils.py +468 -116
- sglang/srt/speculative/eagle_worker.py +258 -84
- sglang/srt/torch_memory_saver_adapter.py +19 -15
- sglang/srt/two_batch_overlap.py +4 -2
- sglang/srt/utils.py +235 -11
- sglang/test/attention/test_prefix_chunk_info.py +2 -0
- sglang/test/runners.py +38 -3
- sglang/test/test_block_fp8.py +1 -0
- sglang/test/test_block_fp8_deep_gemm_blackwell.py +252 -0
- sglang/test/test_block_fp8_ep.py +2 -0
- sglang/test/test_utils.py +4 -1
- sglang/utils.py +9 -0
- sglang/version.py +1 -1
- {sglang-0.4.7.dist-info → sglang-0.4.8.dist-info}/METADATA +8 -14
- {sglang-0.4.7.dist-info → sglang-0.4.8.dist-info}/RECORD +150 -128
- sglang/srt/entrypoints/verl_engine.py +0 -179
- sglang/srt/openai_api/adapter.py +0 -1990
- {sglang-0.4.7.dist-info → sglang-0.4.8.dist-info}/WHEEL +0 -0
- {sglang-0.4.7.dist-info → sglang-0.4.8.dist-info}/licenses/LICENSE +0 -0
- {sglang-0.4.7.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
|