Repository navigation
fix(rocm): make rms_norm_type="sgl-kernel" actually use the aiter RMSNorm - #1709
Open
menglcai-amd wants to merge 1 commit into
Open
menglcai-amd wants to merge 1 commit into
menglcai-amd wants to merge 1 commit into
Conversation
Signed-off-by: menglcai <menglcai@amd.com>
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.
Problem
While we tested Wan2.2-TI2V-5B on MI250 (gfx90a) with the stock
configs/wan22/wan_ti2v.json, the startup log said:But the RMSNorm in the transformer blocks never reached aiter. In
lightx2v.common.ops.norm.rms_norm_weight,sgl_kernelwasNone, 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"whenrms_norm_typeis not set (lightx2v/models/networks/wan/weights/transformer_weights.py), so every Wan config on ROCm is affected, includingconfigs/platforms/amd_rocm/wan_t2v.json.Cause
On ROCm,
init_device_envputs anAiterSglKernelCompatobject intosys.modules["sgl_kernel"].lightx2v/__init__.pyruns this beforerms_norm_weight.pyis imported. Thenrms_norm_weight.pydoes:The compat object is not a package, so
sgl_kernel.utilscannot be imported. Theexceptbranch setssgl_kernel = None.There is a second problem behind the first one.
RMSWeightSgl.applycallssgl_kernel.rmsnorm(x, w, eps, enable_pdl=...), butAiterSglKernelCompat.rmsnorm(input, weight, eps)has noenable_pdlparameter. If only the import were fixed, this call would raiseTypeError.Fix
ROCm only, in
lightx2v_platform/base/amd_rocm.py(+4/-1):sys.modules["sgl_kernel.utils"]withis_arch_support_pdlthat returnsFalse. PDL is a CUDA (Hopper and newer) feature.enable_pdl=FalsetoAiterSglKernelCompat.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:rms_norm_weight.sgl_kernelNoneAiterSglKernelCompatrms_norm_weight.is_arch_support_pdlNoneFalseOp 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.End to end: Wan2.2-TI2V-5B T2V,
configs/wan22/wan_ti2v.jsonwith these ROCm changes:torch_sdpaattention (no flash_attn3 on ROCm),rope_type="torch_complex_rope"(no flashinfer in this environment), 41 frames, 20 steps, seed 42.rms_norm_typeis not set, so the Wan default"sgl-kernel"is used. One run for each case.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: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.
pre-commit run --files lightx2v_platform/base/amd_rocm.pypasses.