Optimize detokenization without HF decode kwargs (#25309)
This commit is contained in:
@@ -44,6 +44,7 @@ from sglang.srt.utils import (
|
||||
)
|
||||
from sglang.srt.utils.hf_transformers_utils import get_tokenizer
|
||||
from sglang.srt.utils.network import get_zmq_socket
|
||||
from sglang.srt.utils.patch_tokenizer import decode_without_hf_kwargs
|
||||
from sglang.srt.utils.watchdog import Watchdog
|
||||
from sglang.utils import (
|
||||
TypeBasedDispatcher,
|
||||
@@ -190,6 +191,12 @@ class DetokenizerManager(MultiHttpWorkerDetokenizerMixin):
|
||||
) -> List[str]:
|
||||
"""Batch decode with grouping by (skip_special_tokens, spaces_between_special_tokens)."""
|
||||
|
||||
if not getattr(self.tokenizer, "is_fast", False):
|
||||
return [
|
||||
decode_without_hf_kwargs(self.tokenizer, ids, skip)
|
||||
for ids, skip in zip(ids_list, skip_list)
|
||||
]
|
||||
|
||||
# fast path
|
||||
first_skip, first_space = skip_list[0], space_list[0]
|
||||
if all(
|
||||
|
||||
@@ -29,6 +29,15 @@ def _is_kimi_tiktoken_tokenizer(tokenizer):
|
||||
return class_name == "TikTokenTokenizer" and "tokenization_kimi" in module_name
|
||||
|
||||
|
||||
def decode_without_hf_kwargs(tokenizer, token_ids, skip_special_tokens):
|
||||
if skip_special_tokens:
|
||||
special_ids = getattr(tokenizer, "all_special_ids_set", None)
|
||||
if special_ids is None:
|
||||
special_ids = set(tokenizer.all_special_ids)
|
||||
token_ids = [tid for tid in token_ids if tid not in special_ids]
|
||||
return tokenizer.decode(token_ids)
|
||||
|
||||
|
||||
class _SpecialTokensCachePatcher:
|
||||
_PATCHED_FLAG = "_sglang_special_tokens_patched"
|
||||
_CACHED_TOKENS_ATTR = "_sglang_cached_special_tokens"
|
||||
|
||||
Reference in New Issue
Block a user