Support penalty in overlap mode; return logprob with chunked prefill; improve benchmark scripts (#3988)
Co-authored-by: SangBin Cho <rkooo567@gmail.com> Co-authored-by: dhou-xai <dhou@x.ai> Co-authored-by: Hanming Lu <hanming_lu@berkeley.edu>
This commit is contained in:
@@ -16,10 +16,11 @@ The definition of objects transfered between different
|
||||
processes (TokenizerManager, DetokenizerManager, Controller).
|
||||
"""
|
||||
|
||||
import copy
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from typing import Dict, List, Optional, Union
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
from sglang.srt.managers.schedule_batch import BaseFinishReason
|
||||
from sglang.srt.sampling.sampling_params import SamplingParams
|
||||
@@ -55,6 +56,8 @@ class GenerateReqInput:
|
||||
logprob_start_len: Optional[Union[List[int], int]] = None
|
||||
# If return logprobs, the number of top logprobs to return at each position.
|
||||
top_logprobs_num: Optional[Union[List[int], int]] = None
|
||||
# If return logprobs, the token ids to return logprob for.
|
||||
token_ids_logprob: Optional[Union[List[List[int]], List[int]]] = None
|
||||
# Whether to detokenize tokens in text in the returned logprobs.
|
||||
return_text_in_logprobs: bool = False
|
||||
# Whether to stream output.
|
||||
@@ -146,6 +149,8 @@ class GenerateReqInput:
|
||||
self.logprob_start_len = -1
|
||||
if self.top_logprobs_num is None:
|
||||
self.top_logprobs_num = 0
|
||||
if not self.token_ids_logprob: # covers both None and []
|
||||
self.token_ids_logprob = None
|
||||
else:
|
||||
if self.parallel_sample_num == 1:
|
||||
num = self.batch_size
|
||||
@@ -191,6 +196,17 @@ class GenerateReqInput:
|
||||
else:
|
||||
assert self.parallel_sample_num == 1
|
||||
|
||||
if not self.token_ids_logprob: # covers both None and []
|
||||
self.token_ids_logprob = [None] * num
|
||||
elif not isinstance(self.token_ids_logprob, list):
|
||||
self.token_ids_logprob = [[self.token_ids_logprob] for _ in range(num)]
|
||||
elif not isinstance(self.token_ids_logprob[0], list):
|
||||
self.token_ids_logprob = [
|
||||
copy.deepcopy(self.token_ids_logprob) for _ in range(num)
|
||||
]
|
||||
else:
|
||||
assert self.parallel_sample_num == 1
|
||||
|
||||
if self.custom_logit_processor is None:
|
||||
self.custom_logit_processor = [None] * num
|
||||
elif not isinstance(self.custom_logit_processor, list):
|
||||
@@ -198,6 +214,12 @@ class GenerateReqInput:
|
||||
else:
|
||||
assert self.parallel_sample_num == 1
|
||||
|
||||
# Other checks
|
||||
if self.session_params is not None:
|
||||
assert isinstance(self.session_params, dict) or isinstance(
|
||||
self.session_params[0], dict
|
||||
)
|
||||
|
||||
def regenerate_rid(self):
|
||||
self.rid = uuid.uuid4().hex
|
||||
return self.rid
|
||||
@@ -212,6 +234,7 @@ class GenerateReqInput:
|
||||
return_logprob=self.return_logprob[i],
|
||||
logprob_start_len=self.logprob_start_len[i],
|
||||
top_logprobs_num=self.top_logprobs_num[i],
|
||||
token_ids_logprob=self.token_ids_logprob[i],
|
||||
return_text_in_logprobs=self.return_text_in_logprobs,
|
||||
stream=self.stream,
|
||||
log_metrics=self.log_metrics,
|
||||
@@ -244,6 +267,8 @@ class TokenizedGenerateReqInput:
|
||||
logprob_start_len: int
|
||||
# If return logprobs, the number of top logprobs to return at each position.
|
||||
top_logprobs_num: int
|
||||
# If return logprobs, the token id to return logprob for
|
||||
token_ids_logprob: List[int]
|
||||
# Whether to stream output
|
||||
stream: bool
|
||||
|
||||
@@ -378,10 +403,21 @@ class BatchTokenIDOut:
|
||||
input_top_logprobs_idx: List[List]
|
||||
output_top_logprobs_val: List[List]
|
||||
output_top_logprobs_idx: List[List]
|
||||
input_token_ids_logprobs_val: List[List]
|
||||
input_token_ids_logprobs_idx: List[List]
|
||||
output_token_ids_logprobs_val: List[List]
|
||||
output_token_ids_logprobs_idx: List[List]
|
||||
|
||||
# Hidden states
|
||||
output_hidden_states: List[List[float]]
|
||||
|
||||
|
||||
@dataclass
|
||||
class BatchMultimodalDecodeReq:
|
||||
# The request id
|
||||
rids: List[str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class BatchStrOut:
|
||||
# The request id
|
||||
@@ -406,10 +442,21 @@ class BatchStrOut:
|
||||
input_top_logprobs_idx: List[List]
|
||||
output_top_logprobs_val: List[List]
|
||||
output_top_logprobs_idx: List[List]
|
||||
input_token_ids_logprobs_val: List[List]
|
||||
input_token_ids_logprobs_idx: List[List]
|
||||
output_token_ids_logprobs_val: List[List]
|
||||
output_token_ids_logprobs_idx: List[List]
|
||||
|
||||
# Hidden states
|
||||
output_hidden_states: List[List[float]]
|
||||
|
||||
|
||||
@dataclass
|
||||
class BatchMultimodalOut:
|
||||
# The request id
|
||||
rids: List[str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class BatchEmbeddingOut:
|
||||
# The request id
|
||||
@@ -439,6 +486,8 @@ class UpdateWeightFromDiskReqInput:
|
||||
class UpdateWeightFromDiskReqOutput:
|
||||
success: bool
|
||||
message: str
|
||||
# Number of paused requests during weight sync.
|
||||
num_paused_requests: Optional[int] = 0
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -526,11 +575,57 @@ class AbortReq:
|
||||
rid: str
|
||||
|
||||
|
||||
class ProfileReq(Enum):
|
||||
@dataclass
|
||||
class GetInternalStateReq:
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class GetInternalStateReqOutput:
|
||||
internal_state: Dict[Any, Any]
|
||||
|
||||
|
||||
@dataclass
|
||||
class SetInternalStateReq:
|
||||
server_args: Dict[str, Any]
|
||||
|
||||
|
||||
@dataclass
|
||||
class SetInternalStateReqOutput:
|
||||
updated: bool
|
||||
server_args: Dict[str, Any]
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProfileReqInput:
|
||||
# The output directory
|
||||
output_dir: Optional[str] = None
|
||||
# If set, it profile as many as this number of steps.
|
||||
# If it is set, profiling is automatically stopped after this step, and
|
||||
# the caller doesn't need to run stop_profile.
|
||||
num_steps: Optional[int] = None
|
||||
activities: Optional[List[str]] = None
|
||||
|
||||
|
||||
class ProfileReqType(Enum):
|
||||
START_PROFILE = 1
|
||||
STOP_PROFILE = 2
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProfileReq:
|
||||
type: ProfileReqType
|
||||
output_dir: Optional[str] = None
|
||||
num_steps: Optional[int] = None
|
||||
activities: Optional[List[str]] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProfileReqOutput:
|
||||
success: bool
|
||||
message: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class ConfigureLoggingReq:
|
||||
log_requests: Optional[bool] = None
|
||||
@@ -556,6 +651,11 @@ class OpenSessionReqOutput:
|
||||
success: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class HealthCheckOutput:
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Function:
|
||||
description: Optional[str] = None
|
||||
|
||||
Reference in New Issue
Block a user