fix(norm): use getattr for optional .bias on layernorm in fused_split_qk_norm#531
Open
zhshgmail wants to merge 1 commit into
Open
fix(norm): use getattr for optional .bias on layernorm in fused_split_qk_norm#531zhshgmail wants to merge 1 commit into
zhshgmail wants to merge 1 commit into
Conversation
…_qk_norm
The kernel call site read q_a_layernorm.bias and kv_a_layernorm.bias
unconditionally, which crashes when the caller passes RMSNorm modules
(RMSNorm has .weight but no .bias). This is the exact configuration
sglang's srt/models/deepseek_v2.py uses on the DSA_NPU path -- it
constructs q_a_layernorm / kv_a_layernorm as RMSNorm.
Symptom on lmsysorg/sglang:main-cann8.5.0-a3 (sglang 0.5.12.post2.dev434,
sgl-kernel-npu 2026.5.1) loading a 1-layer DeepseekV32 random-init HF
checkpoint with device='npu' + attention_backend='ascend':
File sgl_kernel_npu/norm/fused_split_qk_norm.py, line 118
q_a_layernorm.bias,
AttributeError: 'RMSNorm' object has no attribute 'bias'
Replace each .bias read with getattr(layernorm, 'bias', None). The
kernel already has a separate runtime constant flag for bias presence
(passed as the last two args), so passing None when no bias is present
is harmless.
Contributor
There was a problem hiding this comment.
Code Review
This pull request modifies fused_split_qk_norm.py to use getattr when accessing the bias attribute of q_a_layernorm and kv_a_layernorm, preventing potential attribute errors if the bias is missing. There are no review comments, and I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(norm): use
getattrfor optionalbiasattribute on layernorm infused_split_qk_normSummary
sgl_kernel_npu/norm/fused_split_qk_norm.py:118+readsq_a_layernorm.biasandkv_a_layernorm.biasunconditionally. When the caller passes RMSNorm modules (which only have.weight, no.bias), this raisesAttributeErrormid-forward and crashes the scheduler.This is the exact configuration that sglang's
srt/models/deepseek_v2.pyuses on the DSA_NPU path:q_a_layernormandkv_a_layernormare constructed asRMSNorm, not LayerNorm.Reproduction
device='npu'+attention_backend='ascend'fused_split_qk_norm->AttributeError: 'RMSNorm' object has no attribute 'bias'Discovered while loading a fabricated 1-layer DSv4-Flash random-init HF checkpoint into
sgl.Engine(device='npu', ...)onlmsysorg/sglang:main-cann8.5.0-a3(image built 2026-05-25; sglang0.5.12.post2.dev434+gb13d3d18c, sgl-kernel-npu2026.5.1).Full traceback:
Fix
Use
getattr(layernorm, 'bias', None)so the kernel correctly receivesNonewhen bias is absent. Same change for theis not Nonecallsites a few lines below.The kernel implementation already gates on the runtime constant flag (
bias_exists), so passingNoneis harmless when no bias is present.Verification
After the patch on the same image, the same model loads + forwards + generates without error on NPU:
(Full repro at: https://github.com/zhshgmail/easyr1-npu/blob/main/workspace/T32_tilelang_rescue/sgl_kernel_npu_rmsnorm_bias_patch.diff)
Related
sgl-project/sglangsrt/models/deepseek_v2.pyconstructsq_a_layernorm/kv_a_layernormas RMSNorm. No change needed there..biasaccess pattern.