Fix deprecation warning of sre_parse for python 3.13 (#16247)

This commit is contained in:
Lianmin Zheng
2025-12-31 21:25:09 -08:00
committed by GitHub
parent b5af283b1c
commit e4c1e441af
5 changed files with 32 additions and 19 deletions
-2
View File
@@ -733,8 +733,6 @@ class Scheduler(
self.running_batch: ScheduleBatch = ScheduleBatch(reqs=[], batch_is_full=False) self.running_batch: ScheduleBatch = ScheduleBatch(reqs=[], batch_is_full=False)
# The current forward batch # The current forward batch
self.cur_batch: Optional[ScheduleBatch] = None self.cur_batch: Optional[ScheduleBatch] = None
# The current split prefill batch
self.split_prefill_batch: Optional[ScheduleBatch] = None
# The last forward batch # The last forward batch
self.last_batch: Optional[ScheduleBatch] = None self.last_batch: Optional[ScheduleBatch] = None
self.forward_ct = 0 self.forward_ct = 0
+19 -13
View File
@@ -219,11 +219,12 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
def init_model_config(self): def init_model_config(self):
server_args = self.server_args server_args = self.server_args
model_config_class = getattr(self, "model_config_class", ModelConfig)
# Read model args # Read model args
self.model_path = server_args.model_path self.model_path = server_args.model_path
self.served_model_name = server_args.served_model_name self.served_model_name = server_args.served_model_name
self.model_config = ModelConfig.from_server_args(server_args) self.model_config = model_config_class.from_server_args(server_args)
self.is_generation = self.model_config.is_generation self.is_generation = self.model_config.is_generation
self.is_image_gen = self.model_config.is_image_gen self.is_image_gen = self.model_config.is_image_gen
self.context_len = self.model_config.context_len self.context_len = self.model_config.context_len
@@ -232,11 +233,15 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
speculative_algorithm = SpeculativeAlgorithm.from_string( speculative_algorithm = SpeculativeAlgorithm.from_string(
server_args.speculative_algorithm server_args.speculative_algorithm
) )
self.reserve_input_token_num = ( if speculative_algorithm.is_eagle():
0 # In the current eagle implementation, we store the draft tokens in the output token slots,
if speculative_algorithm.is_none() # so we need to reserve the space for the draft tokens.
else server_args.speculative_num_draft_tokens self.num_reserved_tokens = max(
server_args.speculative_eagle_topk * server_args.speculative_num_steps,
server_args.speculative_num_draft_tokens,
) )
else:
self.num_reserved_tokens = 0
self.validate_total_tokens = True self.validate_total_tokens = True
def init_tokenizer_and_processor(self): def init_tokenizer_and_processor(self):
@@ -457,6 +462,9 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
) )
self.init_communicators(self.server_args) self.init_communicators(self.server_args)
self.sampling_params_class = SamplingParams
self.signal_handler_class = SignalHandler
async def generate_request( async def generate_request(
self, self,
obj: Union[GenerateReqInput, EmbeddingReqInput], obj: Union[GenerateReqInput, EmbeddingReqInput],
@@ -724,7 +732,7 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
# FIXME: unify the length validation logic with the one in the scheduler. # FIXME: unify the length validation logic with the one in the scheduler.
_max_req_len = self.context_len _max_req_len = self.context_len
input_token_num = len(input_ids) if input_ids is not None else 0 input_token_num = len(input_ids) if input_ids is not None else 0
input_token_num += self.reserve_input_token_num input_token_num += self.num_reserved_tokens
# Validate input length # Validate input length
if input_token_num >= self.context_len: if input_token_num >= self.context_len:
@@ -860,9 +868,6 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
f"The input_ids {input_ids} contains values greater than the vocab size ({vocab_size})." f"The input_ids {input_ids} contains values greater than the vocab size ({vocab_size})."
) )
def _get_sampling_params(self, sampling_kwargs: Dict) -> SamplingParams:
return SamplingParams(**sampling_kwargs)
def _create_tokenized_object( def _create_tokenized_object(
self, self,
obj: Union[GenerateReqInput, EmbeddingReqInput], obj: Union[GenerateReqInput, EmbeddingReqInput],
@@ -880,7 +885,7 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
sampling_kwargs = {**self.preferred_sampling_params, **obj.sampling_params} sampling_kwargs = {**self.preferred_sampling_params, **obj.sampling_params}
else: else:
sampling_kwargs = obj.sampling_params sampling_kwargs = obj.sampling_params
sampling_params = self._get_sampling_params(sampling_kwargs) sampling_params = self.sampling_params_class(**sampling_kwargs)
sampling_params.normalize(self.tokenizer) sampling_params.normalize(self.tokenizer)
sampling_params.verify(self.model_config.vocab_size) sampling_params.verify(self.model_config.vocab_size)
@@ -1412,21 +1417,22 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
) )
self.event_loop = loop self.event_loop = loop
# We cannot add signal handler when the tokenizer manager is not in
# the main thread due to the CPython limitation.
if threading.current_thread() is threading.main_thread(): if threading.current_thread() is threading.main_thread():
signal_handler = SignalHandler(self) signal_handler = self.signal_handler_class(self)
loop.add_signal_handler(signal.SIGTERM, signal_handler.sigterm_handler) loop.add_signal_handler(signal.SIGTERM, signal_handler.sigterm_handler)
# Update the signal handler for the process. It overrides the sigquit handler in the launch phase. # Update the signal handler for the process. It overrides the sigquit handler in the launch phase.
loop.add_signal_handler( loop.add_signal_handler(
signal.SIGQUIT, signal_handler.running_phase_sigquit_handler signal.SIGQUIT, signal_handler.running_phase_sigquit_handler
) )
else: else:
# We cannot add signal handler when the tokenizer manager is not in
# the main thread due to the CPython limitation.
logger.warning( logger.warning(
"Signal handler is not added because the tokenizer manager is " "Signal handler is not added because the tokenizer manager is "
"not in the main thread. This disables graceful shutdown of the " "not in the main thread. This disables graceful shutdown of the "
"tokenizer manager when SIGTERM is received." "tokenizer manager when SIGTERM is received."
) )
self.asyncio_tasks.add( self.asyncio_tasks.add(
loop.create_task(print_exception_wrapper(self.sigterm_watchdog)) loop.create_task(print_exception_wrapper(self.sigterm_watchdog))
) )
@@ -5,7 +5,7 @@ Mixin class providing multiplexing scheduling logic
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import TYPE_CHECKING from typing import TYPE_CHECKING, Optional
import torch import torch
import torch.distributed as dist import torch.distributed as dist
@@ -23,6 +23,7 @@ from sglang.srt.multiplex.pdmux_context import (
) )
if TYPE_CHECKING: if TYPE_CHECKING:
from sglang.srt.managers.schedule_batch import ScheduleBatch
from sglang.srt.managers.scheduler import Scheduler from sglang.srt.managers.scheduler import Scheduler
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -31,6 +32,9 @@ logger = logging.getLogger(__name__)
class SchedulerMultiplexMixin: class SchedulerMultiplexMixin:
def init_pdmux(self: Scheduler): def init_pdmux(self: Scheduler):
# The current split prefill batch
self.split_prefill_batch: Optional[ScheduleBatch] = None
# for pd_multiplexing, Init stream_groups, exclude normal stream for prefill only and decode only # for pd_multiplexing, Init stream_groups, exclude normal stream for prefill only and decode only
self.pdmux_config = load_pdmux_config(self.server_args.pdmux_config_path) self.pdmux_config = load_pdmux_config(self.server_args.pdmux_config_path)
initialize_stream_groups(self.gpu_id, self.pdmux_config) initialize_stream_groups(self.gpu_id, self.pdmux_config)
@@ -14,9 +14,14 @@
"""Sampling parameters for text generation.""" """Sampling parameters for text generation."""
import logging import logging
import sre_parse
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
# sre_parse is deprecated in Python 3.11+, use re._parser instead
try:
import re._parser as sre_parse
except ImportError:
import sre_parse # Python < 3.11
_SAMPLING_EPS = 1e-6 _SAMPLING_EPS = 1e-6
TOP_K_ALL = 1 << 30 TOP_K_ALL = 1 << 30
+1 -1
View File
@@ -5198,4 +5198,4 @@ def auto_choose_speculative_params(self: ServerArgs):
return (5, 4, 8) return (5, 4, 8)
else: else:
# The default value for all other models # The default value for all other models
return (5, 4, 8) return (3, 1, 4)