[CI] Bump Transformers version to 5.17.0 (#56108)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Claude Opus 5
parent
f8b5c11468
commit
ec4a3a5370
@@ -54,8 +54,19 @@ from vllm.sequence import IntermediateTensors
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def get_mlp_layer_types(config) -> list[str]:
|
||||
"""Return which layers are MoE, rejecting configs predating Transformers support."""
|
||||
mlp_layer_types = getattr(config, "mlp_layer_types", None)
|
||||
if mlp_layer_types is None:
|
||||
raise ValueError(
|
||||
"Laguna requires the `LagunaConfig` from Transformers, which is "
|
||||
"available from v5.17.0. Please update Transformers to run this model."
|
||||
)
|
||||
return mlp_layer_types
|
||||
|
||||
|
||||
class LagunaMLP(nn.Module):
|
||||
"""Dense MLP for Laguna (used in mlp_only_layers)."""
|
||||
"""Dense MLP for Laguna."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -206,7 +217,7 @@ class LagunaMoE(nn.Module):
|
||||
top_k=config.num_experts_per_tok,
|
||||
hidden_size=config.hidden_size,
|
||||
intermediate_size=config.moe_intermediate_size,
|
||||
renormalize=config.norm_topk_prob,
|
||||
renormalize=True,
|
||||
quant_config=quant_config,
|
||||
prefix=f"{prefix}.experts",
|
||||
scoring_func="sigmoid",
|
||||
@@ -293,13 +304,12 @@ class LagunaAttention(nn.Module):
|
||||
else:
|
||||
self.sliding_window = None
|
||||
|
||||
# QKV projection (no bias for Laguna)
|
||||
self.qkv_proj = QKVParallelLinear(
|
||||
self.hidden_size,
|
||||
self.head_dim,
|
||||
self.total_num_heads,
|
||||
self.total_num_kv_heads,
|
||||
bias=config.qkv_bias,
|
||||
bias=config.attention_bias,
|
||||
quant_config=quant_config,
|
||||
prefix=f"{prefix}.qkv_proj",
|
||||
)
|
||||
@@ -506,14 +516,9 @@ class LagunaDecoderLayer(nn.Module):
|
||||
),
|
||||
)
|
||||
|
||||
# Check if this layer uses MoE or dense MLP (matches Qwen2/Qwen3 convention)
|
||||
mlp_only_layers = (
|
||||
[] if not hasattr(config, "mlp_only_layers") else config.mlp_only_layers
|
||||
)
|
||||
self.is_moe_layer = (
|
||||
(layer_idx not in mlp_only_layers)
|
||||
and (config.num_experts > 0)
|
||||
and ((layer_idx + 1) % config.decoder_sparse_step == 0)
|
||||
get_mlp_layer_types(config)[layer_idx] == "sparse"
|
||||
and config.num_experts > 0
|
||||
)
|
||||
|
||||
if self.is_moe_layer:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import importlib.metadata
|
||||
import math
|
||||
from collections.abc import Iterable, Mapping, Sequence
|
||||
from dataclasses import dataclass, fields
|
||||
@@ -12,15 +13,12 @@ import torch.nn as nn
|
||||
from mistral_common.protocol.instruct.chunk import ImageChunk, TextChunk
|
||||
from mistral_common.protocol.instruct.messages import UserMessage
|
||||
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
||||
from packaging.version import Version
|
||||
from transformers import BatchFeature, PixtralVisionConfig
|
||||
from transformers.models.pixtral.image_processing_pixtral import (
|
||||
_num_image_tokens as _get_pixtral_hf_num_image_tokens,
|
||||
)
|
||||
from transformers.models.pixtral.modeling_pixtral import (
|
||||
PixtralRotaryEmbedding,
|
||||
apply_rotary_pos_emb,
|
||||
position_ids_in_meshgrid,
|
||||
)
|
||||
from transformers.models.pixtral.modeling_pixtral import apply_rotary_pos_emb
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.config.multimodal import BaseDummyOptions
|
||||
@@ -92,6 +90,39 @@ from .vision import (
|
||||
|
||||
PATCH_MERGE = "patch_merge"
|
||||
|
||||
# Transformers 5.17 renamed Pixtral's rotary embedding and switched it to axial
|
||||
# RoPE, which takes 2D (height, width) positions instead of flattened grid ids.
|
||||
TRANSFORMERS_VERSION = importlib.metadata.version("transformers")
|
||||
TRANSFORMERS_WITH_AXIAL_ROPE = Version(TRANSFORMERS_VERSION) >= Version("5.17.0.dev0")
|
||||
|
||||
if TRANSFORMERS_WITH_AXIAL_ROPE:
|
||||
from transformers.models.pixtral.modeling_pixtral import (
|
||||
PixtralVisionRotaryEmbedding,
|
||||
)
|
||||
else:
|
||||
from transformers.models.pixtral.modeling_pixtral import (
|
||||
PixtralRotaryEmbedding as PixtralVisionRotaryEmbedding,
|
||||
)
|
||||
from transformers.models.pixtral.modeling_pixtral import (
|
||||
position_ids_in_meshgrid as flat_position_ids_in_meshgrid,
|
||||
)
|
||||
|
||||
|
||||
def position_ids_in_meshgrid(
|
||||
patch_embeds_list: list[torch.Tensor],
|
||||
max_width: int,
|
||||
) -> torch.Tensor:
|
||||
if not TRANSFORMERS_WITH_AXIAL_ROPE:
|
||||
return flat_position_ids_in_meshgrid(patch_embeds_list, max_width)
|
||||
positions = []
|
||||
for patch in patch_embeds_list:
|
||||
height, width = patch.shape[-2:]
|
||||
h_ids, w_ids = torch.meshgrid(
|
||||
torch.arange(height), torch.arange(width), indexing="ij"
|
||||
)
|
||||
positions.append(torch.stack([h_ids.flatten(), w_ids.flatten()], dim=-1))
|
||||
return torch.cat(positions, dim=0)
|
||||
|
||||
|
||||
def _make_packed_sequence_metadata(
|
||||
sequence_lengths: list[int],
|
||||
@@ -1467,7 +1498,9 @@ class PixtralHFVisionModel(nn.Module):
|
||||
|
||||
self.dtype = next(self.parameters()).dtype
|
||||
self.device = next(self.parameters()).device
|
||||
self.patch_positional_embedding = PixtralRotaryEmbedding(config, self.device)
|
||||
self.patch_positional_embedding = PixtralVisionRotaryEmbedding(config).to(
|
||||
self.device
|
||||
)
|
||||
|
||||
def forward(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user