From 80b86dbecb0831d4088dc79eb5e1421ff1d06412 Mon Sep 17 00:00:00 2001 From: "jacky.cheng" Date: Tue, 20 Oct 2026 02:07:37 +0800 Subject: [PATCH] [Fix] [AMD] diffusion: Accept residual and skip_bias in the ROCm Conv3d-to-Conv2d VAE patch (#44672) --- .../multimodal_gen/runtime/platforms/rocm.py | 9 ++++-- .../test/unit/test_rocm_conv3d_patch.py | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 python/sglang/multimodal_gen/test/unit/test_rocm_conv3d_patch.py diff --git a/python/sglang/multimodal_gen/runtime/platforms/rocm.py b/python/sglang/multimodal_gen/runtime/platforms/rocm.py index 0fba6bba88..4f2b90bdba 100644 --- a/python/sglang/multimodal_gen/runtime/platforms/rocm.py +++ b/python/sglang/multimodal_gen/runtime/platforms/rocm.py @@ -421,6 +421,8 @@ class RocmPlatform(Platform): x, cache_x=None, *, + residual=None, + skip_bias=False, _padding=padding, _stride=stride, _kt=kt, @@ -433,14 +435,17 @@ class RocmPlatform(Platform): pad[4] -= cache_x.shape[2] x = F.pad(x, pad) x = x.to(self.weight.dtype) - return RocmPlatform._conv3d_as_batched_conv2d( + # Same contract as WanCausalConv3d.forward: skip_bias leaves the bias + # to a following fused norm, residual is added to the conv output. + out = RocmPlatform._conv3d_as_batched_conv2d( x, self._weight_2d, - self.bias, + None if skip_bias else self.bias, _stride, _kt, compute_bf16=_bf16, ) + return out if residual is None else out + residual def _patched_halo_conv_forward( self, diff --git a/python/sglang/multimodal_gen/test/unit/test_rocm_conv3d_patch.py b/python/sglang/multimodal_gen/test/unit/test_rocm_conv3d_patch.py new file mode 100644 index 0000000000..203e5d4223 --- /dev/null +++ b/python/sglang/multimodal_gen/test/unit/test_rocm_conv3d_patch.py @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: Apache-2.0 +import unittest + +import torch + +from sglang.multimodal_gen.runtime.models.vaes.wanvae import WanCausalConv3d +from sglang.multimodal_gen.runtime.platforms.rocm import RocmPlatform + + +class TestRocmConv3dPatchEpilogueKwargs(unittest.TestCase): + """The Wan VAE decoder calls its causal convs with residual= and skip_bias=; + the ROCm Conv3d->Conv2d replacement must accept them and match the original.""" + + def test_patched_conv_matches_original_with_residual_and_skip_bias(self): + torch.manual_seed(0) + ref = WanCausalConv3d(8, 16, 3, padding=1) + patched = WanCausalConv3d(8, 16, 3, padding=1) + patched.load_state_dict(ref.state_dict()) + self.assertEqual(RocmPlatform._replace_conv3d_with_conv2d(patched), 1) + + x = torch.randn(1, 8, 3, 12, 12) + cache_x = torch.randn(1, 8, 2, 12, 12) + residual = torch.randn(1, 16, 3, 12, 12) + for kwargs in ({"residual": residual}, {"skip_bias": True}): + with self.subTest(kwargs=list(kwargs)), torch.no_grad(): + torch.testing.assert_close( + patched(x, cache_x, **kwargs), ref(x, cache_x, **kwargs) + ) + + +if __name__ == "__main__": + unittest.main()