Skip to content

fix(rocm): make rms_norm_type="sgl-kernel" actually use the aiter RMSNorm - #1709

Open
menglcai-amd wants to merge 1 commit into
ModelTC:mainfrom
menglcai-amd:fix/rocm-sgl-rmsnorm
Open

menglcai-amd wants to merge 1 commit into
ModelTC:mainfrom
menglcai-amd:fix/rocm-sgl-rmsnorm

Conversation

@menglcai-amd

@menglcai-amd menglcai-amd commented Nov 13, 2026 •

Copy link
Copy Markdown

Problem

While we tested Wan2.2-TI2V-5B on MI250 (gfx90a) with the stock configs/wan22/wan_ti2v.json, the startup log said:

  - aiter sgl_kernel compatibility layer enabled (RMSNorm, GEMM)

But the RMSNorm in the transformer blocks never reached aiter. In lightx2v.common.ops.norm.rms_norm_weight, sgl_kernel was None, so every "sgl-kernel" RMSNorm took the bf16 torch fallback. Nothing failed and nothing was logged.

This is not limited to one config. The Wan network uses "sgl-kernel" when rms_norm_type is not set (lightx2v/models/networks/wan/weights/transformer_weights.py), so every Wan config on ROCm is affected, including configs/platforms/amd_rocm/wan_t2v.json.

Cause

On ROCm, init_device_env puts an AiterSglKernelCompat object into sys.modules["sgl_kernel"]. lightx2v/__init__.py runs this before rms_norm_weight.py is imported. Then rms_norm_weight.py does:

try:
    import sgl_kernel
    from sgl_kernel.utils import is_arch_support_pdl
except ImportError:
    sgl_kernel = None
    is_arch_support_pdl = None

The compat object is not a package, so sgl_kernel.utils cannot be imported. The except branch sets sgl_kernel = None.

There is a second problem behind the first one. RMSWeightSgl.apply calls sgl_kernel.rmsnorm(x, w, eps, enable_pdl=...), but AiterSglKernelCompat.rmsnorm(input, weight, eps) has no enable_pdl parameter. If only the import were fixed, this call would raise TypeError.

Fix

ROCm only, in lightx2v_platform/base/amd_rocm.py (+4/-1):

  • Register sys.modules["sgl_kernel.utils"] with is_arch_support_pdl that returns False. PDL is a CUDA (Hopper and newer) feature.
  • Add enable_pdl=False to AiterSglKernelCompat.rmsnorm. The value is ignored.

NVIDIA and other platforms do not load this file. The registration runs only when aiter is installed, the same as the existing sys.modules["sgl_kernel"] line.

Validation

Environment: gfx90a, MI250, one GCD. ROCm 10.3.0a20261111 (TheRock nightly wheels), PyTorch 2.16.0a0+rocm10.3.0a20261111, aiter 8bbce0dba. PLATFORM=amd_rocm.

Detection, after import lightx2v:

Before After
rms_norm_weight.sgl_kernel None AiterSglKernelCompat
rms_norm_weight.is_arch_support_pdl None returns False

Op check: RMS_WEIGHT_REGISTER["sgl-kernel"], compared with an fp32 RMSNorm reference. bf16 and fp16, shapes (1, 4096, 3072), (2, 333, 5120), (7, 128). All cases pass |out - ref| <= 1e-2 + 1.6e-2 * |ref|, before and after. The bf16 max abs error goes from 0.0625 (torch bf16 fallback) to 0.0156 (aiter). Time per call: mean of 100 calls after 10 warmup calls, CUDA events.

Shape (bf16) Before (torch fallback) After (aiter)
4096 x 3072 178 us 68 us
8448 x 5376 541 us 150 us

End to end: Wan2.2-TI2V-5B T2V, configs/wan22/wan_ti2v.json with these ROCm changes: torch_sdpa attention (no flash_attn3 on ROCm), rope_type="torch_complex_rope" (no flashinfer in this environment), 41 frames, 20 steps, seed 42. rms_norm_type is not set, so the Wan default "sgl-kernel" is used. One run for each case.

DiT time (s) Step time after warmup (s)
Before 65.9 2.47
After 65.5 2.42 - 2.50

The end-to-end gain is small (about 1%), because RMSNorm is only the q/k norm in a Wan block. The main point of this PR is that the setting now does what it says.

The output video changes. Before the fix, two runs give the same video (PSNR 99 dB). To check that the new video is not worse, we also ran the same setup with rms_norm_type="fp32_variance" (fp32 RMSNorm) as a reference:

Pair PSNR (mean over 41 frames)
Before vs. after 16.1 dB
Before vs. fp32 reference 15.4 dB
After vs. fp32 reference 18.5 dB

The new output is closer to the fp32 reference. The small RMSNorm difference grows over 20 denoising steps, so the videos are not pixel-equal, but all three show the same scene with the same quality.

Frame Before (torch bf16 fallback) / After (aiter) / fp32 reference
0 cmp_wan22_frame00
20 cmp_wan22_frame20
40 cmp_wan22_frame40

pre-commit run --files lightx2v_platform/base/amd_rocm.py passes.

Signed-off-by: menglcai <menglcai@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant