[Perf] Optimize RMSNorm in Z-Image (#3304)

Signed-off-by: Lancer <maruixiang6688@gmail.com>
This commit is contained in:
Lancer authored and GitHub committed 2026-05-04 17:34:43 +08:00
1 parent 33586d845c
commit bb69cbc9f1
3 files changed
+114 -3

No files matched your search

+18 -2
View File
@@ -70,17 +70,33 @@ class RMSNorm(CustomOp):
self.weight = nn.Parameter(torch.ones(hidden_size))
self.variance_epsilon = eps
def _forward_fused(self, x: torch.Tensor) -> torch.Tensor:
from vllm._custom_ops import rms_norm as fused_rms_norm
orig_shape = x.shape
hidden_size = orig_shape[-1]
x_2d = x.reshape(-1, hidden_size)
out = torch.empty_like(x_2d)
fused_rms_norm(out, x_2d, self.weight.data, self.variance_epsilon)
return out.reshape(orig_shape)
def forward_cuda(
self,
x: torch.Tensor,
) -> torch.Tensor:
return self.forward_native(x)
try:
return self._forward_fused(x)
except Exception:
return self.forward_native(x)
def forward_hip(
self,
x: torch.Tensor,
) -> torch.Tensor:
return self.forward_native(x)
try:
return self._forward_fused(x)
except Exception:
return self.forward_native(x)
def forward_npu(
self,
@@ -25,7 +25,6 @@ import torch.nn as nn
from torch.nn.utils.rnn import pad_sequence
from vllm.logger import init_logger
from vllm.model_executor.layers.activation import SiluAndMul
from vllm.model_executor.layers.layernorm import RMSNorm
from vllm.model_executor.layers.linear import (
MergedColumnParallelLinear,
QKVParallelLinear,
@@ -34,6 +33,8 @@ from vllm.model_executor.layers.linear import (
)
from vllm.model_executor.model_loader.weight_utils import default_weight_loader
from vllm_omni.diffusion.layers.norm import RMSNorm
if TYPE_CHECKING:
from vllm.model_executor.layers.quantization.base_config import (
QuantizationConfig,