fix: fix the bug blocking completion template application (#17010)

Co-authored-by: xdtbynd <supercluster@vip.qq.com>
Co-authored-by: cy <chenyang08056032@163.com>
Co-authored-by: sglang-npu-bot <sglangnpu@163.com>
This commit is contained in:
xdtbynd
2026-02-24 18:50:08 +08:00
committed by GitHub
parent 6e54361608
commit 1a83b2c15d
4 changed files with 119 additions and 3 deletions

View File

@@ -30,6 +30,7 @@ from sglang.srt.parser.code_completion_parser import (
FimPosition,
completion_template_exists,
register_completion_template,
set_completion_template,
)
from sglang.srt.parser.conversation import (
Conversation,
@@ -199,6 +200,8 @@ class TemplateManager:
else:
self._completion_template_name = completion_template_arg
set_completion_template(self._completion_template_name)
def initialize_templates(
self,
tokenizer_manager: TokenizerManager,

View File

@@ -15,15 +15,16 @@
import dataclasses
import logging
from enum import auto
from enum import Enum, auto
from typing import Optional
from sglang.srt.entrypoints.openai.protocol import CompletionRequest
logger = logging.getLogger(__name__)
completion_template_name = None
completion_template_name: Optional[str] = None
class FimPosition:
class FimPosition(Enum):
"""Position of fim middle token."""
MIDDLE = auto()
@@ -68,6 +69,12 @@ def completion_template_exists(template_name: str) -> bool:
return template_name in completion_templates
def set_completion_template(template_name: str) -> None:
global completion_template_name
if completion_template_name is None:
completion_template_name = template_name
def is_completion_template_defined() -> bool:
global completion_template_name
return completion_template_name is not None