vllm.model_executor.layers.fusion.mm_input_norm
¶
Fused Normalisation on the Device.
Equivalent to::
output = (input * rescale_factor - image_mean) / image_std
This is implemented as a single per-channel affine transform::
output = input * weight[c] + bias[c]
where::
weight = rescale_factor / image_std
bias = -image_mean / image_std
Classes:
-
FusedMMInputNorm–Module that applies rescaling and normalisation to input images.
-
IdentityInputNorm–Stand-in used when the processor requires no rescale/normalise.
-
NormParams–Resolved per-channel affine parameters (flags already folded in).
Functions:
-
build_mm_input_norm–Build the input normalisation module for a model.
-
fused_mm_input_norm_triton–Fused per-channel affine transform for normalisation.
FusedMMInputNorm
¶
Bases: CustomOp
Module that applies rescaling and normalisation to input images. Equivalent to: output = (input * rescale_factor - mean) / std
Dtype semantics:
- Input dtype — the dtype of the
pixel_valuesargument toforward_*. It isuint8whenmm_device_do_normalizeis enabled (raw bytes travel to the device unprocessed) and equalsvisual_dtypeotherwise. - Output dtype — the
visual_dtypeargument offorward_*. The computation itself is always fp32, independent of the output dtype (e.g. compute fp32, emit bf16).
Platform dispatch:
forward_native— pure PyTorch eager path, used as the semantic reference and default fallback on all platforms.forward_cuda— Triton kernel path for CUDA devices.forward_xpu— custom XPU kernel path.forward_oot— out-of-tree platform override entry point; falls back toforward_nativeunless a plugin overrides it.
Methods:
-
forward_cuda–Triton kernel path for CUDA devices.
-
forward_native–Pure PyTorch eager implementation.
-
forward_oot–Out-of-tree platform override entrypoint.
-
forward_xpu–XPU fused custom kernel path.
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
forward_cuda(pixel_values, visual_dtype)
¶
Triton kernel path for CUDA devices.
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
forward_native(pixel_values, visual_dtype)
¶
Pure PyTorch eager implementation.
This is the semantic reference implementation and the fallback used on any platform without a specialised kernel.
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
forward_oot(pixel_values, visual_dtype)
¶
Out-of-tree platform override entrypoint.
forward_xpu(pixel_values, visual_dtype)
¶
XPU fused custom kernel path.
On XPU, fuse the whole rescale + normalise into a single custom
kernel. The eager path materializes an fp32 intermediate and then
casts back, which adds device-side compute that cancels the
bandwidth saving of transferring uint8 pixel_values. The fused
kernel reads uint8 directly and writes visual_dtype in one pass.
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
IdentityInputNorm
¶
Bases: Module
Stand-in used when the processor requires no rescale/normalise.
Not a no-op: with mm_device_do_normalize enabled, raw uint8
pixels travel to the device unprocessed and must be cast to
visual_dtype here.
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
NormParams
¶
Bases: NamedTuple
Resolved per-channel affine parameters (flags already folded in).
Attributes:
-
is_identity(bool) –Whether
weight = rescale/stdandbias = -mean/stdare
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
is_identity
property
¶
Whether weight = rescale/std and bias = -mean/std are
numerically the identity transform (mirrors torch.allclose's
default fp32 tolerances).
_load_norm_params(model_config)
¶
Resolve the per-channel affine parameters (image_mean, image_std,
rescale_factor) from the processor config.
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
build_mm_input_norm(model_config)
¶
Build the input normalisation module for a model.
Returns an IdentityInputNorm when device-side normalisation is
disabled or the processor's rescale/normalise is numerically the identity
transform; otherwise a FusedMMInputNorm built from the processor's
parameters.
Source code in vllm/model_executor/layers/fusion/mm_input_norm.py
fused_mm_input_norm_triton(inputs, outputs, weight, bias)
¶
Fused per-channel affine transform for normalisation.
Parameters:
-
(inputs¶Tensor) –Input tensor, shape
(N, C, L). A contiguous copy is materialized internally if needed. -
(outputs¶Tensor) –Output tensor, contiguous and shaped exactly
(N, C, L). -
(weight¶Tensor) –Per-channel scale, shape
(C,). -
(bias¶Tensor) –Per-channel shift, shape
(C,).
Returns:
-
Tensor–outputs, for chaining.