Skip to content

Fix the SM120 Sage and ConvRot GELU kernels on Windows - #1639

Open
hiroki-abe-58 wants to merge 1 commit into
ModelTC:mainfrom
hiroki-abe-58:fix-sage-sm120-torch-ops
Open

hiroki-abe-58 wants to merge 1 commit into
ModelTC:mainfrom
hiroki-abe-58:fix-sage-sm120-torch-ops

Conversation

@hiroki-abe-58

Copy link
Copy Markdown

On Windows, the RTX 5090 EdenLive preset (configs/edenlive/realtime/wan22_5b_ar_int8_convrot_5090.json) stops before the first chunk. There are two separate failures.

Problem

  1. SM120 SageAttention. sage_attn2_sm120_cached calls sageattention._fused and _qattn_sm89 functions as module attributes. The Windows SageAttention wheels that the Windows guide links to (woct0rdho, stable-ABI builds) register these kernels as torch ops instead (torch.ops.sageattention_fused, torch.ops.sageattention_qattn_sm89), so the modules have no such attributes:
    AttributeError: module 'sageattention._fused' has no attribute 'quant_per_block_int8_fuse_sub_mean_cuda'
  2. Fused GELU → ConvRot INT8 quantizer. It is built with cpp_extension.load(is_python_module=False) and opened with ctypes. On Windows a DLL only exports functions that are marked for export, so the entry point is missing:
    AttributeError: function 'lightx2v_prepare_convrot_gelu' not found
    prepare_convrot_gelu_fusion only catches OSError and RuntimeError, so the model load fails, instead of falling back to the unfused path as its docstring describes.

Change

  • sage_sm120_cached.py: one helper returns the module functions when the module has them, and otherwise the torch-ops namespaces (stable-ABI builds). Builds with module functions behave as before.
  • convrot_gelu_quant.cu: export the two extern "C" entry points under _WIN32. The macro is empty on other platforms.
  • fused_gelu_linear.py: a missing entry point (AttributeError) now counts as "fusion unavailable", like a failed build.

Validation

Setup: Windows 11, RTX 5090 (driver 610.88), torch 2.14.1+cu130, SageAttention 2.2.0+cu130torch2.10.0andhigher.post6 (abi3), comfy-kitchen 0.2.39, CUDA 13.1 with MSVC 2022 (Build Tools 17.14).

Kernel checks (EdenLive 5B attention shapes: 24 heads, head dim 128, 2640 query and 15840 key/value tokens, BF16):

check main (d2d7424) this PR
SageAttn2Sm120CachedWeight.apply vs SDPA AttributeError cosine 0.99924
apply_prepared(prepare_sage_sm120_kv(...)) vs SDPA AttributeError cosine 0.99924
prepare_convrot_gelu_fusion() AttributeError True; dumpbin /exports lists both functions
fused_gelu_convrot_int8_quant(x) vs comfy-kitchen's quantize_int8_rowwise_convrot64(gelu(x), 256), x: [2640, 14336] BF16 - INT8 values and scales bit-identical

End to end. I ran python -m lightx2v.infer --model_cls wan22_edenlive_ar --task i2v with the 5090 preset's settings: INT8 ConvRot DiT and proxy encoder, sage_attn2_sm120_cached, use_compile, warmup, use_cuda_graph, and LightTAE streaming decode. Three kernels have no Windows build, so I substituted:

  • torch_real_rope for FlashInfer RoPE;
  • torch RMSNorm for sgl-kernel;
  • BF16 T5 on the CPU for FP8-SGL.

Input: the first 120 frames of the cryo-crossing sample at 1280×704.

  • main: stops at model load (ConvRot) or at the first attention call (Sage), depending on the config.
  • This PR: 117 frames at 22.3 FPS generation. That is the sum of the request's chunk times; the one-time compile warmup of about 108 s is excluded. Peak reserved memory was 24.0 GiB, and the frames follow the proxy video.

For comparison, on the same machine without sage_attn2_sm120_cached, compile and CUDA graphs:

  • BF16 with torch kernels: 7.9 FPS;
  • with SageAttention 2 and Triton norms: 11.0 FPS;
  • with INT8 ConvRot added: 16.8 FPS.

Not changed here: building the extension needs the MSVC environment, and vcvars64.bat sets Platform=x64. Windows environment variable names are case-insensitive, so lightx2v_platform reads it as PLATFORM and stops with Unsupported PLATFORM: x64 unless PLATFORM=cuda is set. I can add a line about this to the Windows guide if that would help.

🤖 Generated with Claude Code

- sage_attn2_sm120_cached: the Windows SageAttention wheels are stable-ABI builds that register the fused and SM89 kernels as torch ops, so sageattention._fused/_qattn_sm89 have no function attributes; use torch.ops.sageattention_fused / sageattention_qattn_sm89 when the modules have none.

- convrot_gelu_quant.cu: a Windows DLL exports only functions marked for export, so ctypes could not find the two entry points; export them on _WIN32.

- prepare_convrot_gelu_fusion: treat a missing entry point (AttributeError) like a failed build, so the unfused path is used as documented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant