sgl-project/sglang · error · NotImplementedError

Norm type {self.norm_type} not implemented

Error message

Norm type {self.norm_type} not implemented

What it means

The residual-scale-shift norm wrapper only supports norm_type values 'rms' (RMSNorm) and 'layer' (FP32LayerNorm); anything else fails at construction with NotImplementedError.

Source

Thrown at python/sglang/multimodal_gen/runtime/layers/layernorm.py:597

    def __init__(
        self,
        hidden_size: int,
        eps: float = 1e-6,
        elementwise_affine: bool = False,
        dtype: torch.dtype = torch.float32,
        prefix: str = "",
    ):
        super().__init__()
        self.eps = eps
        self.dtype = dtype
        if self.norm_type == "rms":
            self.norm = RMSNorm(hidden_size, eps=eps, dtype=dtype)
        elif self.norm_type == "layer":
            self.norm = FP32LayerNorm(
                hidden_size, elementwise_affine=elementwise_affine, eps=eps, dtype=dtype
            )
        else:
            raise NotImplementedError(f"Norm type {self.norm_type} not implemented")

    def forward_cuda(
        self,
        residual: torch.Tensor,
        x: torch.Tensor,
        gate: torch.Tensor | int,
        shift: torch.Tensor,
        scale: torch.Tensor,
    ) -> tuple[torch.Tensor, torch.Tensor]:
        if residual.numel() == 0 or x.numel() == 0:
            return self.forward_native(residual, x, gate, shift, scale)

        if x.shape[-1] % 256 != 0 or x.shape[-1] > 8192:
            import warnings

            warnings.warn(
                "FusedScaleResidualNormScaleShift cuda not available, using native fallback",
                stacklevel=2,

View on GitHub (pinned to 0132848349)

Solutions

  1. Use 'rms' or 'layer' exactly
  2. Normalize config: map common aliases ('rmsnorm'->'rms', 'layernorm'->'layer') before construction
  3. Extend the __init__ branch if you genuinely need a new norm type (maintainer action)

Example fix

# before
NormWrapper(hidden_size, norm_type="rmsnorm")
# after
NormWrapper(hidden_size, norm_type="rms")
Defensive patterns

Strategy: validation

Validate before calling

assert norm_type in ('rms', 'layer'), f'unsupported norm_type: {norm_type}'

Type guard

def is_valid_norm_type(t: str) -> bool:\n    return t in ('rms', 'layer')

Prevention

When it happens

Trigger: Passing norm_type not in {'rms','layer'} (e.g. 'ln', 'layer_norm', 'group') to the wrapper's __init__.

Common situations: Typo or different naming convention in a model config; porting a checkpoint whose config uses a different norm name; case sensitivity ('RMS' vs 'rms').

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/74133a4f878c3b8e. Report an issue: GitHub.