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.
- sglang/api.py +1 -1
- sglang/bench_offline_throughput.py +19 -0
- sglang/bench_one_batch.py +2 -2
- sglang/bench_serving.py +123 -79
- sglang/global_config.py +8 -3
- sglang/lang/backend/runtime_endpoint.py +1 -1
- sglang/lang/ir.py +1 -1
- sglang/srt/_custom_ops.py +83 -91
- sglang/srt/configs/load_config.py +4 -1
- sglang/srt/configs/model_config.py +48 -2
- sglang/srt/configs/qwen2_5_vl_config.py +5 -2
- sglang/srt/constrained/base_grammar_backend.py +117 -15
- sglang/srt/constrained/llguidance_backend.py +151 -0
- sglang/srt/constrained/outlines_backend.py +24 -33
- sglang/srt/constrained/xgrammar_backend.py +69 -38
- sglang/srt/distributed/device_communicators/custom_all_reduce.py +225 -80
- sglang/srt/distributed/parallel_state.py +48 -3
- sglang/srt/entrypoints/engine.py +67 -9
- sglang/srt/entrypoints/http_server.py +190 -41
- sglang/srt/entrypoints/verl_engine.py +147 -0
- sglang/srt/function_call_parser.py +0 -1
- sglang/srt/layers/activation.py +11 -0
- sglang/srt/layers/attention/{__init__.py → base_attn_backend.py} +14 -6
- sglang/srt/layers/attention/double_sparsity_backend.py +1 -1
- sglang/srt/layers/attention/flashinfer_backend.py +208 -295
- sglang/srt/layers/attention/flashinfer_mla_backend.py +582 -0
- sglang/srt/layers/attention/torch_native_backend.py +1 -1
- sglang/srt/layers/attention/triton_backend.py +9 -6
- sglang/srt/layers/attention/triton_ops/decode_attention.py +3 -0
- sglang/srt/layers/attention/triton_ops/extend_attention.py +20 -4
- sglang/srt/layers/attention/triton_ops/rocm_mla_decode_rope.py +439 -0
- sglang/srt/layers/attention/utils.py +39 -0
- sglang/srt/layers/attention/vision.py +60 -63
- sglang/srt/layers/dp_attention.py +142 -1
- sglang/srt/layers/layernorm.py +1 -1
- sglang/srt/layers/linear.py +3 -1
- sglang/srt/layers/logits_processor.py +281 -45
- sglang/srt/layers/moe/ep_moe/kernels.py +126 -8
- sglang/srt/layers/moe/ep_moe/layer.py +140 -28
- sglang/srt/layers/moe/fused_moe_native.py +2 -0
- 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
- 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
- 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
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=14336,device_name=AMD_Instinct_MI300X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=14336,device_name=AMD_Instinct_MI325X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=14336,device_name=AMD_Radeon_Graphics.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=1792,device_name=AMD_Instinct_MI300X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=1792,device_name=AMD_Instinct_MI325X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=1792,device_name=AMD_Radeon_Graphics.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=3584,device_name=AMD_Instinct_MI300X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=3584,device_name=AMD_Instinct_MI325X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=3584,device_name=AMD_Radeon_Graphics.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=4096,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +16 -16
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=4096,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +16 -16
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=4096,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8.json +16 -16
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=7168,device_name=AMD_Instinct_MI300X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=7168,device_name=AMD_Instinct_MI325X.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=7168,device_name=AMD_Radeon_Graphics.json +18 -18
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=8192,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8.json +15 -15
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=8192,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8.json +15 -15
- sglang/srt/layers/moe/fused_moe_triton/configs/E=8,N=8192,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8.json +15 -15
- sglang/srt/layers/moe/fused_moe_triton/fused_moe.py +88 -20
- sglang/srt/layers/moe/fused_moe_triton/layer.py +34 -13
- sglang/srt/layers/moe/topk.py +13 -4
- sglang/srt/layers/quantization/__init__.py +111 -7
- sglang/srt/layers/quantization/blockwise_int8.py +409 -0
- 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
- sglang/srt/layers/quantization/configs/N=1536,K=1536,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=1536,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=2048,K=512,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=2304,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- sglang/srt/layers/quantization/configs/N=24576,K=1536,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- sglang/srt/layers/quantization/configs/N=24576,K=1536,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- sglang/srt/layers/quantization/configs/N=24576,K=1536,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- 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
- sglang/srt/layers/quantization/configs/N=24576,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=256,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- 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
- sglang/srt/layers/quantization/configs/N=32768,K=512,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=576,K=7168,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=7168,K=1024,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=7168,K=1152,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=7168,K=128,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=AMD_Instinct_MI300X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=AMD_Instinct_MI325X,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=AMD_Radeon_Graphics,dtype=fp8_w8a8,block_shape=[128, 128].json +164 -0
- 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
- sglang/srt/layers/quantization/configs/N=7168,K=16384,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- 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
- sglang/srt/layers/quantization/configs/N=7168,K=18432,device_name=NVIDIA_L20Y,dtype=fp8_w8a8,block_shape=[128, 128].json +26 -0
- sglang/srt/layers/quantization/fp8.py +69 -28
- sglang/srt/layers/quantization/fp8_utils.py +17 -1
- sglang/srt/layers/quantization/gptq.py +416 -0
- sglang/srt/layers/quantization/int8_kernel.py +327 -0
- sglang/srt/layers/quantization/int8_utils.py +73 -0
- sglang/srt/layers/quantization/modelopt_quant.py +18 -1
- sglang/srt/layers/radix_attention.py +1 -0
- sglang/srt/layers/rotary_embedding.py +0 -1
- sglang/srt/layers/sampler.py +76 -31
- sglang/srt/layers/vocab_parallel_embedding.py +14 -13
- sglang/srt/lora/lora.py +17 -1
- sglang/srt/lora/lora_config.py +5 -0
- sglang/srt/lora/lora_manager.py +1 -3
- sglang/srt/managers/cache_controller.py +193 -62
- sglang/srt/managers/configure_logging.py +2 -1
- sglang/srt/managers/data_parallel_controller.py +6 -2
- sglang/srt/managers/detokenizer_manager.py +124 -102
- sglang/srt/managers/image_processor.py +2 -1
- sglang/srt/managers/io_struct.py +143 -6
- sglang/srt/managers/schedule_batch.py +238 -197
- sglang/srt/managers/schedule_policy.py +29 -29
- sglang/srt/managers/scheduler.py +681 -259
- sglang/srt/managers/session_controller.py +6 -2
- sglang/srt/managers/tokenizer_manager.py +224 -68
- sglang/srt/managers/tp_worker.py +15 -4
- sglang/srt/managers/tp_worker_overlap_thread.py +3 -4
- sglang/srt/mem_cache/chunk_cache.py +18 -11
- sglang/srt/mem_cache/hiradix_cache.py +394 -0
- sglang/srt/mem_cache/memory_pool.py +44 -18
- sglang/srt/mem_cache/radix_cache.py +58 -47
- sglang/srt/metrics/collector.py +94 -36
- sglang/srt/model_executor/cuda_graph_runner.py +55 -24
- sglang/srt/model_executor/forward_batch_info.py +49 -16
- sglang/srt/model_executor/model_runner.py +209 -28
- sglang/srt/model_loader/loader.py +3 -3
- sglang/srt/model_loader/weight_utils.py +36 -14
- sglang/srt/models/baichuan.py +31 -6
- sglang/srt/models/chatglm.py +39 -7
- sglang/srt/models/commandr.py +29 -5
- sglang/srt/models/dbrx.py +31 -5
- sglang/srt/models/deepseek.py +43 -6
- sglang/srt/models/deepseek_nextn.py +32 -19
- sglang/srt/models/deepseek_v2.py +265 -29
- sglang/srt/models/exaone.py +19 -9
- sglang/srt/models/gemma.py +22 -8
- sglang/srt/models/gemma2.py +25 -12
- sglang/srt/models/gemma2_reward.py +5 -1
- sglang/srt/models/gpt2.py +28 -13
- sglang/srt/models/gpt_bigcode.py +27 -5
- sglang/srt/models/granite.py +21 -9
- sglang/srt/models/grok.py +21 -4
- sglang/srt/models/internlm2.py +36 -6
- sglang/srt/models/internlm2_reward.py +5 -1
- sglang/srt/models/llama.py +26 -9
- sglang/srt/models/llama_classification.py +5 -1
- sglang/srt/models/llama_eagle.py +17 -4
- sglang/srt/models/llama_embedding.py +5 -1
- sglang/srt/models/llama_reward.py +7 -2
- sglang/srt/models/llava.py +19 -3
- sglang/srt/models/llavavid.py +10 -1
- sglang/srt/models/minicpm.py +26 -2
- sglang/srt/models/minicpm3.py +39 -3
- sglang/srt/models/minicpmv.py +45 -14
- sglang/srt/models/mixtral.py +20 -9
- sglang/srt/models/mixtral_quant.py +50 -8
- sglang/srt/models/mllama.py +57 -11
- sglang/srt/models/olmo.py +34 -6
- sglang/srt/models/olmo2.py +34 -13
- sglang/srt/models/olmoe.py +26 -4
- sglang/srt/models/phi3_small.py +29 -10
- sglang/srt/models/qwen.py +26 -3
- sglang/srt/models/qwen2.py +26 -4
- sglang/srt/models/qwen2_5_vl.py +46 -8
- sglang/srt/models/qwen2_eagle.py +17 -5
- sglang/srt/models/qwen2_moe.py +44 -6
- sglang/srt/models/qwen2_rm.py +78 -0
- sglang/srt/models/qwen2_vl.py +39 -8
- sglang/srt/models/stablelm.py +32 -5
- sglang/srt/models/torch_native_llama.py +5 -2
- sglang/srt/models/xverse.py +21 -9
- sglang/srt/models/xverse_moe.py +45 -7
- sglang/srt/models/yivl.py +2 -1
- sglang/srt/openai_api/adapter.py +109 -24
- sglang/srt/openai_api/protocol.py +17 -1
- sglang/srt/reasoning_parser.py +154 -0
- sglang/srt/sampling/penaltylib/__init__.py +4 -6
- sglang/srt/sampling/penaltylib/frequency_penalty.py +66 -0
- sglang/srt/sampling/penaltylib/{penalizers/min_new_tokens.py → min_new_tokens.py} +15 -23
- sglang/srt/sampling/penaltylib/orchestrator.py +39 -188
- sglang/srt/sampling/penaltylib/presence_penalty.py +66 -0
- sglang/srt/sampling/sampling_batch_info.py +79 -157
- sglang/srt/sampling/sampling_params.py +16 -13
- sglang/srt/server_args.py +136 -52
- sglang/srt/speculative/build_eagle_tree.py +2 -8
- sglang/srt/speculative/eagle_draft_cuda_graph_runner.py +0 -1
- sglang/srt/speculative/eagle_utils.py +92 -58
- sglang/srt/speculative/eagle_worker.py +186 -94
- sglang/srt/speculative/spec_info.py +1 -13
- sglang/srt/utils.py +43 -17
- sglang/srt/warmup.py +47 -0
- sglang/test/few_shot_gsm8k.py +4 -1
- sglang/test/runners.py +389 -126
- sglang/test/send_one.py +88 -0
- sglang/test/test_block_fp8_ep.py +361 -0
- sglang/test/test_programs.py +1 -1
- sglang/test/test_utils.py +138 -84
- sglang/utils.py +50 -60
- sglang/version.py +1 -1
- {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/METADATA +21 -15
- {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/RECORD +214 -166
- {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/WHEEL +1 -1
- sglang/bench_latency.py +0 -1
- sglang/srt/sampling/penaltylib/penalizers/frequency_penalty.py +0 -75
- sglang/srt/sampling/penaltylib/penalizers/presence_penalty.py +0 -74
- sglang/srt/sampling/penaltylib/penalizers/repetition_penalty.py +0 -85
- sglang/test/srt/sampling/penaltylib/utils.py +0 -344
- {sglang-0.4.3.post1.dist-info → sglang-0.4.3.post3.dist-info}/LICENSE +0 -0
- {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
|
sglang/srt/layers/activation.py
CHANGED
@@ -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.
|
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[
|
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[
|
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(
|
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
|
|