[Refactor] Remove deepseek dead code (#48780)

Signed-off-by: yewentao256 <zhyanwentao@126.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

Wentao Ye committed Jul 17, 2026 at 10:57 UTC 877dae9c684cd8cb2f66eed33f1c3261c6792c10
7 files changed +3 -387
vllm/model_executor/models/deepseek_eagle3.py
-3
@@ -12,7 +12,6 @@ from transformers import DeepseekV2Config, DeepseekV3Config
12
13 from vllm.compilation.decorators import support_torch_compile
14 from vllm.config import VllmConfig, get_current_vllm_config
15 -from vllm.logger import init_logger
15 from vllm.model_executor.layers.layernorm import RMSNorm
16 from vllm.model_executor.layers.linear import ReplicatedLinear
17 from vllm.model_executor.layers.logits_processor import LogitsProcessor
@@ -36,8 +35,6 @@ from .utils import (
35 process_eagle_weight,
36 )
37
39 -logger = init_logger(__name__)
40 -
38
39 class DeepseekV2Eagle3DecoderLayer(nn.Module):
40 """
vllm/model_executor/models/deepseek_mtp.py
-3
@@ -11,7 +11,6 @@ from vllm._aiter_ops import rocm_aiter_ops
11 from vllm.compilation.decorators import support_torch_compile
12 from vllm.config import VllmConfig
13 from vllm.distributed import tensor_model_parallel_all_gather
14 -from vllm.logger import init_logger
14 from vllm.model_executor.layers.fused_moe import (
15 fused_moe_make_expert_params_mapping,
16 )
@@ -38,8 +37,6 @@ from .deepseek_v2 import (
37 )
38 from .utils import get_pp_missing_layer_names, maybe_prefix
39
41 -logger = init_logger(__name__)
42 -
40
41 def _restore_full_token_layout_if_needed(
42 hidden_states: torch.Tensor,
vllm/model_executor/warmup/deepseek_v4_mhc_warmup.py
-18
@@ -15,7 +15,6 @@ import torch
15
16 from vllm.logger import init_logger
17 from vllm.tracing import instrument
18 -from vllm.utils.math_utils import cdiv
18
19 logger = init_logger(__name__)
20
@@ -39,23 +38,6 @@ _DEFAULT_TOKEN_SIZE_CANDIDATES = (
38 )
39
40
42 -def _compute_mhc_pre_num_split(
43 - *,
44 - num_tokens: int,
45 - hidden_size: int,
46 - hc_mult: int,
47 - num_sms: int,
48 -) -> int:
49 - block_k = 64
50 - block_m = 64
51 - k = hc_mult * hidden_size
52 - grid_size = cdiv(num_tokens, block_m)
53 - split_k = num_sms // grid_size
54 - num_block_k = cdiv(k, block_k)
55 - split_k = min(split_k, num_block_k // 4)
56 - return max(split_k, 1)
57 -
58 -
41 def _normalize_token_sizes(
42 token_sizes: Iterable[int],
43 *,
vllm/renderers/deepseek_v32.py
-3
@@ -8,7 +8,6 @@ from vllm.entrypoints.chat_utils import (
8 parse_chat_messages,
9 parse_chat_messages_async,
10 )
11 -from vllm.logger import init_logger
11 from vllm.tokenizers.deepseek_v32 import DeepseekV32Tokenizer
12 from vllm.utils.async_utils import make_async
13
@@ -17,8 +16,6 @@ from .inputs import DictPrompt
16 from .inputs.preprocess import parse_dec_only_prompt
17 from .params import ChatParams
18
20 -logger = init_logger(__name__)
21 -
19
20 class DeepseekV32Renderer(BaseRenderer[DeepseekV32Tokenizer]):
21 def __init__(
vllm/renderers/deepseek_v4.py
-3
@@ -8,7 +8,6 @@ from vllm.entrypoints.chat_utils import (
8 parse_chat_messages,
9 parse_chat_messages_async,
10 )
11 -from vllm.logger import init_logger
11 from vllm.tokenizers.deepseek_v4 import DeepseekV4Tokenizer
12 from vllm.utils.async_utils import make_async
13
@@ -17,8 +16,6 @@ from .inputs import DictPrompt
16 from .inputs.preprocess import parse_dec_only_prompt
17 from .params import ChatParams
18
20 -logger = init_logger(__name__)
21 -
19
20 class DeepseekV4Renderer(BaseRenderer[DeepseekV4Tokenizer]):
21 def __init__(
vllm/tokenizers/deepseek_v32_encoding.py
-169
@@ -7,8 +7,6 @@ import copy
7 import json
8 from typing import Any
9
10 -import regex as re
11 -
10 # flake8: noqa: E501
11 TOOLS_SYSTEM_TEMPLATE = """## Tools
12 You have access to a set of tools you can use to answer the user's question.
@@ -79,19 +77,6 @@ def tool_calls_from_openai_format(tool_calls):
77 ]
78
79
82 -def tool_calls_to_openai_format(tool_calls):
83 - return [
84 - {
85 - "type": "function",
86 - "function": {
87 - "name": tool_call["name"],
88 - "arguments": tool_call["arguments"],
89 - },
90 - }
91 - for tool_call in tool_calls
92 - ]
93 -
94 -
80 def encode_arguments_to_dsml(tool_call: dict[str, str]) -> str:
81 p_dsml_template = """<{dsml_token}parameter name="{key}" string="{is_str}">{value}</{dsml_token}parameter>"""
82 P_dsml_strs = []
@@ -113,24 +98,6 @@ def encode_arguments_to_dsml(tool_call: dict[str, str]) -> str:
98 return "\n".join(P_dsml_strs)
99
100
116 -def decode_dsml_to_arguments(
117 - tool_name: str, tool_args: dict[str, tuple[str, str]]
118 -) -> dict[str, str]:
119 - def _decode_value(key: str, value: str, string: str):
120 - if string == "true":
121 - value = to_json(value)
122 - return f"{to_json(key)}: {value}"
123 -
124 - tool_args_json = (
125 - "{"
126 - + ", ".join(
127 - [_decode_value(k, v, string=is_str) for k, (v, is_str) in tool_args.items()]
128 - )
129 - + "}"
130 - )
131 - return dict(name=tool_name, arguments=tool_args_json)
132 -
133 -
101 def render_tools(tools: list[dict[str, str | dict[str, Any]]]) -> str:
102 tools_json = [to_json(t) for t in tools]
103
@@ -333,139 +300,3 @@ def encode_messages(
300 )
301
302 return prompt
336 -
337 -
338 -def _read_until_stop(
339 - index: int, text: str, stop: list[str]
340 -) -> tuple[int, str, None | str]:
341 - min_pos = len(text)
342 - matched_stop = None
343 -
344 - for s in stop:
345 - pos = text.find(s, index)
346 - if pos != -1 and pos < min_pos:
347 - min_pos = pos
348 - matched_stop = s
349 -
350 - if matched_stop:
351 - content = text[index:min_pos]
352 - return min_pos + len(matched_stop), content, matched_stop
353 - else:
354 - content = text[index:]
355 - return len(text), content, None
356 -
357 -
358 -def parse_tool_calls(index: int, text: str):
359 - tool_calls: list[dict[str, Any]] = []
360 - stop_token = None
361 - tool_calls_end_token = f"</{dsml_token}function_calls>"
362 -
363 - while index < len(text):
364 - index, _, stop_token = _read_until_stop(
365 - index, text, [f"<{dsml_token}invoke", tool_calls_end_token]
366 - )
367 - if _ != ">\n":
368 - raise RuntimeError("Tool call format error")
369 -
370 - if stop_token == tool_calls_end_token:
371 - break
372 -
373 - if stop_token is None:
374 - raise RuntimeError("Missing special token")
375 -
376 - index, tool_name_content, stop_token = _read_until_stop(
377 - index, text, [f"<{dsml_token}parameter", f"</{dsml_token}invoke"]
378 - )
379 -
380 - p_tool_name = re.findall(
381 - r'^\s*name="(.*?)">\n$', tool_name_content, flags=re.DOTALL
382 - )
383 - if len(p_tool_name) != 1:
384 - raise RuntimeError("Tool name format error")
385 - tool_name = p_tool_name[0]
386 -
387 - tool_args: dict[str, tuple[str, str]] = {}
388 - while stop_token == f"<{dsml_token}parameter":
389 - index, param_content, stop_token = _read_until_stop(
390 - index, text, [f"/{dsml_token}parameter"]
391 - )
392 -
393 - param_kv = re.findall(
394 - r'^ name="(.*?)" string="(true|false)">(.*?)<$',
395 - param_content,
396 - flags=re.DOTALL,
397 - )
398 - if len(param_kv) != 1:
399 - raise RuntimeError("Parameter format error")
400 - param_name, string, param_value = param_kv[0]
401 -
402 - if param_name in tool_args:
403 - raise RuntimeError("Duplicate parameter name")
404 - tool_args[param_name] = (param_value, string)
405 -
406 - index, content, stop_token = _read_until_stop(
407 - index, text, [f"<{dsml_token}parameter", f"</{dsml_token}invoke"]
408 - )
409 - if content != ">\n":
410 - raise RuntimeError("Parameter format error")
411 -
412 - tool_call = decode_dsml_to_arguments(tool_name=tool_name, tool_args=tool_args)
413 - tool_calls.append(tool_call)
414 -
415 - return index, stop_token, tool_calls
416 -
417 -
418 -# NOTE: This function is designed to parse only correctly
419 -# formatted string and will not attempt to correct malformed output
420 -# that may be generated by the model.
421 -def parse_message_from_completion_text(text: str, thinking_mode: str):
422 - summary_content, reasoning, tool_calls = "", "", []
423 - index, stop_token = 0, None
424 - tool_calls_start_token = f"\n\n<{dsml_token}function_calls"
425 -
426 - is_thinking, is_tool_calling = thinking_mode == "thinking", False
427 -
428 - if is_thinking:
429 - index, content_delta, stop_token = _read_until_stop(
430 - index, text, [thinking_end_token, tool_calls_start_token]
431 - )
432 - reasoning = content_delta
433 - if stop_token != thinking_end_token:
434 - raise RuntimeError("Invalid thinking format")
435 -
436 - index, content_delta, stop_token = _read_until_stop(
437 - index, text, [eos_token, tool_calls_start_token]
438 - )
439 - summary_content = content_delta
440 - if stop_token == tool_calls_start_token:
441 - is_tool_calling = True
442 - else:
443 - if stop_token != eos_token:
444 - raise RuntimeError("Invalid summary format")
445 -
446 - if is_tool_calling:
447 - index, stop_token, tool_calls = parse_tool_calls(index, text)
448 -
449 - index, tool_ends_text, stop_token = _read_until_stop(index, text, [eos_token])
450 - if tool_ends_text:
451 - raise RuntimeError("Unexpected content after tool calls")
452 -
453 - if not (len(text) == index and stop_token in [eos_token, None]):
454 - raise RuntimeError("Unexpected content at end")
455 -
456 - for sp_token in [
457 - bos_token,
458 - eos_token,
459 - thinking_start_token,
460 - thinking_end_token,
461 - dsml_token,
462 - ]:
463 - if sp_token in summary_content or sp_token in reasoning:
464 - raise RuntimeError("Unexpected special token in content")
465 -
466 - return {
467 - "role": "assistant",
468 - "content": summary_content,
469 - "reasoning": reasoning,
470 - "tool_calls": tool_calls_to_openai_format(tool_calls),
471 - }
vllm/tokenizers/deepseek_v4_encoding.py
+3 -188
@@ -6,16 +6,14 @@
6 """
7 DeepSeek-V4 Encoding
8
9 -A self-contained implementation for encoding/decoding DeepSeek-V4 chat messages
10 -with tool calling, thinking mode, and quick instruction task support.
9 +A self-contained implementation for encoding DeepSeek-V4 chat messages with tool
10 +calling, thinking mode, and quick instruction task support.
11 """
12
13 -from typing import Any, Dict, List, Union, Optional, Tuple
13 +from typing import Any, Dict, List, Union, Optional
14 import copy
15 import json
16
17 -import regex as re
18 -
17 # ============================================================
18 # Special Tokens
19 # ============================================================
@@ -128,20 +126,6 @@ def tool_calls_from_openai_format(tool_calls):
126 ]
127
128
131 -def tool_calls_to_openai_format(tool_calls):
132 - """Convert internal tool calls to OpenAI format."""
133 - return [
134 - {
135 - "type": "function",
136 - "function": {
137 - "name": tool_call["name"],
138 - "arguments": tool_call["arguments"],
139 - }
140 - }
141 - for tool_call in tool_calls
142 - ]
143 -
144 -
129 def encode_arguments_to_dsml(tool_call: Dict[str, Any]) -> str:
130 """
131 Encode tool call arguments into DSML parameter format.
@@ -172,26 +156,6 @@ def encode_arguments_to_dsml(tool_call: Dict[str, Any]) -> str:
156 return "\n".join(P_dsml_strs)
157
158
175 -def decode_dsml_to_arguments(tool_name: str, tool_args: Dict[str, Tuple[str, str]]) -> Dict[str, str]:
176 - """
177 - Decode DSML parameters back to a tool call dict.
178 -
179 - Args:
180 - tool_name: Name of the tool.
181 - tool_args: Dict mapping param_name -> (value, is_string_flag).
182 -
183 - Returns:
184 - Dict with "name" and "arguments" (JSON string) keys.
185 - """
186 - def _decode_value(key: str, value: str, string: str):
187 - if string == "true":
188 - value = to_json(value)
189 - return f"{to_json(key)}: {value}"
190 -
191 - tool_args_json = "{" + ", ".join([_decode_value(k, v, string=is_str) for k, (v, is_str) in tool_args.items()]) + "}"
192 - return dict(name=tool_name, arguments=tool_args_json)
193 -
194 -
159 def render_tools(tools: List[Dict[str, Union[str, Dict[str, Any]]]]) -> str:
160 """
161 Render tool schemas into the system prompt format.
@@ -605,153 +569,4 @@ def _drop_thinking_messages(messages: List[Dict[str, Any]]) -> List[Dict[str, An
569 return result
570
571
608 -# ============================================================
609 -# Parsing (Decoding model output)
610 -# ============================================================
611 -
612 -def _read_until_stop(index: int, text: str, stop: List[str]) -> Tuple[int, str, Optional[str]]:
613 - """
614 - Read text from index until one of the stop strings is found.
615 -
616 - Returns:
617 - Tuple of (new_index, content_before_stop, matched_stop_string_or_None).
618 - """
619 - min_pos = len(text)
620 - matched_stop = None
621 -
622 - for s in stop:
623 - pos = text.find(s, index)
624 - if pos != -1 and pos < min_pos:
625 - min_pos = pos
626 - matched_stop = s
627 -
628 - if matched_stop:
629 - content = text[index:min_pos]
630 - return min_pos + len(matched_stop), content, matched_stop
631 - else:
632 - content = text[index:]
633 - return len(text), content, None
634 -
635 -
636 -def parse_tool_calls(index: int, text: str) -> Tuple[int, Optional[str], List[Dict[str, str]]]:
637 - """
638 - Parse DSML tool calls from text starting at the given index.
639 -
640 - Args:
641 - index: Starting position in text.
642 - text: The full text to parse.
643 -
644 - Returns:
645 - Tuple of (new_index, last_stop_token, list_of_tool_call_dicts).
646 - Each tool call dict has "name" and "arguments" keys.
647 - """
648 - tool_calls: List[Dict[str, Any]] = []
649 - stop_token = None
650 - tool_calls_end_token = f"</{dsml_token}{tool_calls_block_name}>"
651 -
652 - while index < len(text):
653 - index, content_before, stop_token = _read_until_stop(index, text, [f"<{dsml_token}invoke", tool_calls_end_token])
654 - if content_before != ">\n":
655 - raise ValueError(f"Tool call format error: expected '>\\n' but got '{content_before}'")
656 -
657 - if stop_token == tool_calls_end_token:
658 - break
659 -
660 - if stop_token is None:
661 - raise ValueError("Missing special token in tool calls")
662 -
663 - index, tool_name_content, stop_token = _read_until_stop(index, text, [f"<{dsml_token}parameter", f"</{dsml_token}invoke"])
664 -
665 - p_tool_name = re.findall(r'^\s*name="(.*?)">\n$', tool_name_content, flags=re.DOTALL)
666 - if len(p_tool_name) != 1:
667 - raise ValueError(f"Tool name format error: '{tool_name_content}'")
668 - tool_name = p_tool_name[0]
669 -
670 - tool_args: Dict[str, Tuple[str, str]] = {}
671 - while stop_token == f"<{dsml_token}parameter":
672 - index, param_content, stop_token = _read_until_stop(index, text, [f"/{dsml_token}parameter"])
673 -
674 - param_kv = re.findall(r'^ name="(.*?)" string="(true|false)">(.*?)<$', param_content, flags=re.DOTALL)
675 - if len(param_kv) != 1:
676 - raise ValueError(f"Parameter format error: '{param_content}'")
677 - param_name, string, param_value = param_kv[0]
678 -
679 - if param_name in tool_args:
680 - raise ValueError(f"Duplicate parameter name: '{param_name}'")
681 - tool_args[param_name] = (param_value, string)
682 -
683 - index, content, stop_token = _read_until_stop(index, text, [f"<{dsml_token}parameter", f"</{dsml_token}invoke"])
684 - if content != ">\n":
685 - raise ValueError(f"Parameter format error: expected '>\\n' but got '{content}'")
686 -
687 - tool_call = decode_dsml_to_arguments(tool_name=tool_name, tool_args=tool_args)
688 - tool_calls.append(tool_call)
689 -
690 - return index, stop_token, tool_calls
691 -
692 -
693 -def parse_message_from_completion_text(text: str, thinking_mode: str) -> Dict[str, Any]:
694 - """
695 - Parse a model completion text into a structured assistant message.
696 -
697 - This function takes the raw text output from the model (a single assistant turn)
698 - and extracts:
699 - - reasoning (thinking block)
700 - - content (summary/response)
701 - - tool_calls (if any)
702 -
703 - NOTE: This function is designed to parse only correctly formatted strings and
704 - will raise ValueError for malformed output.
705 -
706 - Args:
707 - text: The raw completion text (including EOS token).
708 - thinking_mode: Either "chat" or "thinking".
709 -
710 - Returns:
711 - Dict with keys: "role", "content", "reasoning", "tool_calls".
712 - tool_calls are in OpenAI format.
713 - """
714 - summary_content, reasoning = "", ""
715 - tool_calls: List[Dict[str, str]] = []
716 - index, stop_token = 0, None
717 - tool_calls_start_token = f"\n\n<{dsml_token}{tool_calls_block_name}"
718 -
719 - is_thinking = thinking_mode == "thinking"
720 - is_tool_calling = False
721 -
722 - if is_thinking:
723 - index, content_delta, stop_token = _read_until_stop(index, text, [thinking_end_token, tool_calls_start_token])
724 - reasoning = content_delta
725 - if stop_token != thinking_end_token:
726 - raise ValueError("Invalid thinking format: missing </think>")
727 -
728 - index, content_delta, stop_token = _read_until_stop(index, text, [eos_token, tool_calls_start_token])
729 - summary_content = content_delta
730 - if stop_token == tool_calls_start_token:
731 - is_tool_calling = True
732 - else:
733 - if stop_token != eos_token:
734 - raise ValueError("Invalid format: missing EOS token")
735 -
736 - if is_tool_calling:
737 - index, stop_token, tool_calls = parse_tool_calls(index, text)
738 -
739 - index, tool_ends_text, stop_token = _read_until_stop(index, text, [eos_token])
740 - if tool_ends_text:
741 - raise ValueError("Unexpected content after tool calls")
742 -
743 - if len(text) != index or stop_token not in [eos_token, None]:
744 - raise ValueError("Unexpected content at end")
745 -
746 - for sp_token in [bos_token, eos_token, thinking_start_token, thinking_end_token, dsml_token]:
747 - if sp_token in summary_content or sp_token in reasoning:
748 - raise ValueError(f"Unexpected special token '{sp_token}' in content")
749 -
750 - return {
751 - "role": "assistant",
752 - "content": summary_content,
753 - "reasoning": reasoning,
754 - "tool_calls": tool_calls_to_openai_format(tool_calls)
755 - }
756 -
572 # fmt: on