sglang 0.2.15__py3-none-any.whl → 0.3.1__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/bench_latency.py +10 -6
- sglang/bench_serving.py +33 -38
- sglang/global_config.py +0 -4
- sglang/lang/backend/runtime_endpoint.py +13 -6
- sglang/lang/interpreter.py +1 -1
- sglang/launch_server.py +3 -6
- sglang/launch_server_llavavid.py +7 -8
- sglang/srt/{model_config.py → configs/model_config.py} +5 -0
- sglang/srt/constrained/__init__.py +2 -0
- sglang/srt/constrained/fsm_cache.py +29 -38
- sglang/srt/constrained/jump_forward.py +0 -1
- sglang/srt/conversation.py +4 -1
- sglang/srt/hf_transformers_utils.py +2 -4
- sglang/srt/layers/attention_backend.py +480 -0
- sglang/srt/layers/flashinfer_utils.py +235 -0
- sglang/srt/layers/logits_processor.py +64 -77
- sglang/srt/layers/radix_attention.py +11 -161
- sglang/srt/layers/sampler.py +40 -35
- sglang/srt/layers/torchao_utils.py +75 -0
- sglang/srt/layers/{decode_attention.py → triton_attention/decode_attention.py} +67 -63
- sglang/srt/layers/{extend_attention.py → triton_attention/extend_attention.py} +40 -132
- sglang/srt/layers/{prefill_attention.py → triton_attention/prefill_attention.py} +13 -7
- sglang/srt/lora/lora.py +403 -0
- sglang/srt/lora/lora_config.py +43 -0
- sglang/srt/lora/lora_manager.py +256 -0
- sglang/srt/managers/controller_multi.py +1 -5
- sglang/srt/managers/controller_single.py +0 -5
- sglang/srt/managers/io_struct.py +16 -1
- sglang/srt/managers/policy_scheduler.py +122 -5
- sglang/srt/managers/schedule_batch.py +110 -74
- sglang/srt/managers/tokenizer_manager.py +24 -15
- sglang/srt/managers/tp_worker.py +181 -115
- sglang/srt/model_executor/cuda_graph_runner.py +60 -133
- sglang/srt/model_executor/forward_batch_info.py +35 -312
- sglang/srt/model_executor/model_runner.py +118 -141
- sglang/srt/models/baichuan.py +416 -0
- sglang/srt/models/chatglm.py +6 -8
- sglang/srt/models/commandr.py +1 -5
- sglang/srt/models/dbrx.py +1 -5
- sglang/srt/models/deepseek.py +1 -5
- sglang/srt/models/deepseek_v2.py +1 -5
- sglang/srt/models/exaone.py +8 -43
- sglang/srt/models/gemma.py +1 -5
- sglang/srt/models/gemma2.py +1 -5
- sglang/srt/models/gpt_bigcode.py +1 -5
- sglang/srt/models/grok.py +1 -5
- sglang/srt/models/internlm2.py +1 -5
- sglang/srt/models/{llama2.py → llama.py} +48 -26
- sglang/srt/models/llama_classification.py +14 -40
- sglang/srt/models/llama_embedding.py +7 -6
- sglang/srt/models/llava.py +38 -16
- sglang/srt/models/llavavid.py +7 -8
- sglang/srt/models/minicpm.py +1 -5
- sglang/srt/models/minicpm3.py +665 -0
- sglang/srt/models/mistral.py +2 -3
- sglang/srt/models/mixtral.py +6 -5
- sglang/srt/models/mixtral_quant.py +1 -5
- sglang/srt/models/qwen.py +1 -5
- sglang/srt/models/qwen2.py +1 -5
- sglang/srt/models/qwen2_moe.py +6 -5
- sglang/srt/models/stablelm.py +1 -5
- sglang/srt/models/xverse.py +375 -0
- sglang/srt/models/xverse_moe.py +445 -0
- sglang/srt/openai_api/adapter.py +65 -46
- sglang/srt/openai_api/protocol.py +11 -3
- sglang/srt/sampling/sampling_batch_info.py +67 -58
- sglang/srt/server.py +24 -14
- sglang/srt/server_args.py +130 -28
- sglang/srt/utils.py +12 -0
- sglang/test/few_shot_gsm8k.py +132 -0
- sglang/test/runners.py +114 -22
- sglang/test/test_programs.py +70 -0
- sglang/test/test_utils.py +89 -1
- sglang/utils.py +38 -4
- sglang/version.py +1 -1
- {sglang-0.2.15.dist-info → sglang-0.3.1.dist-info}/METADATA +31 -18
- sglang-0.3.1.dist-info/RECORD +129 -0
- {sglang-0.2.15.dist-info → sglang-0.3.1.dist-info}/WHEEL +1 -1
- sglang-0.2.15.dist-info/RECORD +0 -118
- {sglang-0.2.15.dist-info → sglang-0.3.1.dist-info}/LICENSE +0 -0
- {sglang-0.2.15.dist-info → sglang-0.3.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,416 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
|
3
|
+
#
|
4
|
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
5
|
+
# and OPT implementations in this library. It has been modified from its
|
6
|
+
# original forms to accommodate minor architectural differences compared
|
7
|
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
"""Inference-only BaiChuan model compatible with HuggingFace weights."""
|
21
|
+
import math
|
22
|
+
from typing import Iterable, Optional, Tuple
|
23
|
+
|
24
|
+
import torch
|
25
|
+
from torch import nn
|
26
|
+
from transformers import PretrainedConfig
|
27
|
+
from vllm.config import CacheConfig
|
28
|
+
from vllm.distributed import (
|
29
|
+
get_tensor_model_parallel_rank,
|
30
|
+
get_tensor_model_parallel_world_size,
|
31
|
+
)
|
32
|
+
from vllm.model_executor.layers.linear import (
|
33
|
+
MergedColumnParallelLinear,
|
34
|
+
QKVParallelLinear,
|
35
|
+
RowParallelLinear,
|
36
|
+
)
|
37
|
+
from vllm.model_executor.layers.quantization.base_config import QuantizationConfig
|
38
|
+
from vllm.model_executor.layers.rotary_embedding import get_rope
|
39
|
+
from vllm.model_executor.layers.vocab_parallel_embedding import (
|
40
|
+
ParallelLMHead,
|
41
|
+
VocabParallelEmbedding,
|
42
|
+
)
|
43
|
+
from vllm.model_executor.model_loader.weight_utils import default_weight_loader
|
44
|
+
|
45
|
+
from sglang.srt.layers.activation import SiluAndMul
|
46
|
+
from sglang.srt.layers.layernorm import RMSNorm
|
47
|
+
from sglang.srt.layers.logits_processor import LogitsProcessor
|
48
|
+
from sglang.srt.layers.radix_attention import RadixAttention
|
49
|
+
from sglang.srt.model_executor.forward_batch_info import InputMetadata
|
50
|
+
|
51
|
+
|
52
|
+
def _get_alibi_slopes(total_num_heads: int) -> torch.Tensor:
|
53
|
+
closest_power_of_2 = 2 ** math.floor(math.log2(total_num_heads))
|
54
|
+
base = torch.tensor(
|
55
|
+
2 ** (-(2 ** -(math.log2(closest_power_of_2) - 3))),
|
56
|
+
dtype=torch.float32,
|
57
|
+
)
|
58
|
+
powers = torch.arange(1, 1 + closest_power_of_2, dtype=torch.int32)
|
59
|
+
slopes = torch.pow(base, powers)
|
60
|
+
|
61
|
+
if closest_power_of_2 != total_num_heads:
|
62
|
+
extra_base = torch.tensor(
|
63
|
+
2 ** (-(2 ** -(math.log2(2 * closest_power_of_2) - 3))),
|
64
|
+
dtype=torch.float32,
|
65
|
+
)
|
66
|
+
num_remaining_heads = min(
|
67
|
+
closest_power_of_2, total_num_heads - closest_power_of_2
|
68
|
+
)
|
69
|
+
extra_powers = torch.arange(
|
70
|
+
start=1, end=1 + 2 * num_remaining_heads, step=2, dtype=torch.int32
|
71
|
+
)
|
72
|
+
slopes = torch.cat([slopes, torch.pow(extra_base, extra_powers)], dim=0)
|
73
|
+
return slopes
|
74
|
+
|
75
|
+
|
76
|
+
class BaiChuanMLP(nn.Module):
|
77
|
+
|
78
|
+
def __init__(
|
79
|
+
self,
|
80
|
+
hidden_size: int,
|
81
|
+
intermediate_size: int,
|
82
|
+
hidden_act: str,
|
83
|
+
quant_config: Optional[QuantizationConfig] = None,
|
84
|
+
):
|
85
|
+
super().__init__()
|
86
|
+
self.gate_up_proj = MergedColumnParallelLinear(
|
87
|
+
hidden_size, [intermediate_size] * 2, bias=False, quant_config=quant_config
|
88
|
+
)
|
89
|
+
self.down_proj = RowParallelLinear(
|
90
|
+
intermediate_size, hidden_size, bias=False, quant_config=quant_config
|
91
|
+
)
|
92
|
+
if hidden_act != "silu":
|
93
|
+
raise ValueError(
|
94
|
+
f"Unsupported activation: {hidden_act}. "
|
95
|
+
"Only silu is supported for now."
|
96
|
+
)
|
97
|
+
self.act_fn = SiluAndMul()
|
98
|
+
|
99
|
+
def forward(self, x):
|
100
|
+
gate_up, _ = self.gate_up_proj(x)
|
101
|
+
x = self.act_fn(gate_up)
|
102
|
+
x, _ = self.down_proj(x)
|
103
|
+
return x
|
104
|
+
|
105
|
+
|
106
|
+
class BaiChuanAttention(nn.Module):
|
107
|
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
108
|
+
|
109
|
+
def __init__(
|
110
|
+
self,
|
111
|
+
hidden_size: int,
|
112
|
+
num_heads: int,
|
113
|
+
position_embedding: str,
|
114
|
+
rope_theta: float = 10000,
|
115
|
+
max_position_embeddings: int = 8192,
|
116
|
+
quant_config: Optional[QuantizationConfig] = None,
|
117
|
+
layer_id: int = 0,
|
118
|
+
):
|
119
|
+
super().__init__()
|
120
|
+
self.hidden_size = hidden_size
|
121
|
+
tensor_model_parallel_world_size = get_tensor_model_parallel_world_size()
|
122
|
+
tp_size = get_tensor_model_parallel_world_size()
|
123
|
+
self.total_num_heads = num_heads
|
124
|
+
assert self.total_num_heads % tensor_model_parallel_world_size == 0
|
125
|
+
self.num_heads = self.total_num_heads // tensor_model_parallel_world_size
|
126
|
+
self.head_dim = hidden_size // self.total_num_heads
|
127
|
+
self.postion_embedding = position_embedding
|
128
|
+
self.rope_theta = rope_theta
|
129
|
+
self.max_position_embeddings = max_position_embeddings
|
130
|
+
self.total_num_kv_heads = self.num_heads
|
131
|
+
if self.total_num_kv_heads >= tp_size:
|
132
|
+
# Number of KV heads is greater than TP size, so we partition
|
133
|
+
# the KV heads across multiple tensor parallel GPUs.
|
134
|
+
assert self.total_num_kv_heads % tp_size == 0
|
135
|
+
else:
|
136
|
+
# Number of KV heads is less than TP size, so we replicate
|
137
|
+
# the KV heads across multiple tensor parallel GPUs.
|
138
|
+
assert tp_size % self.total_num_kv_heads == 0
|
139
|
+
self.num_kv_heads = max(1, self.total_num_kv_heads // tp_size)
|
140
|
+
|
141
|
+
# pylint: disable=invalid-name
|
142
|
+
self.W_pack = QKVParallelLinear(
|
143
|
+
hidden_size,
|
144
|
+
self.head_dim,
|
145
|
+
self.total_num_heads,
|
146
|
+
self.total_num_heads,
|
147
|
+
bias=False,
|
148
|
+
quant_config=quant_config,
|
149
|
+
)
|
150
|
+
self.o_proj = RowParallelLinear(
|
151
|
+
self.total_num_heads * self.head_dim,
|
152
|
+
hidden_size,
|
153
|
+
bias=False,
|
154
|
+
quant_config=quant_config,
|
155
|
+
)
|
156
|
+
# Create the alibi slopes and slice them.
|
157
|
+
if self.postion_embedding == "ALIBI":
|
158
|
+
tp_rank = get_tensor_model_parallel_rank()
|
159
|
+
head_start = tp_rank * self.num_heads
|
160
|
+
head_end = (tp_rank + 1) * self.num_heads
|
161
|
+
alibi_slopes = _get_alibi_slopes(self.total_num_heads)
|
162
|
+
alibi_slopes = alibi_slopes[head_start:head_end].tolist()
|
163
|
+
|
164
|
+
scaling = self.head_dim**-0.5
|
165
|
+
self.attn = RadixAttention(
|
166
|
+
self.num_heads,
|
167
|
+
self.head_dim,
|
168
|
+
scaling,
|
169
|
+
num_kv_heads=self.num_kv_heads,
|
170
|
+
layer_id=layer_id,
|
171
|
+
)
|
172
|
+
else:
|
173
|
+
self.rotary_emb = get_rope(
|
174
|
+
self.head_dim,
|
175
|
+
rotary_dim=self.head_dim,
|
176
|
+
max_position=self.max_position_embeddings,
|
177
|
+
base=self.rope_theta,
|
178
|
+
)
|
179
|
+
self.scaling = self.head_dim**-0.5
|
180
|
+
self.attn = RadixAttention(
|
181
|
+
self.num_heads,
|
182
|
+
self.head_dim,
|
183
|
+
self.scaling,
|
184
|
+
num_kv_heads=self.num_kv_heads,
|
185
|
+
layer_id=layer_id,
|
186
|
+
)
|
187
|
+
|
188
|
+
def forward(
|
189
|
+
self,
|
190
|
+
positions: torch.Tensor,
|
191
|
+
hidden_states: torch.Tensor,
|
192
|
+
input_metadata: InputMetadata,
|
193
|
+
) -> torch.Tensor:
|
194
|
+
qkv, _ = self.W_pack(hidden_states)
|
195
|
+
q, k, v = qkv.chunk(chunks=3, dim=-1)
|
196
|
+
if self.postion_embedding != "ALIBI":
|
197
|
+
q, k = self.rotary_emb(positions, q, k)
|
198
|
+
attn_output = self.attn(q, k, v, input_metadata)
|
199
|
+
output, _ = self.o_proj(attn_output)
|
200
|
+
return output
|
201
|
+
|
202
|
+
|
203
|
+
class BaiChuanDecoderLayer(nn.Module):
|
204
|
+
|
205
|
+
def __init__(
|
206
|
+
self,
|
207
|
+
config: PretrainedConfig,
|
208
|
+
position_embedding: str,
|
209
|
+
layer_id: int = 0,
|
210
|
+
quant_config: Optional[QuantizationConfig] = None,
|
211
|
+
):
|
212
|
+
super().__init__()
|
213
|
+
self.hidden_size = config.hidden_size
|
214
|
+
rope_theta = getattr(config, "rope_theta", 10000)
|
215
|
+
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
|
216
|
+
self.self_attn = BaiChuanAttention(
|
217
|
+
hidden_size=self.hidden_size,
|
218
|
+
num_heads=config.num_attention_heads,
|
219
|
+
position_embedding=position_embedding,
|
220
|
+
rope_theta=rope_theta,
|
221
|
+
layer_id=layer_id,
|
222
|
+
max_position_embeddings=max_position_embeddings,
|
223
|
+
quant_config=quant_config,
|
224
|
+
)
|
225
|
+
self.mlp = BaiChuanMLP(
|
226
|
+
hidden_size=self.hidden_size,
|
227
|
+
intermediate_size=config.intermediate_size,
|
228
|
+
hidden_act=config.hidden_act,
|
229
|
+
quant_config=quant_config,
|
230
|
+
)
|
231
|
+
self.input_layernorm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
232
|
+
self.post_attention_layernorm = RMSNorm(
|
233
|
+
config.hidden_size, eps=config.rms_norm_eps
|
234
|
+
)
|
235
|
+
|
236
|
+
def forward(
|
237
|
+
self,
|
238
|
+
positions: torch.Tensor,
|
239
|
+
hidden_states: torch.Tensor,
|
240
|
+
input_metadata: InputMetadata,
|
241
|
+
residual: Optional[torch.Tensor],
|
242
|
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
243
|
+
# Self Attention
|
244
|
+
if residual is None:
|
245
|
+
residual = hidden_states
|
246
|
+
hidden_states = self.input_layernorm(hidden_states)
|
247
|
+
else:
|
248
|
+
hidden_states, residual = self.input_layernorm(hidden_states, residual)
|
249
|
+
hidden_states = self.self_attn(
|
250
|
+
positions=positions,
|
251
|
+
hidden_states=hidden_states,
|
252
|
+
input_metadata=input_metadata,
|
253
|
+
)
|
254
|
+
|
255
|
+
# Fully Connected
|
256
|
+
hidden_states, residual = self.post_attention_layernorm(hidden_states, residual)
|
257
|
+
hidden_states = self.mlp(hidden_states)
|
258
|
+
return hidden_states, residual
|
259
|
+
|
260
|
+
|
261
|
+
class BaiChuanModel(nn.Module):
|
262
|
+
|
263
|
+
def __init__(
|
264
|
+
self,
|
265
|
+
config: PretrainedConfig,
|
266
|
+
position_embedding: str,
|
267
|
+
quant_config: Optional[QuantizationConfig] = None,
|
268
|
+
):
|
269
|
+
super().__init__()
|
270
|
+
self.config = config
|
271
|
+
self.padding_idx = config.pad_token_id
|
272
|
+
self.vocab_size = config.vocab_size
|
273
|
+
|
274
|
+
self.embed_tokens = VocabParallelEmbedding(
|
275
|
+
config.vocab_size,
|
276
|
+
config.hidden_size,
|
277
|
+
)
|
278
|
+
self.layers = nn.ModuleList(
|
279
|
+
[
|
280
|
+
BaiChuanDecoderLayer(
|
281
|
+
config,
|
282
|
+
layer_id=i,
|
283
|
+
position_embedding=position_embedding,
|
284
|
+
quant_config=quant_config,
|
285
|
+
)
|
286
|
+
for i in range(config.num_hidden_layers)
|
287
|
+
]
|
288
|
+
)
|
289
|
+
self.norm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
290
|
+
|
291
|
+
def forward(
|
292
|
+
self,
|
293
|
+
input_ids: torch.Tensor,
|
294
|
+
positions: torch.Tensor,
|
295
|
+
input_metadata: InputMetadata,
|
296
|
+
) -> torch.Tensor:
|
297
|
+
hidden_states = self.embed_tokens(input_ids)
|
298
|
+
residual = None
|
299
|
+
for i in range(len(self.layers)):
|
300
|
+
layer = self.layers[i]
|
301
|
+
hidden_states, residual = layer(
|
302
|
+
positions,
|
303
|
+
hidden_states,
|
304
|
+
input_metadata,
|
305
|
+
residual,
|
306
|
+
)
|
307
|
+
hidden_states, _ = self.norm(hidden_states, residual)
|
308
|
+
return hidden_states
|
309
|
+
|
310
|
+
|
311
|
+
class BaiChuanBaseForCausalLM(nn.Module):
|
312
|
+
packed_modules_mapping = {
|
313
|
+
"W_pack": ["W_pack"],
|
314
|
+
"gate_up_proj": [
|
315
|
+
"gate_proj",
|
316
|
+
"up_proj",
|
317
|
+
],
|
318
|
+
}
|
319
|
+
# LoRA specific attributes
|
320
|
+
supported_lora_modules = [
|
321
|
+
"W_pack",
|
322
|
+
"o_proj",
|
323
|
+
"gate_up_proj",
|
324
|
+
"down_proj",
|
325
|
+
]
|
326
|
+
embedding_modules = {}
|
327
|
+
embedding_padding_modules = []
|
328
|
+
|
329
|
+
def __init__(
|
330
|
+
self,
|
331
|
+
config: PretrainedConfig,
|
332
|
+
position_embedding: str,
|
333
|
+
cache_config: Optional[CacheConfig] = None,
|
334
|
+
quant_config: Optional[QuantizationConfig] = None,
|
335
|
+
):
|
336
|
+
super().__init__()
|
337
|
+
|
338
|
+
self.config = config
|
339
|
+
|
340
|
+
self.quant_config = quant_config
|
341
|
+
self.model = BaiChuanModel(config, position_embedding, quant_config)
|
342
|
+
self.lm_head = ParallelLMHead(
|
343
|
+
config.vocab_size, config.hidden_size, quant_config=quant_config
|
344
|
+
)
|
345
|
+
if self.config.tie_word_embeddings:
|
346
|
+
self.lm_head.weight = self.model.embed_tokens.weight
|
347
|
+
self.logits_processor = LogitsProcessor(config)
|
348
|
+
|
349
|
+
def forward(
|
350
|
+
self,
|
351
|
+
input_ids: torch.Tensor,
|
352
|
+
positions: torch.Tensor,
|
353
|
+
input_metadata: InputMetadata,
|
354
|
+
) -> torch.Tensor:
|
355
|
+
hidden_states = self.model(input_ids, positions, input_metadata)
|
356
|
+
return self.logits_processor(
|
357
|
+
input_ids, hidden_states, self.lm_head.weight, input_metadata
|
358
|
+
)
|
359
|
+
|
360
|
+
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
361
|
+
stacked_params_mapping = [
|
362
|
+
# (param_name, shard_name, shard_id)
|
363
|
+
("gate_up_proj", "gate_proj", 0),
|
364
|
+
("gate_up_proj", "up_proj", 1),
|
365
|
+
]
|
366
|
+
params_dict = dict(self.named_parameters())
|
367
|
+
for name, loaded_weight in weights:
|
368
|
+
if "rotary_emb.inv_freq" in name:
|
369
|
+
continue
|
370
|
+
if name == "lm_head.weight":
|
371
|
+
# Unlike Baichuan, Baichuan2 normalizes the head weights.
|
372
|
+
# Refer to:
|
373
|
+
# https://huggingface.co/baichuan-inc/Baichuan2-7B-Chat/blob/84603cde5ebffb6084e476cfaeceaf0b8b91fe54/modeling_baichuan.py#L508
|
374
|
+
# Distinguish between Baichuan and Baichuan2 by checking the
|
375
|
+
# vocab size. This is suggested by
|
376
|
+
# https://github.com/vllm-project/vllm/pull/1022#discussion_r1325652704
|
377
|
+
is_baichuan2 = self.config.vocab_size == 125696
|
378
|
+
if is_baichuan2:
|
379
|
+
loaded_weight = torch.nn.functional.normalize(loaded_weight)
|
380
|
+
|
381
|
+
for param_name, weight_name, shard_id in stacked_params_mapping:
|
382
|
+
if weight_name not in name:
|
383
|
+
continue
|
384
|
+
name = name.replace(weight_name, param_name)
|
385
|
+
# Skip loading extra bias for GPTQ models.
|
386
|
+
if name.endswith(".bias") and name not in params_dict:
|
387
|
+
continue
|
388
|
+
param = params_dict[name]
|
389
|
+
weight_loader = param.weight_loader
|
390
|
+
weight_loader(param, loaded_weight, shard_id)
|
391
|
+
break
|
392
|
+
else:
|
393
|
+
# Skip loading extra bias for GPTQ models.
|
394
|
+
if name.endswith(".bias") and name not in params_dict:
|
395
|
+
continue
|
396
|
+
param = params_dict[name]
|
397
|
+
weight_loader = getattr(param, "weight_loader", default_weight_loader)
|
398
|
+
weight_loader(param, loaded_weight)
|
399
|
+
|
400
|
+
|
401
|
+
class BaichuanForCausalLM(BaiChuanBaseForCausalLM):
|
402
|
+
"""Baichuan 13B and Baichuan2 7B/13B."""
|
403
|
+
|
404
|
+
def __init__(
|
405
|
+
self,
|
406
|
+
config,
|
407
|
+
cache_config: Optional[CacheConfig] = None,
|
408
|
+
quant_config: Optional[QuantizationConfig] = None,
|
409
|
+
):
|
410
|
+
if config.hidden_size == 4096: # baichuan2 7b
|
411
|
+
super().__init__(config, "ROPE", cache_config, quant_config)
|
412
|
+
else: # baichuan 13b, baichuan2 13b
|
413
|
+
super().__init__(config, "ALIBI", cache_config, quant_config)
|
414
|
+
|
415
|
+
|
416
|
+
EntryClass = [BaichuanForCausalLM]
|
sglang/srt/models/chatglm.py
CHANGED
@@ -42,7 +42,6 @@ from sglang.srt.layers.activation import SiluAndMul
|
|
42
42
|
from sglang.srt.layers.layernorm import RMSNorm
|
43
43
|
from sglang.srt.layers.logits_processor import LogitsProcessor
|
44
44
|
from sglang.srt.layers.radix_attention import RadixAttention
|
45
|
-
from sglang.srt.layers.sampler import Sampler
|
46
45
|
from sglang.srt.model_executor.forward_batch_info import InputMetadata
|
47
46
|
|
48
47
|
LoraConfig = None
|
@@ -371,7 +370,6 @@ class ChatGLMForCausalLM(nn.Module):
|
|
371
370
|
self.transformer = ChatGLMModel(config, cache_config, quant_config)
|
372
371
|
self.lm_head = self.transformer.output_layer
|
373
372
|
self.logits_processor = LogitsProcessor(config)
|
374
|
-
self.sampler = Sampler()
|
375
373
|
|
376
374
|
@torch.no_grad()
|
377
375
|
def forward(
|
@@ -381,11 +379,9 @@ class ChatGLMForCausalLM(nn.Module):
|
|
381
379
|
input_metadata: InputMetadata,
|
382
380
|
) -> torch.Tensor:
|
383
381
|
hidden_states = self.transformer(input_ids, positions, input_metadata)
|
384
|
-
|
382
|
+
return self.logits_processor(
|
385
383
|
input_ids, hidden_states, self.lm_head.weight, input_metadata
|
386
384
|
)
|
387
|
-
sample_output = self.sampler(logits_output, input_metadata.sampling_info)
|
388
|
-
return sample_output, logits_output
|
389
385
|
|
390
386
|
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
391
387
|
params_dict = dict(self.named_parameters(remove_duplicate=False))
|
@@ -402,6 +398,8 @@ class ChatGLMForCausalLM(nn.Module):
|
|
402
398
|
weight_loader(param, loaded_weight)
|
403
399
|
|
404
400
|
|
405
|
-
|
406
|
-
|
407
|
-
|
401
|
+
class ChatGLMModel(ChatGLMForCausalLM):
|
402
|
+
pass
|
403
|
+
|
404
|
+
|
405
|
+
EntryClass = [ChatGLMForCausalLM, ChatGLMModel]
|
sglang/srt/models/commandr.py
CHANGED
@@ -64,7 +64,6 @@ from vllm.model_executor.utils import set_weight_attrs
|
|
64
64
|
from sglang.srt.layers.activation import SiluAndMul
|
65
65
|
from sglang.srt.layers.logits_processor import LogitsProcessor
|
66
66
|
from sglang.srt.layers.radix_attention import RadixAttention
|
67
|
-
from sglang.srt.layers.sampler import Sampler
|
68
67
|
from sglang.srt.model_executor.forward_batch_info import InputMetadata
|
69
68
|
|
70
69
|
|
@@ -327,7 +326,6 @@ class CohereForCausalLM(nn.Module):
|
|
327
326
|
self.config = config
|
328
327
|
self.quant_config = quant_config
|
329
328
|
self.logits_processor = LogitsProcessor(config)
|
330
|
-
self.sampler = Sampler()
|
331
329
|
self.model = CohereModel(config, quant_config)
|
332
330
|
|
333
331
|
@torch.no_grad()
|
@@ -342,11 +340,9 @@ class CohereForCausalLM(nn.Module):
|
|
342
340
|
positions,
|
343
341
|
input_metadata,
|
344
342
|
)
|
345
|
-
|
343
|
+
return self.logits_processor(
|
346
344
|
input_ids, hidden_states, self.model.embed_tokens.weight, input_metadata
|
347
345
|
)
|
348
|
-
sample_output = self.sampler(logits_output, input_metadata.sampling_info)
|
349
|
-
return sample_output, logits_output
|
350
346
|
|
351
347
|
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
352
348
|
stacked_params_mapping = [
|
sglang/srt/models/dbrx.py
CHANGED
@@ -45,7 +45,6 @@ from vllm.transformers_utils.configs.dbrx import DbrxConfig
|
|
45
45
|
|
46
46
|
from sglang.srt.layers.logits_processor import LogitsProcessor
|
47
47
|
from sglang.srt.layers.radix_attention import RadixAttention
|
48
|
-
from sglang.srt.layers.sampler import Sampler
|
49
48
|
from sglang.srt.model_executor.forward_batch_info import InputMetadata
|
50
49
|
|
51
50
|
|
@@ -383,7 +382,6 @@ class DbrxForCausalLM(nn.Module):
|
|
383
382
|
padding_size=DEFAULT_VOCAB_PADDING_SIZE,
|
384
383
|
)
|
385
384
|
self.logits_processor = LogitsProcessor(config)
|
386
|
-
self.sampler = Sampler()
|
387
385
|
|
388
386
|
@torch.no_grad()
|
389
387
|
def forward(
|
@@ -393,11 +391,9 @@ class DbrxForCausalLM(nn.Module):
|
|
393
391
|
input_metadata: InputMetadata,
|
394
392
|
) -> torch.Tensor:
|
395
393
|
hidden_states = self.transformer(input_ids, positions, input_metadata)
|
396
|
-
|
394
|
+
return self.logits_processor(
|
397
395
|
input_ids, hidden_states, self.lm_head.weight, input_metadata
|
398
396
|
)
|
399
|
-
sample_output = self.sampler(logits_output, input_metadata.sampling_info)
|
400
|
-
return sample_output, logits_output
|
401
397
|
|
402
398
|
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
403
399
|
expert_params_mapping = [
|
sglang/srt/models/deepseek.py
CHANGED
@@ -46,7 +46,6 @@ from sglang.srt.layers.activation import SiluAndMul
|
|
46
46
|
from sglang.srt.layers.layernorm import RMSNorm
|
47
47
|
from sglang.srt.layers.logits_processor import LogitsProcessor
|
48
48
|
from sglang.srt.layers.radix_attention import RadixAttention
|
49
|
-
from sglang.srt.layers.sampler import Sampler
|
50
49
|
from sglang.srt.model_executor.forward_batch_info import InputMetadata
|
51
50
|
|
52
51
|
|
@@ -386,7 +385,6 @@ class DeepseekForCausalLM(nn.Module):
|
|
386
385
|
config.vocab_size, config.hidden_size, quant_config=quant_config
|
387
386
|
)
|
388
387
|
self.logits_processor = LogitsProcessor(config)
|
389
|
-
self.sampler = Sampler()
|
390
388
|
|
391
389
|
@torch.no_grad()
|
392
390
|
def forward(
|
@@ -396,11 +394,9 @@ class DeepseekForCausalLM(nn.Module):
|
|
396
394
|
input_metadata: InputMetadata,
|
397
395
|
) -> torch.Tensor:
|
398
396
|
hidden_states = self.model(input_ids, positions, input_metadata)
|
399
|
-
|
397
|
+
return self.logits_processor(
|
400
398
|
input_ids, hidden_states, self.lm_head.weight, input_metadata
|
401
399
|
)
|
402
|
-
sample_output = self.sampler(logits_output, input_metadata.sampling_info)
|
403
|
-
return sample_output, logits_output
|
404
400
|
|
405
401
|
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
406
402
|
stacked_params_mapping = [
|
sglang/srt/models/deepseek_v2.py
CHANGED
@@ -46,7 +46,6 @@ from sglang.srt.layers.activation import SiluAndMul
|
|
46
46
|
from sglang.srt.layers.layernorm import RMSNorm
|
47
47
|
from sglang.srt.layers.logits_processor import LogitsProcessor
|
48
48
|
from sglang.srt.layers.radix_attention import RadixAttention
|
49
|
-
from sglang.srt.layers.sampler import Sampler
|
50
49
|
from sglang.srt.managers.schedule_batch import global_server_args_dict
|
51
50
|
from sglang.srt.model_executor.forward_batch_info import InputMetadata
|
52
51
|
|
@@ -649,7 +648,6 @@ class DeepseekV2ForCausalLM(nn.Module):
|
|
649
648
|
config.vocab_size, config.hidden_size, quant_config=quant_config
|
650
649
|
)
|
651
650
|
self.logits_processor = LogitsProcessor(config)
|
652
|
-
self.sampler = Sampler()
|
653
651
|
|
654
652
|
def forward(
|
655
653
|
self,
|
@@ -658,11 +656,9 @@ class DeepseekV2ForCausalLM(nn.Module):
|
|
658
656
|
input_metadata: InputMetadata,
|
659
657
|
) -> torch.Tensor:
|
660
658
|
hidden_states = self.model(input_ids, positions, input_metadata)
|
661
|
-
|
659
|
+
return self.logits_processor(
|
662
660
|
input_ids, hidden_states, self.lm_head.weight, input_metadata
|
663
661
|
)
|
664
|
-
sample_output = self.sampler(logits_output, input_metadata.sampling_info)
|
665
|
-
return sample_output, logits_output
|
666
662
|
|
667
663
|
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
668
664
|
stacked_params_mapping = [
|
sglang/srt/models/exaone.py
CHANGED
@@ -40,7 +40,6 @@ from sglang.srt.layers.activation import SiluAndMul
|
|
40
40
|
from sglang.srt.layers.layernorm import RMSNorm
|
41
41
|
from sglang.srt.layers.logits_processor import LogitsProcessor, LogitsProcessorOutput
|
42
42
|
from sglang.srt.layers.radix_attention import RadixAttention
|
43
|
-
from sglang.srt.layers.sampler import Sampler
|
44
43
|
from sglang.srt.model_executor.forward_batch_info import InputMetadata
|
45
44
|
|
46
45
|
|
@@ -297,7 +296,6 @@ class ExaoneForCausalLM(nn.Module):
|
|
297
296
|
config,
|
298
297
|
quant_config: Optional[QuantizationConfig] = None,
|
299
298
|
cache_config: Optional[CacheConfig] = None,
|
300
|
-
efficient_weight_load=False,
|
301
299
|
) -> None:
|
302
300
|
super().__init__()
|
303
301
|
self.config = config
|
@@ -305,7 +303,6 @@ class ExaoneForCausalLM(nn.Module):
|
|
305
303
|
self.transformer = ExaoneModel(config, quant_config=quant_config)
|
306
304
|
self.lm_head = ParallelLMHead(config.vocab_size, config.hidden_size)
|
307
305
|
self.logits_processor = LogitsProcessor(config)
|
308
|
-
self.sampler = Sampler()
|
309
306
|
|
310
307
|
@torch.no_grad()
|
311
308
|
def forward(
|
@@ -318,36 +315,11 @@ class ExaoneForCausalLM(nn.Module):
|
|
318
315
|
hidden_states = self.transformer(
|
319
316
|
input_ids, positions, input_metadata, input_embeds
|
320
317
|
)
|
321
|
-
|
318
|
+
return self.logits_processor(
|
322
319
|
input_ids, hidden_states, self.lm_head.weight, input_metadata
|
323
320
|
)
|
324
|
-
sample_output = self.sampler(logits_output, input_metadata.sampling_info)
|
325
|
-
return sample_output, logits_output
|
326
321
|
|
327
|
-
def
|
328
|
-
stacked_params_mapping = [
|
329
|
-
# (param_name, shard_name, shard_id, num_shard)
|
330
|
-
("qkv_proj", "q_proj", "q", 3),
|
331
|
-
("qkv_proj", "k_proj", "k", 3),
|
332
|
-
("qkv_proj", "v_proj", "v", 3),
|
333
|
-
("gate_up_proj", "c_fc_0", 0, 2),
|
334
|
-
("gate_up_proj", "c_fc_1", 1, 2),
|
335
|
-
]
|
336
|
-
for param_name, weight_name, shard_id, num_shard in stacked_params_mapping:
|
337
|
-
if weight_name in name:
|
338
|
-
return (
|
339
|
-
name.replace(weight_name, param_name)[: -len(".weight")],
|
340
|
-
num_shard,
|
341
|
-
)
|
342
|
-
return name[: -len(".weight")], 1
|
343
|
-
|
344
|
-
def get_num_params(self):
|
345
|
-
params_dict = dict(self.named_parameters())
|
346
|
-
return len(params_dict)
|
347
|
-
|
348
|
-
def load_weights(
|
349
|
-
self, weights: Iterable[Tuple[str, torch.Tensor]], name=None, loaded_weight=None
|
350
|
-
):
|
322
|
+
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
351
323
|
stacked_params_mapping = [
|
352
324
|
# (param_name, shard_name, shard_id)
|
353
325
|
("qkv_proj", "q_proj", "q"),
|
@@ -358,16 +330,17 @@ class ExaoneForCausalLM(nn.Module):
|
|
358
330
|
]
|
359
331
|
params_dict = dict(self.named_parameters())
|
360
332
|
|
361
|
-
|
333
|
+
for name, loaded_weight in weights:
|
362
334
|
if "rotary_emb.inv_freq" in name or "projector" in name:
|
363
|
-
|
335
|
+
continue
|
364
336
|
if "rotary_emb.cos_cached" in name or "rotary_emb.sin_cached" in name:
|
365
337
|
# Models trained using ColossalAI may include these tensors in
|
366
338
|
# the checkpoint. Skip them.
|
367
|
-
|
339
|
+
continue
|
368
340
|
if name.startswith("model.vision_tower") and name not in params_dict:
|
369
|
-
|
341
|
+
continue
|
370
342
|
|
343
|
+
name = name.replace("attn.attention", "self_attn")
|
371
344
|
for param_name, weight_name, shard_id in stacked_params_mapping:
|
372
345
|
if weight_name not in name:
|
373
346
|
continue
|
@@ -382,18 +355,10 @@ class ExaoneForCausalLM(nn.Module):
|
|
382
355
|
else:
|
383
356
|
# Skip loading extra bias for GPTQ models.
|
384
357
|
if name.endswith(".bias") and name not in params_dict:
|
385
|
-
|
358
|
+
continue
|
386
359
|
param = params_dict[name]
|
387
360
|
weight_loader = getattr(param, "weight_loader", default_weight_loader)
|
388
361
|
weight_loader(param, loaded_weight)
|
389
362
|
|
390
|
-
if name is None or loaded_weight is None:
|
391
|
-
for name, loaded_weight in weights:
|
392
|
-
name = name.replace("attn.attention", "self_attn")
|
393
|
-
load_weights_per_param(name, loaded_weight)
|
394
|
-
else:
|
395
|
-
name = name.replace("attn.attention", "self_attn")
|
396
|
-
load_weights_per_param(name, loaded_weight)
|
397
|
-
|
398
363
|
|
399
364
|
EntryClass = ExaoneForCausalLM
|