+7








4d51588e23
Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai> Signed-off-by: Woosuk Kwon <woosuk@inferact.ai> Signed-off-by: qizixi <zixi@inferact.ai> Signed-off-by: Jee Jee Li <pandaleefree@gmail.com> Signed-off-by: Yongye Zhu <zyy1102000@gmail.com> Co-authored-by: Yongye Zhu <zyy1102000@gmail.com> Co-authored-by: Yongye Zhu <yongye@inferact.ai> Co-authored-by: Simon Mo <simon@inferact.ai> Co-authored-by: Bugen Zhao <i@bugenzhao.com> Co-authored-by: Giancarlo Delfin <gdelfin@inferact.ai> Co-authored-by: Jee Jee Li <pandaleefree@gmail.com> Co-authored-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: Roger Wang <hey@rogerw.io> Co-authored-by: Roy Wang <yasong.wang@inferact.ai> Co-authored-by: Woosuk Kwon <woosuk@inferact.ai> Co-authored-by: youkaichao <youkaichao@gmail.com> Co-authored-by: Zhewen Li <jerven.vllm@gmail.com> Co-authored-by: Zijing Liu <liuzijing2014@gmail.com> Co-authored-by: khluu <khluu000@gmail.com> Co-authored-by: qizixi <zixi@inferact.ai> Co-authored-by: Zhewen Li <zhewenli@inferact.ai>
91 lines
2.8 KiB
Python
91 lines
2.8 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
from vllm.config import VllmConfig
|
|
from vllm.entrypoints.chat_utils import (
|
|
ChatCompletionMessageParam,
|
|
ConversationMessage,
|
|
parse_chat_messages,
|
|
parse_chat_messages_async,
|
|
)
|
|
from vllm.logger import init_logger
|
|
from vllm.tokenizers.deepseek_v4 import DeepseekV4Tokenizer
|
|
from vllm.utils.async_utils import make_async
|
|
|
|
from .base import BaseRenderer
|
|
from .inputs import DictPrompt
|
|
from .inputs.preprocess import parse_dec_only_prompt
|
|
from .params import ChatParams
|
|
|
|
logger = init_logger(__name__)
|
|
|
|
|
|
class DeepseekV4Renderer(BaseRenderer[DeepseekV4Tokenizer]):
|
|
def __init__(
|
|
self,
|
|
config: VllmConfig,
|
|
tokenizer: DeepseekV4Tokenizer | None,
|
|
) -> None:
|
|
super().__init__(config, tokenizer)
|
|
|
|
self._apply_chat_template_async = make_async(
|
|
self._apply_chat_template, executor=self._executor
|
|
)
|
|
|
|
def _apply_chat_template(self, *args, **kwargs):
|
|
return self.get_tokenizer().apply_chat_template(*args, **kwargs)
|
|
|
|
def render_messages(
|
|
self,
|
|
messages: list[ChatCompletionMessageParam],
|
|
params: ChatParams,
|
|
) -> tuple[list[ConversationMessage], DictPrompt]:
|
|
conversation, mm_data, mm_uuids = parse_chat_messages(
|
|
messages,
|
|
self.model_config,
|
|
content_format="string",
|
|
media_io_kwargs=params.media_io_kwargs,
|
|
mm_processor_kwargs=params.mm_processor_kwargs,
|
|
)
|
|
|
|
prompt_raw = self._apply_chat_template(
|
|
conversation=conversation,
|
|
messages=messages,
|
|
**params.get_apply_chat_template_kwargs(),
|
|
)
|
|
|
|
prompt = parse_dec_only_prompt(prompt_raw)
|
|
if mm_data is not None:
|
|
prompt["multi_modal_data"] = mm_data
|
|
if mm_uuids is not None:
|
|
prompt["multi_modal_uuids"] = mm_uuids
|
|
|
|
return conversation, prompt
|
|
|
|
async def render_messages_async(
|
|
self,
|
|
messages: list[ChatCompletionMessageParam],
|
|
params: ChatParams,
|
|
) -> tuple[list[ConversationMessage], DictPrompt]:
|
|
conversation, mm_data, mm_uuids = await parse_chat_messages_async(
|
|
messages,
|
|
self.model_config,
|
|
content_format="string",
|
|
media_io_kwargs=params.media_io_kwargs,
|
|
mm_processor_kwargs=params.mm_processor_kwargs,
|
|
)
|
|
|
|
prompt_raw = await self._apply_chat_template_async(
|
|
conversation=conversation,
|
|
messages=messages,
|
|
**params.get_apply_chat_template_kwargs(),
|
|
)
|
|
|
|
prompt = parse_dec_only_prompt(prompt_raw)
|
|
if mm_data is not None:
|
|
prompt["multi_modal_data"] = mm_data
|
|
if mm_uuids is not None:
|
|
prompt["multi_modal_uuids"] = mm_uuids
|
|
|
|
return conversation, prompt
|