[Chore] Use upstream Transformers DeepseekV4Config (#61392)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Kevin H. Luu <khluu000@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Kevin H. Luu
parent
1c4c319792
commit
b965ee564d
@@ -127,7 +127,6 @@ _CONFIG_REGISTRY: dict[str, type[PreTrainedConfig]] = LazyConfigDict(
|
||||
cosmos3_edge="Cosmos3EdgeConfig",
|
||||
deepseek_vl_v2="DeepseekVLV2Config",
|
||||
deepseek_v32="DeepseekV3Config",
|
||||
deepseek_v4="DeepseekV4Config",
|
||||
dots3_note="Dots3NoteConfig",
|
||||
k3_dspark="K3DSparkConfig",
|
||||
funaudiochat="FunAudioChatConfig",
|
||||
@@ -216,7 +215,10 @@ def is_rope_parameters_nested(rope_parameters: dict[str, Any]) -> bool:
|
||||
# Cannot be nested if rope_parameters is empty
|
||||
if not rope_parameters:
|
||||
return False
|
||||
return set(rope_parameters.keys()).issubset(ALLOWED_LAYER_TYPES)
|
||||
# DeepSeek-V4 nests by rope type ("main", "compress") instead
|
||||
return set(rope_parameters.keys()).issubset(
|
||||
{*ALLOWED_LAYER_TYPES, "main", "compress"}
|
||||
)
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
@@ -29,7 +29,6 @@ _CLASS_TO_MODULE: dict[str, str] = {
|
||||
"Cosmos3EdgeTextConfig": "vllm.transformers_utils.configs.cosmos3_edge",
|
||||
"Cosmos3EdgeVisionConfig": "vllm.transformers_utils.configs.cosmos3_edge",
|
||||
"DeepseekVLV2Config": "vllm.transformers_utils.configs.deepseek_vl2",
|
||||
"DeepseekV4Config": "vllm.transformers_utils.configs.deepseek_v4",
|
||||
"DeepseekV41Config": "vllm.transformers_utils.configs.deepseek_v41",
|
||||
"Dots3NoteConfig": "vllm.transformers_utils.configs.dots3_note",
|
||||
"K3DSparkConfig": "vllm.transformers_utils.configs.k3_dspark",
|
||||
@@ -103,7 +102,6 @@ __all__ = [
|
||||
"Cosmos3EdgeVisionConfig",
|
||||
"DeepseekVLV2Config",
|
||||
"DeepseekV3Config",
|
||||
"DeepseekV4Config",
|
||||
"Dots3NoteConfig",
|
||||
"K3DSparkConfig",
|
||||
"DotsOCRConfig",
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import Any
|
||||
|
||||
from transformers import PreTrainedConfig
|
||||
|
||||
|
||||
class DeepseekV4Config(PreTrainedConfig):
|
||||
model_type = "deepseek_v4"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
max_position_embeddings: int = 1048576,
|
||||
rope_scaling: dict[str, Any] | None = None,
|
||||
rope_parameters: dict[str, Any] | None = None,
|
||||
rope_theta: float = 10000.0,
|
||||
vision_n_layers: int = 0,
|
||||
vision_dim: int = 1024,
|
||||
vision_n_heads: int = 16,
|
||||
vision_inter_dim: int = 2816,
|
||||
vision_patch_size: int = 14,
|
||||
vision_rope_theta: float = 10000.0,
|
||||
vision_downsample_ratio: int = 3,
|
||||
vision_max_n_token: int = 384,
|
||||
vision_min_pixels: int = 147456,
|
||||
vision_max_wh_ratio: float = 8,
|
||||
**kwargs,
|
||||
):
|
||||
self.max_position_embeddings = max_position_embeddings
|
||||
self.rope_scaling = rope_scaling
|
||||
self.rope_theta = rope_theta
|
||||
self.rope_parameters = rope_scaling or rope_parameters
|
||||
# Vision tower config; vision_n_layers == 0 means text-only.
|
||||
self.vision_n_layers = vision_n_layers
|
||||
self.vision_dim = vision_dim
|
||||
self.vision_n_heads = vision_n_heads
|
||||
self.vision_inter_dim = vision_inter_dim
|
||||
self.vision_patch_size = vision_patch_size
|
||||
self.vision_rope_theta = vision_rope_theta
|
||||
self.vision_downsample_ratio = vision_downsample_ratio
|
||||
self.vision_max_n_token = vision_max_n_token
|
||||
self.vision_min_pixels = vision_min_pixels
|
||||
self.vision_max_wh_ratio = vision_max_wh_ratio
|
||||
# The sparse-SWA index kernels widen the window within image spans
|
||||
# in-kernel, so mm-prefix ranges longer than sliding_window must be
|
||||
# kept (they are only consumed by those kernels).
|
||||
self.mm_prefix_clamp_sliding_window = vision_n_layers > 0
|
||||
# The visibility span covers the sentinel block [IMAGE_START,
|
||||
# IMAGE_END]; the mm placeholder additionally carries a leading
|
||||
# compressor-alignment pad (see mm_preprocess.COMPRESS_PAD_TO).
|
||||
self.mm_prefix_span_leading_pad_modulus = 4 if vision_n_layers > 0 else 0
|
||||
super().__init__(**kwargs)
|
||||
@@ -0,0 +1,18 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import Any
|
||||
|
||||
|
||||
def get_compress_ratios(config: Any) -> list[int]:
|
||||
"""Per-layer compress ratios (0 = sliding window), MTP layers included.
|
||||
|
||||
Reads the legacy `compress_ratios` of DeepSeek-V4.1 configs, or derives it
|
||||
from `layer_types` of the upstream `DeepseekV4Config`, which drops the MTP
|
||||
layers. Returns an empty list for other configs.
|
||||
"""
|
||||
if (compress_ratios := getattr(config, "compress_ratios", None)) is not None:
|
||||
return compress_ratios
|
||||
if (compress_rates := getattr(config, "compress_rates", None)) is None:
|
||||
return []
|
||||
ratios = [compress_rates.get(t, 0) for t in config.layer_types]
|
||||
return ratios + [0] * config.num_nextn_predict_layers
|
||||
@@ -18,6 +18,7 @@ from vllm.transformers_utils.config import (
|
||||
ConfigFormat,
|
||||
get_safetensors_params_metadata,
|
||||
)
|
||||
from vllm.transformers_utils.deepseek_v4_utils import get_compress_ratios
|
||||
from vllm.transformers_utils.repo_utils import (
|
||||
file_or_path_exists,
|
||||
get_hf_file_to_dict,
|
||||
@@ -90,7 +91,7 @@ class ModelArchConfigConvertorBase:
|
||||
def get_head_size(self) -> int:
|
||||
if self.is_deepseek_mla():
|
||||
# special case for deepseek_v4
|
||||
if hasattr(self.hf_text_config, "compress_ratios"):
|
||||
if get_compress_ratios(self.hf_text_config):
|
||||
return self.hf_text_config.head_dim
|
||||
qk_rope_head_dim = self._get_qk_rope_head_dim()
|
||||
if not envs.VLLM_MLA_DISABLE:
|
||||
@@ -318,7 +319,7 @@ class ModelArchConfigConvertorBase:
|
||||
"hy_v4_mtp",
|
||||
):
|
||||
# check is deepseek_v4 model
|
||||
if hasattr(self.hf_text_config, "compress_ratios"):
|
||||
if get_compress_ratios(self.hf_text_config):
|
||||
return getattr(self.hf_text_config, "head_dim", None) is not None
|
||||
else:
|
||||
return getattr(self.hf_text_config, "kv_lora_rank", None) is not None
|
||||
|
||||
Reference in New Issue
Block a user