Deprecate Transformers v4 support (#45161)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2026-06-11 11:04:01 +08:00
committed by GitHub
parent b038a2f73b
commit 18d87a87dc
19 changed files with 61 additions and 267 deletions
@@ -3,6 +3,7 @@
# adapted from https://github.com/deepseek-ai/DeepSeek-VL2/blob/faf18023f24b962b32d9f0a2d89e402a8d383a78/deepseek_vl2/models/modeling_deepseek_vl_v2.py#L115-L268
from huggingface_hub.dataclasses import strict
from transformers import DeepseekV2Config, PretrainedConfig
@@ -87,16 +88,9 @@ class MlpProjectorConfig(PretrainedConfig):
super().__init__(**kwargs)
if hasattr(DeepseekV2Config, "validate"):
# Transformers v5
from huggingface_hub.dataclasses import strict
@strict
class DeepseekVLV2TextConfig(DeepseekV2Config):
kv_lora_rank: int | None = None
else:
# Transformers v4
DeepseekVLV2TextConfig = DeepseekV2Config # type: ignore[misc]
@strict
class DeepseekVLV2TextConfig(DeepseekV2Config):
kv_lora_rank: int | None = None
class DeepseekVLV2Config(PretrainedConfig):
@@ -228,15 +228,8 @@ class OlmoHybridConfig(PretrainedConfig):
if "full_attention" not in layer_types:
layer_types[-1] = "full_attention"
if hasattr(self, "validate_layer_type"):
# Transformers v5
self.layer_types = layer_types
self.validate_layer_type()
else:
# Transformers v4
from transformers.configuration_utils import layer_type_validation
layer_type_validation(layer_types, num_hidden_layers)
self.layer_types = layer_types
self.validate_layer_type()
if "linear_attention" not in layer_types:
raise ValueError(
"OLMoHybrid expects at least one 'linear_attention' layer."
+5 -12
View File
@@ -94,18 +94,11 @@ class Qwen3_5TextConfig(PretrainedConfig):
else "full_attention"
for i in range(self.num_hidden_layers)
]
if hasattr(self, "validate_layer_type"):
# Transformers v5
kwargs["ignore_keys_at_rope_validation"] = {
"mrope_section",
"mrope_interleaved",
}
self.validate_layer_type()
else:
# Transformers v4
from transformers.configuration_utils import layer_type_validation
layer_type_validation(self.layer_types, self.num_hidden_layers)
kwargs["ignore_keys_at_rope_validation"] = {
"mrope_section",
"mrope_interleaved",
}
self.validate_layer_type()
# linear attention part
self.linear_conv_kernel_dim = linear_conv_kernel_dim
+5 -12
View File
@@ -100,18 +100,11 @@ class Qwen3_5MoeTextConfig(PretrainedConfig):
else "full_attention"
for i in range(self.num_hidden_layers)
]
if hasattr(self, "validate_layer_type"):
# Transformers v5
kwargs["ignore_keys_at_rope_validation"] = {
"mrope_section",
"mrope_interleaved",
}
self.validate_layer_type()
else:
# Transformers v4
from transformers.configuration_utils import layer_type_validation
layer_type_validation(self.layer_types, self.num_hidden_layers)
kwargs["ignore_keys_at_rope_validation"] = {
"mrope_section",
"mrope_interleaved",
}
self.validate_layer_type()
# linear attention part
self.linear_conv_kernel_dim = linear_conv_kernel_dim
@@ -252,14 +252,7 @@ class Qwen3NextConfig(PretrainedConfig):
"linear_attention" if bool((i + 1) % 4) else "full_attention"
for i in range(self.num_hidden_layers)
]
if hasattr(self, "validate_layer_type"):
# Transformers v5
self.validate_layer_type()
else:
# Transformers v4
from transformers.configuration_utils import layer_type_validation
layer_type_validation(self.layer_types)
self.validate_layer_type()
# linear attention part
self.linear_conv_kernel_dim = linear_conv_kernel_dim
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import os
from dataclasses import fields, is_dataclass
from dataclasses import fields
from typing import Any
from transformers import PretrainedConfig
@@ -16,11 +16,8 @@ class SpeculatorsConfig(PretrainedConfig):
model_type = "speculators"
def __init__(self, **kwargs):
# Transformers v4 - super().__init__ which sets all kwargs as attributes
if not is_dataclass(PretrainedConfig):
return super().__init__(**kwargs)
# Transformers v5 - super().__init__ performs some validation before
# setting all kwargs as attributes, so we set them first to be safe
# super().__init__ performs some validation before setting all kwargs as
# attributes, so we set them first to be safe
pre_trained_config_fields = {f.name for f in fields(PretrainedConfig)}
super_kwargs = dict()
for key, value in kwargs.items():