Improve benchmark scripts and error message printing (#2922)
This commit is contained in:
@@ -59,6 +59,9 @@ class GenerateReqInput:
|
||||
return_text_in_logprobs: bool = False
|
||||
# Whether to stream output.
|
||||
stream: bool = False
|
||||
# Whether to log metrics for this request (e.g. health_generate calls do not log metrics)
|
||||
log_metrics: bool = True
|
||||
|
||||
# The modalities of the image data [image, multi-images, video]
|
||||
modalities: Optional[List[str]] = None
|
||||
# LoRA related
|
||||
@@ -196,6 +199,7 @@ class GenerateReqInput:
|
||||
top_logprobs_num=self.top_logprobs_num[i],
|
||||
return_text_in_logprobs=self.return_text_in_logprobs,
|
||||
stream=self.stream,
|
||||
log_metrics=self.log_metrics,
|
||||
modalities=self.modalities[i] if self.modalities else None,
|
||||
lora_path=self.lora_path[i] if self.lora_path is not None else None,
|
||||
)
|
||||
@@ -243,6 +247,8 @@ class EmbeddingReqInput:
|
||||
sampling_params: Union[List[Dict], Dict] = None
|
||||
# Dummy input embeds for compatibility
|
||||
input_embeds: Optional[Union[List[List[List[float]]], List[List[float]]]] = None
|
||||
# Whether to log metrics for this request (e.g. health_generate calls do not log metrics)
|
||||
log_metrics: bool = True
|
||||
|
||||
def normalize_batch_and_arguments(self):
|
||||
if (self.text is None and self.input_ids is None) or (
|
||||
|
||||
@@ -631,7 +631,8 @@ class Scheduler:
|
||||
if len(req.origin_input_ids) > self.max_req_input_len:
|
||||
logger.warning(
|
||||
"Request length is longer than the KV cache pool size or "
|
||||
"the max context length. Truncated!!!"
|
||||
"the max context length. Truncated. "
|
||||
f"{len(req.origin_input_ids)=}, {self.max_req_input_len=}."
|
||||
)
|
||||
req.origin_input_ids = req.origin_input_ids[: self.max_req_input_len]
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ from sglang.srt.utils import (
|
||||
get_zmq_socket,
|
||||
kill_process_tree,
|
||||
)
|
||||
from sglang.utils import get_exception_traceback
|
||||
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
|
||||
@@ -640,7 +641,9 @@ class TokenizerManager:
|
||||
|
||||
self.to_create_loop = False
|
||||
loop = asyncio.get_event_loop()
|
||||
self.asyncio_tasks.add(loop.create_task(self.handle_loop()))
|
||||
self.asyncio_tasks.add(
|
||||
loop.create_task(print_exception_wrapper(self.handle_loop))
|
||||
)
|
||||
|
||||
# We cannot add signal handler when the tokenizer manager is not in
|
||||
# the main thread due to the CPython limitation.
|
||||
@@ -653,7 +656,9 @@ class TokenizerManager:
|
||||
"not in the main thread. This disables graceful shutdown of the "
|
||||
"tokenizer manager when SIGTERM is received."
|
||||
)
|
||||
self.asyncio_tasks.add(loop.create_task(self.sigterm_watchdog()))
|
||||
self.asyncio_tasks.add(
|
||||
loop.create_task(print_exception_wrapper(self.sigterm_watchdog))
|
||||
)
|
||||
|
||||
async def sigterm_watchdog(self):
|
||||
while not self.gracefully_exit:
|
||||
@@ -738,9 +743,13 @@ class TokenizerManager:
|
||||
state.finished = recv_obj.finished_reasons[i] is not None
|
||||
state.event.set()
|
||||
|
||||
if self.enable_metrics:
|
||||
if self.enable_metrics and state.obj.log_metrics:
|
||||
self.collect_metrics(state, recv_obj, i)
|
||||
if self.dump_requests_folder and state.finished:
|
||||
if (
|
||||
self.dump_requests_folder
|
||||
and state.finished
|
||||
and state.obj.log_metrics
|
||||
):
|
||||
self.dump_requests(state, out_dict)
|
||||
elif isinstance(recv_obj, OpenSessionReqOutput):
|
||||
self.session_futures[recv_obj.session_id].set_result(
|
||||
@@ -887,20 +896,38 @@ class TokenizerManager:
|
||||
)
|
||||
|
||||
if len(self.dump_request_list) >= self.dump_requests_threshold:
|
||||
filename = os.path.join(
|
||||
self.dump_requests_folder,
|
||||
datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".pkl",
|
||||
)
|
||||
logger.info(f"Dump {len(self.dump_request_list)} requests to {filename}")
|
||||
|
||||
to_dump = self.dump_request_list
|
||||
self.dump_request_list = []
|
||||
|
||||
def background_task():
|
||||
os.makedirs(self.dump_requests_folder, exist_ok=True)
|
||||
current_time = datetime.now()
|
||||
filename = current_time.strftime("%Y-%m-%d_%H-%M-%S") + ".pkl"
|
||||
with open(os.path.join(self.dump_requests_folder, filename), "wb") as f:
|
||||
with open(filename, "wb") as f:
|
||||
pickle.dump(to_dump, f)
|
||||
|
||||
# Schedule the task to run in the background without awaiting it
|
||||
asyncio.create_task(asyncio.to_thread(background_task))
|
||||
|
||||
|
||||
async def print_exception_wrapper(func):
|
||||
"""
|
||||
Sometimes an asyncio function does not print exception.
|
||||
We do another wrapper to handle the exception.
|
||||
"""
|
||||
try:
|
||||
await func()
|
||||
except Exception:
|
||||
traceback = get_exception_traceback()
|
||||
logger.error(f"TokenizerManager hit an exception: {traceback}")
|
||||
kill_process_tree(os.getpid(), include_parent=True)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class SignalHandler:
|
||||
def __init__(self, tokenizer_manager):
|
||||
self.tokenizer_manager = tokenizer_manager
|
||||
|
||||
Reference in New Issue
Block a user