[Diffusion] Fuse FLUX.2 NVFP4 FC1, SwiGLU, and FC2 quantization (#37096)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -82,6 +82,7 @@ from sglang.multimodal_gen.runtime.models.dits.flux import (
|
||||
_flux_norm_modulate,
|
||||
)
|
||||
from sglang.multimodal_gen.runtime.models.dits.flux_2 import (
|
||||
_can_use_nvfp4_swiglu_quant_fusion,
|
||||
_flux2_norm_modulate,
|
||||
_flux2_swiglu,
|
||||
)
|
||||
@@ -121,6 +122,7 @@ from sglang.multimodal_gen.runtime.models.vaes.wan_vae_cuda_opt import (
|
||||
VaeFastPathGate,
|
||||
)
|
||||
from sglang.multimodal_gen.runtime.models.vaes.wanvae import WanRMS_norm
|
||||
from sglang.multimodal_gen.runtime.platforms.interface import DeviceCapability
|
||||
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
|
||||
from sglang.test.test_utils import CustomTestCase
|
||||
|
||||
@@ -342,6 +344,11 @@ class TestFlux2EagerFusions(CustomTestCase):
|
||||
self.assertFalse(flux2._FLUX2_SWIGLU.disabled)
|
||||
self.assertEqual(len(flux2._FLUX2_SWIGLU_SIGS), 2)
|
||||
|
||||
def test_nvfp4_swiglu_quant_fusion_is_sm103_only(self):
|
||||
self.assertFalse(_can_use_nvfp4_swiglu_quant_fusion(DeviceCapability(10, 0)))
|
||||
self.assertTrue(_can_use_nvfp4_swiglu_quant_fusion(DeviceCapability(10, 3)))
|
||||
self.assertFalse(_can_use_nvfp4_swiglu_quant_fusion(DeviceCapability(12, 0)))
|
||||
|
||||
def test_fp16_preserves_reference_path(self):
|
||||
x = torch.randn(1, 17, 512, device="cuda", dtype=torch.float16)
|
||||
expected = F.silu(x[..., :256]) * x[..., 256:]
|
||||
|
||||
@@ -35,11 +35,15 @@ from sglang.kernels.ops.diffusion import (
|
||||
QualityGatedFusion,
|
||||
can_use_ln_modulate,
|
||||
flashinfer_rmsnorm_diagnostic_hint,
|
||||
flux2_nvfp4_swiglu_quant_active,
|
||||
fused_ln_modulate,
|
||||
fused_ln_modulate_active,
|
||||
mark_flux2_nvfp4_swiglu_quant_site,
|
||||
mark_fused_ln_modulate_site,
|
||||
mount_flux2_nvfp4_swiglu_quant,
|
||||
mount_fused_ln_modulate,
|
||||
tensors_equal,
|
||||
unmount_flux2_nvfp4_swiglu_quant,
|
||||
unmount_fused_ln_modulate,
|
||||
)
|
||||
from sglang.test.ci.ci_register import register_cpu_ci, register_cuda_ci
|
||||
@@ -92,6 +96,18 @@ def test_quality_gate_rejection_is_all_or_nothing():
|
||||
assert not fusion.mount(nn.Module())
|
||||
|
||||
|
||||
def test_flux2_nvfp4_swiglu_quant_is_disabled_until_quality_gate_mounts():
|
||||
site = nn.Module()
|
||||
root = nn.ModuleList([site])
|
||||
mark_flux2_nvfp4_swiglu_quant_site(site)
|
||||
|
||||
assert not flux2_nvfp4_swiglu_quant_active(site)
|
||||
assert mount_flux2_nvfp4_swiglu_quant(root)
|
||||
assert flux2_nvfp4_swiglu_quant_active(site)
|
||||
unmount_flux2_nvfp4_swiglu_quant(root)
|
||||
assert not flux2_nvfp4_swiglu_quant_active(site)
|
||||
|
||||
|
||||
def test_qwen_image_added_qkv_site_is_request_scoped():
|
||||
site = nn.Module()
|
||||
site.to_added_qkv = nn.Module()
|
||||
|
||||
Reference in New Issue
Block a user