Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/model_executor/layers/test_mm_input_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
import torch

from vllm.config import CompilationConfig, VllmConfig, set_current_vllm_config
from vllm.config.compilation import CompilationMode
from vllm.model_executor.layers.fusion.mm_input_norm import (
FusedMMInputNorm,
IdentityInputNorm,
Expand Down Expand Up @@ -263,6 +265,25 @@ def test_rejects_mismatched_output_shape(self):
class TestFusedMMInputNormConstruction:
"""Weight/bias buffer semantics at init time."""

def test_compiled_encoder_enables_only_requested_input_norm(self):
config = VllmConfig(
compilation_config=CompilationConfig(
mode=CompilationMode.VLLM_COMPILE,
compile_mm_encoder=True,
custom_ops=["none"],
)
)
with set_current_vllm_config(config):
FusedMMInputNorm(_RGB_MEAN, _RGB_STD, _RGB_RESCALE)
FusedMMInputNorm(_RGB_MEAN, _RGB_STD, _RGB_RESCALE, enforce_enable=True)
assert (
config.compilation_config.enabled_custom_ops["fused_mm_input_norm"] == 1
)
assert (
config.compilation_config.disabled_custom_ops["fused_mm_input_norm"]
== 1
)

def test_identity_config_buffers(self):
"""Numerically identity parameters still build plain weight/bias
buffers; the identity shortcut lives in ``from_model_config``."""
Expand Down
9 changes: 7 additions & 2 deletions vllm/model_executor/layers/fusion/mm_input_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ def __init__(
image_std: list[float],
rescale_factor: float,
channel: int = 3,
*,
enforce_enable: bool = False,
):
super().__init__()
super().__init__(enforce_enable=enforce_enable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's always enable fusion for this ops directly like mhc:

@classmethod
def enabled(cls) -> bool:
return True

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, modified this PR to enable it unconditionally


assert len(image_mean) == len(image_std) == channel, (
f"image_mean/image_std must have {channel} entries, "
Expand Down Expand Up @@ -332,7 +334,9 @@ def forward_oot(
return self.forward_native(pixel_values, visual_dtype)


def build_mm_input_norm(model_config: ModelConfig) -> nn.Module:
def build_mm_input_norm(
model_config: ModelConfig, *, enforce_enable: bool = False
) -> nn.Module:
"""Build the input normalisation module for a model.

Returns an ``IdentityInputNorm`` when device-side normalisation is
Expand All @@ -357,4 +361,5 @@ def build_mm_input_norm(model_config: ModelConfig) -> nn.Module:
image_std=params.image_std,
rescale_factor=params.rescale_factor,
channel=len(params.image_mean),
enforce_enable=enforce_enable,
)
5 changes: 4 additions & 1 deletion vllm/model_executor/models/mistral3.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ def __init__(self, *, vllm_config: VllmConfig, prefix: str = "") -> None:
self.vision_tower = init_vision_tower_for_mistral3(
config,
quant_config=quant_config,
input_norm=build_mm_input_norm(vllm_config.model_config),
input_norm=build_mm_input_norm(
vllm_config.model_config,
enforce_enable=vllm_config.compilation_config.compile_mm_encoder,
),
require_post_norm=False,
prefix=maybe_prefix(prefix, "vision_tower"),
)
Expand Down
Loading