{"record":{"id":"dc9f14b020aeec1b","repo":"hiyouga/LlamaFactory","slug":"self-class-name-has-no-rmsnorm-weight-fo","errorCode":null,"errorMessage":"{self.__class__.__name__} has no RMSNorm weight for NPU RMSNorm kernel.","messagePattern":"(.+?) has no RMSNorm weight for NPU RMSNorm kernel\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/npu_rms_norm.py","lineNumber":58,"sourceCode":"else:\n    _TORCH_NPU_IMPORT_ERROR = None\n\n\ndef npu_rms_norm_forward(self, hidden_states):\n    \"\"\"NPU forward implementation for standard RMSNorm.\n\n    Args:\n        self (nn.Module): The RMSNorm module instance with ``weight`` and either ``variance_epsilon`` or ``eps``.\n        hidden_states (Tensor): Input hidden states tensor.\n\n    Returns:\n        Tensor: Normalized tensor consistent with the baseline RMSNorm behavior.\n    \"\"\"\n    _eps = getattr(self, \"variance_epsilon\", None) or getattr(self, \"eps\", 1e-6)\n\n    weight = getattr(self, \"weight\", None)\n    if weight is None:\n        raise RuntimeError(f\"{self.__class__.__name__} has no RMSNorm weight for NPU RMSNorm kernel.\")\n\n    effective_weight = weight.float()\n\n    return torch_npu.npu_rms_norm(hidden_states, effective_weight.to(hidden_states.dtype), epsilon=_eps)[0]\n\n\ndef npu_residual_rms_norm_forward(self, hidden_states):\n    \"\"\"NPU forward implementation for residual RMSNorm.\n\n    Residual RMSNorm uses ``scale = 1.0 + weight`` where ``weight`` is initialized\n    to 0 in the original transformers implementation.\n\n    Args:\n        self (nn.Module): The residual RMSNorm module with ``weight`` and either ``variance_epsilon`` or ``eps``.\n        hidden_states (Tensor): Input hidden states tensor.\n\n    Returns:\n        Tensor: Normalized tensor consistent with residual RMSNorm behavior.","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/npu_rms_norm.py#L40-L76","documentation":"The patched NPU RMSNorm forward reads the module's `weight` attribute; if the module has no weight (weight is None or the attribute is missing), the NPU op has no scale tensor and the code raises RuntimeError naming the module class before calling torch_npu.npu_rms_norm.","triggerScenarios":"A module matched by _MODEL_TYPE_TO_PATCHES whose `weight` is None — e.g. an RMSNorm constructed with elementwise_affine=False, a partially initialized/tied-weight module, or a custom norm class that stores the scale under a different attribute name.","commonSituations":"Loading checkpoints where the norm weight was not restored (remapped state dict); custom model classes with renamed attributes; newer transformers refactors moving the weight off the expected attribute.","solutions":["Inspect the failing module class from the error message and confirm its weight attribute exists and is a Parameter","If the norm legitimately has no affine weight, exclude that module/model type from npu_fused_rmsnorm patches","Verify the checkpoint loads fully (no missing-keys warnings for norm weights)","Align transformers version with what _MODEL_TYPE_TO_PATCHES was built against"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"for name, m in model.named_modules():\n    if isinstance(m, nn.RMSNorm) and getattr(m, \"weight\", None) is None:\n        raise ValueError(f\"{name} has no RMSNorm weight; cannot use npu_fused_rmsnorm\")","typeGuard":null,"tryCatchPattern":"try:\n    patched = apply_npu_rmsnorm(model)\nexcept RuntimeError as e:\n    if \"no RMSNorm weight\" in str(e):\n        # module without affine weight: skip patching this module\n        log.warning(\"skip NPU RMSNorm: %s\", e)\n    else:\n        raise","preventionTips":["Confirm checkpoints load all norm weights (watch missing-keys warnings)","Exclude weightless norm variants from the patch map"],"tags":["runtime","npu","rmsnorm","model-state"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}