Skip to content
Open
Changes from all commits
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
16 changes: 14 additions & 2 deletions python/sglang/srt/layers/layernorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ def __init__(self, dim: int, eps: float = 1e-6):
# Re-dispatch

def _norm(self, x):
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
squared = x * x
mean = torch.mean(squared, dim=-1, keepdim=True)
return x * torch.rsqrt(mean + self.eps)

def forward_native(self, x):
output = self._norm(x.float())
Expand All @@ -372,4 +374,14 @@ def extra_repr(self):
logger.info(
"sgl-kernel layernorm implementation is not available on current platform. Fallback to other kernel libraries."
)
from vllm.model_executor.layers.layernorm import GemmaRMSNorm, RMSNorm
try:
from vllm.model_executor.layers.layernorm import GemmaRMSNorm, RMSNorm
except ImportError:

class GemmaRMSNorm:
def __init__(self, *args, **kwargs):
pass

class RMSNorm:
def __init__(self, *args, **kwargs):
pass