[MM] Add Triton kernel for mm_input_normal. (#56798)

Signed-off-by: wang.yuqi <yuqi.wang@daocloud.io>
Signed-off-by: wang.yuqi <noooop@126.com>
Signed-off-by: Isotr0py <Isotr0py@outlook.com>
Co-authored-by: Isotr0py <2037008807@qq.com>
Co-authored-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
wang.yuqi
2026-09-25 04:31:20 +00:00
committed by GitHub
co-authored by Isotr0py Isotr0py
parent 267eee54bf
commit 8a269919f4
9 changed files with 749 additions and 304 deletions
-60
View File
@@ -13,7 +13,6 @@ from vllm.distributed.parallel_state import (
initialize_model_parallel,
)
from vllm.model_executor.models.vision import (
FusedInputNorm,
get_load_balance_assignment,
resolve_visual_encoder_outputs,
run_dp_sharded_mrope_vision_model,
@@ -488,62 +487,3 @@ def test_simple_mrope_vision_model_spatial_merge(spatial_merge_size: int):
assert output.shape[0] == expected_output_patches
assert output.shape[1] == vision_model.out_hidden_size
def _reference_input_norm(
pixel_values: torch.Tensor,
image_mean: list[float],
image_std: list[float],
rescale_factor: float,
channel: int,
out_dtype: torch.dtype,
) -> torch.Tensor:
"""Straightforward per-channel affine: (x * rescale - mean) / std."""
patches, size = pixel_values.shape
patch_size = size // channel
mean = torch.tensor(image_mean, dtype=torch.float32).view(1, channel, 1)
std = torch.tensor(image_std, dtype=torch.float32).view(1, channel, 1)
x = pixel_values.to(torch.float32).view(patches, channel, patch_size)
x = (x * rescale_factor - mean) / std
return x.view(patches, size).to(out_dtype)
@pytest.mark.parametrize("num_patches", [1, 37, 70000])
def test_fused_input_norm_matches_reference(num_patches: int):
"""FusedInputNorm must equal the plain affine, including for num_patches
above the cuDNN batch-norm grid limit (~65535) that previously raised
CUDNN_STATUS_INTERNAL_ERROR (issue #51717)."""
channel = 3
patch_size = 14 * 14
image_mean = [0.48145466, 0.4578275, 0.40821073]
image_std = [0.26862954, 0.26130258, 0.27577711]
rescale_factor = 1.0 / 255.0
set_random_seed(0)
pixel_values = torch.randint(
0, 256, (num_patches, channel * patch_size), dtype=torch.float32
)
norm = FusedInputNorm(
image_mean=image_mean,
image_std=image_std,
rescale_factor=rescale_factor,
channel=channel,
)
assert not norm.is_identity
out = norm(pixel_values, visual_dtype=torch.float32)
expected = _reference_input_norm(
pixel_values, image_mean, image_std, rescale_factor, channel, torch.float32
)
torch.testing.assert_close(out, expected)
def test_fused_input_norm_identity_passthrough():
"""The identity configuration returns the input unchanged (cast only)."""
norm = FusedInputNorm.identity()
assert norm.is_identity
pixel_values = torch.randn(8, 3 * 196, dtype=torch.float32)
out = norm(pixel_values, visual_dtype=torch.bfloat16)
torch.testing.assert_close(out, pixel_values.to(torch.bfloat16))