[Diffusion] Fuse FLUX.2 token concatenation and NVFP4 quantization (#37141)
This commit is contained in:
@@ -51,6 +51,7 @@ from sglang.kernels.ops.diffusion import (
|
||||
mount_fused_ln_modulate,
|
||||
mount_hunyuan_qknorm,
|
||||
mount_ltx2_rms_norm_modulate,
|
||||
try_flux2_token_cat_nvfp4,
|
||||
unmount_hunyuan_qknorm,
|
||||
unmount_ltx2_rms_norm_modulate,
|
||||
wan_rmsnorm_silu,
|
||||
@@ -371,6 +372,40 @@ class TestFlux2EagerFusions(CustomTestCase):
|
||||
self.assertTrue(torch.equal(actual, expected))
|
||||
self.assertEqual(len(flux2._FLUX2_SWIGLU_SIGS), 1)
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not torch.cuda.is_available() or torch.cuda.get_device_capability() != (10, 3),
|
||||
reason="FLUX.2 token-cat NVFP4 requires Blackwell SM103",
|
||||
)
|
||||
def test_token_cat_nvfp4_matches_flashinfer(self):
|
||||
import flashinfer
|
||||
|
||||
torch.manual_seed(20260830)
|
||||
attention = torch.randn(1, 17, 6144, device="cuda", dtype=torch.bfloat16)
|
||||
mlp = torch.randn(1, 17, 18432, device="cuda", dtype=torch.bfloat16)
|
||||
global_scale = torch.tensor(0.625, device="cuda", dtype=torch.float32)
|
||||
|
||||
expected_fp4, expected_scales = flashinfer.fp4_quantize(
|
||||
torch.cat([attention, mlp], dim=-1).view(-1, 24576), global_scale
|
||||
)
|
||||
actual = try_flux2_token_cat_nvfp4(attention, mlp, global_scale)
|
||||
|
||||
self.assertIsNotNone(actual)
|
||||
actual_fp4, actual_scales = actual
|
||||
self.assertTrue(torch.equal(actual_fp4, expected_fp4))
|
||||
self.assertTrue(
|
||||
torch.equal(
|
||||
actual_scales.view(torch.uint8), expected_scales.view(torch.uint8)
|
||||
)
|
||||
)
|
||||
|
||||
def test_token_cat_nvfp4_falls_back_while_compiling(self):
|
||||
attention = torch.empty(1, 1, 6144, device="cuda", dtype=torch.bfloat16)
|
||||
mlp = torch.empty(1, 1, 18432, device="cuda", dtype=torch.bfloat16)
|
||||
global_scale = torch.ones(1, device="cuda", dtype=torch.float32)
|
||||
|
||||
with patch("torch.compiler.is_compiling", return_value=True):
|
||||
self.assertIsNone(try_flux2_token_cat_nvfp4(attention, mlp, global_scale))
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Qwen-Image -- reuse timestep-only modulation across serial CFG branches
|
||||
|
||||
Reference in New Issue
Block a user