Skip to content

fix(minimax_h3): use the portable Triton libdevice in the audio VAE kernel so it compiles on ROCm - #1771

Open
WhatGhost wants to merge 1 commit into
ModelTC:mainfrom
WhatGhost:fix/h3-audio-vae-rocm-libdevice
Open

WhatGhost wants to merge 1 commit into
ModelTC:mainfrom
WhatGhost:fix/h3-audio-vae-rocm-libdevice

Conversation

@WhatGhost

Copy link
Copy Markdown
Contributor

Summary

lightx2v/models/audio_encoders/hf/minimax_h3/triton_ops.py (added in #1721) imports triton.language.extra.cuda.libdevice. On ROCm the kernel fails to compile:

RuntimeError: Implicit conversion of CUDA __nv_expf device function has been dropped; please, update your source
program to use triton.language.extra.<op> to replace triton.language.extra.cuda.<op>

so every MiniMax-H3 request that decodes audio fails on AMD GPUs. This PR imports triton.language.extra.libdevice (dispatched per backend) and replaces libdevice.rcp_rn(x), which the HIP libdevice does not provide, with tl.math.div_rn(1.0, x) (the same correctly rounded reciprocal).

Results

AMD Radeon AI PRO R9700 (gfx1201), ROCm 7.2.4, torch 2.10.0, triton 3.6.0: MiniMax-H3 t2av at 768x1344x124 fails in the audio decoder on main and completes with this patch (the output has a non-silent audio track without clipping).

The audio decoder now runs the fused kernels from #1721 on AMD as well. Compared with its PyTorch modules (the path before #1721; on ROCm LightX2V disables cuDNN/MIOpen, so the grouped transposed convolution runs one GEMM + col2im per batch item and channel group):

PyTorch modules fused kernels
Audio VAE decode, 124 frames (207 latent frames), weights on the GPU 0.83 s 0.21 s (4.0x)
Audio VAE decode, 362 frames (603 latent frames), weights on the GPU 1.42 s 0.63 s (2.3x)
Audio decode in a full 124-frame request (vae_cpu_offload: weights moved in and out) 1.28 s 0.40 s
Full 124-frame request 200.0 s 199.3 s

Decodes are medians of 5, alternating the two paths in one process; the output matches the PyTorch modules to 100 dB SNR (max abs diff 9e-5). Full requests: fp8-triton DiT, 4-step LoRA, one request per path after a warmup, back to back on the same GPU, with the PyTorch modules forced by patching MiniMaxH3AudioActivation1d.forward.

NVIDIA

No change. GeForce RTX 5090 (sm_120), torch 2.11.0+cu130, Triton 3.6.0: the H3 audio VAE decoder with the released checkpoint and random latents of 207 and 603 frames (124- and 362-frame videos), before and after this patch:

207 frames 603 frames
All 127 fused activations, both kernels on the same real inputs bitwise identical bitwise identical
Decoded waveform bitwise identical bitwise identical
Audio decode, median of 5 (before -> after) 17.5 -> 17.1 ms 41.8 -> 41.7 ms
Per-activation kernel time, after / before 0.99-1.00 0.98-1.00

Why: compiled for sm_80, sm_90 and sm_120, exp and sin resolve to the same __nv_expf / __nv_sinf (triton.language.extra.libdevice dispatches to the CUDA libdevice on NVIDIA, since Triton 3.0; it is also what Inductor imports). The reciprocal changes from rcp.rn.ftz.f32 to div.rn.f32; both are correctly rounded and differ only for subnormal values, while the input is exp(beta) + 1e-9 (0.29-5.62 over the checkpoint). The main path gains one SASS instruction; the rest of the added code is the division's out-of-line slow path for special values.

Notes

Other kernels import triton.language.extra.cuda.libdevice too (common/ops/norm/l2_normalize.py, common/ops/mm/fused_gelu_linear.py, common/ops/attn/kernels/ulysses_layout.py, models/video_encoders/hf/minimax_h3_causal/rgb.py, common/kvcache/attn/kernels/sage_*.py); they are not on the H3 t2av path and are left for a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant