diff --git a/python/sglang/multimodal_gen/runtime/models/dits/flux.py b/python/sglang/multimodal_gen/runtime/models/dits/flux.py index 584960c576..10c3645db2 100644 --- a/python/sglang/multimodal_gen/runtime/models/dits/flux.py +++ b/python/sglang/multimodal_gen/runtime/models/dits/flux.py @@ -1196,6 +1196,11 @@ class FluxTransformer2DModel(CachableDiT, LayerwiseOffloadableModuleMixin): Reference: https://blackforestlabs.ai/announcing-black-forest-labs/ """ + _compile_conditions = [ + lambda name, module: isinstance( + module, (FluxTransformerBlock, FluxSingleTransformerBlock) + ) + ] param_names_mapping = FluxConfig().arch_config.param_names_mapping @classmethod diff --git a/python/sglang/multimodal_gen/test/unit/test_regional_torch_compile.py b/python/sglang/multimodal_gen/test/unit/test_regional_torch_compile.py index 9ce2e22b60..74937a5dc7 100644 --- a/python/sglang/multimodal_gen/test/unit/test_regional_torch_compile.py +++ b/python/sglang/multimodal_gen/test/unit/test_regional_torch_compile.py @@ -5,6 +5,11 @@ from unittest.mock import MagicMock, patch import pytest import torch.nn as nn +from sglang.multimodal_gen.runtime.models.dits.flux import ( + FluxSingleTransformerBlock, + FluxTransformer2DModel, + FluxTransformerBlock, +) from sglang.multimodal_gen.runtime.models.dits.ltx_2 import ( LTX2VideoTransformer3DModel, ) @@ -195,6 +200,18 @@ def test_ltx2_compile_conditions_match_only_direct_blocks(): ) +def test_flux_compile_conditions_match_both_block_types(): + def matches(module) -> bool: + return any( + condition("transformer_blocks.0", module) + for condition in FluxTransformer2DModel._compile_conditions + ) + + assert matches(FluxTransformerBlock.__new__(FluxTransformerBlock)) + assert matches(FluxSingleTransformerBlock.__new__(FluxSingleTransformerBlock)) + assert not matches(nn.Linear(2, 2)) + + def test_compile_matching_submodules_matches_only_declared_regions(): model = _RegionalModel()