[perf] Use default torch compile mode for Wan2.2 T2V A14B (#28304)
This commit is contained in:
@@ -59,6 +59,7 @@ class DiTConfig(ModelConfig):
|
|||||||
# sglang-diffusion DiT-specific parameters
|
# sglang-diffusion DiT-specific parameters
|
||||||
prefix: str = ""
|
prefix: str = ""
|
||||||
quant_config: QuantizationConfig | None = None
|
quant_config: QuantizationConfig | None = None
|
||||||
|
torch_compile_mode: str = "max-autotune-no-cudagraphs"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_cli_args(parser: Any, prefix: str = "dit-config") -> Any:
|
def add_cli_args(parser: Any, prefix: str = "dit-config") -> Any:
|
||||||
@@ -78,5 +79,12 @@ class DiTConfig(ModelConfig):
|
|||||||
default=None,
|
default=None,
|
||||||
help="Quantization configuration for the DiT model",
|
help="Quantization configuration for the DiT model",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
f"--{prefix}.torch-compile-mode",
|
||||||
|
type=str,
|
||||||
|
dest=f"{prefix.replace('-', '_')}.torch_compile_mode",
|
||||||
|
default=DiTConfig.torch_compile_mode,
|
||||||
|
help="torch.compile mode for the DiT model",
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|||||||
@@ -186,3 +186,4 @@ class LTX2Config(DiTConfig):
|
|||||||
arch_config: LTX2ArchConfig = field(default_factory=LTX2ArchConfig)
|
arch_config: LTX2ArchConfig = field(default_factory=LTX2ArchConfig)
|
||||||
|
|
||||||
prefix: str = "ltx2"
|
prefix: str = "ltx2"
|
||||||
|
torch_compile_mode: str = "default"
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ from sglang.multimodal_gen.configs.pipeline_configs.ideogram import (
|
|||||||
from sglang.multimodal_gen.configs.pipeline_configs.lingbot_world import (
|
from sglang.multimodal_gen.configs.pipeline_configs.lingbot_world import (
|
||||||
LingBotWorldCausalDMDConfig,
|
LingBotWorldCausalDMDConfig,
|
||||||
)
|
)
|
||||||
from sglang.multimodal_gen.configs.pipeline_configs.ltx_2 import LTX2PipelineConfig
|
from sglang.multimodal_gen.configs.pipeline_configs.ltx_2 import (
|
||||||
|
LTX2PipelineConfig,
|
||||||
|
LTX23PipelineConfig,
|
||||||
|
)
|
||||||
from sglang.multimodal_gen.configs.pipeline_configs.mova import MOVAPipelineConfig
|
from sglang.multimodal_gen.configs.pipeline_configs.mova import MOVAPipelineConfig
|
||||||
from sglang.multimodal_gen.configs.pipeline_configs.sana import SanaPipelineConfig
|
from sglang.multimodal_gen.configs.pipeline_configs.sana import SanaPipelineConfig
|
||||||
from sglang.multimodal_gen.configs.pipeline_configs.stablediffusion3 import (
|
from sglang.multimodal_gen.configs.pipeline_configs.stablediffusion3 import (
|
||||||
@@ -75,5 +78,6 @@ __all__ = [
|
|||||||
"SelfForcingWanT2V480PConfig",
|
"SelfForcingWanT2V480PConfig",
|
||||||
"ZImagePipelineConfig",
|
"ZImagePipelineConfig",
|
||||||
"LTX2PipelineConfig",
|
"LTX2PipelineConfig",
|
||||||
|
"LTX23PipelineConfig",
|
||||||
"LingBotWorldCausalDMDConfig",
|
"LingBotWorldCausalDMDConfig",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -274,9 +274,6 @@ class PipelineConfig:
|
|||||||
# Wan2.2 TI2V parameters
|
# Wan2.2 TI2V parameters
|
||||||
boundary_ratio: float | None = None
|
boundary_ratio: float | None = None
|
||||||
|
|
||||||
# Compilation
|
|
||||||
# enable_torch_compile: bool = False
|
|
||||||
|
|
||||||
# calculate the adjust size for condition image
|
# calculate the adjust size for condition image
|
||||||
# width: original condition image width
|
# width: original condition image width
|
||||||
# height: original condition image height
|
# height: original condition image height
|
||||||
|
|||||||
@@ -710,6 +710,11 @@ class LTX2PipelineConfig(PipelineConfig):
|
|||||||
return latents, audio_latents
|
return latents, audio_latents
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
|
class LTX23PipelineConfig(LTX2PipelineConfig):
|
||||||
|
"""Configuration overrides for LTX-2.3."""
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class LTX2I2VPipelineConfig(LTX2PipelineConfig):
|
class LTX2I2VPipelineConfig(LTX2PipelineConfig):
|
||||||
task_type: ModelTaskType = ModelTaskType.TI2V
|
task_type: ModelTaskType = ModelTaskType.TI2V
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ class Wan2_2_T2V_A14B_Config(WanT2V480PConfig):
|
|||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
self.dit_config.boundary_ratio = self.boundary_ratio
|
self.dit_config.boundary_ratio = self.boundary_ratio
|
||||||
|
self.dit_config.torch_compile_mode = "default"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -64,7 +64,10 @@ from sglang.multimodal_gen.configs.pipeline_configs.ideogram import (
|
|||||||
from sglang.multimodal_gen.configs.pipeline_configs.joy_image import (
|
from sglang.multimodal_gen.configs.pipeline_configs.joy_image import (
|
||||||
JoyImageEditPipelineConfig,
|
JoyImageEditPipelineConfig,
|
||||||
)
|
)
|
||||||
from sglang.multimodal_gen.configs.pipeline_configs.ltx_2 import LTX2PipelineConfig
|
from sglang.multimodal_gen.configs.pipeline_configs.ltx_2 import (
|
||||||
|
LTX2PipelineConfig,
|
||||||
|
LTX23PipelineConfig,
|
||||||
|
)
|
||||||
from sglang.multimodal_gen.configs.pipeline_configs.mova import (
|
from sglang.multimodal_gen.configs.pipeline_configs.mova import (
|
||||||
MOVA360PConfig,
|
MOVA360PConfig,
|
||||||
MOVA720PConfig,
|
MOVA720PConfig,
|
||||||
@@ -647,7 +650,7 @@ def _register_configs():
|
|||||||
)
|
)
|
||||||
register_configs(
|
register_configs(
|
||||||
sampling_param_cls=LTX23SamplingParams,
|
sampling_param_cls=LTX23SamplingParams,
|
||||||
pipeline_config_cls=LTX2PipelineConfig,
|
pipeline_config_cls=LTX23PipelineConfig,
|
||||||
hf_model_paths=["Lightricks/LTX-2.3"],
|
hf_model_paths=["Lightricks/LTX-2.3"],
|
||||||
model_detectors=[
|
model_detectors=[
|
||||||
lambda path: "ltx-2.3" in path.lower(),
|
lambda path: "ltx-2.3" in path.lower(),
|
||||||
|
|||||||
@@ -321,8 +321,11 @@ class DenoisingStage(PipelineStage, RolloutDenoisingMixin):
|
|||||||
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
mode = os.environ.get(
|
dit_config = getattr(self.server_args.pipeline_config, "dit_config", None)
|
||||||
"SGLANG_TORCH_COMPILE_MODE", "max-autotune-no-cudagraphs"
|
mode = os.environ.get("SGLANG_TORCH_COMPILE_MODE") or getattr(
|
||||||
|
dit_config,
|
||||||
|
"torch_compile_mode",
|
||||||
|
"max-autotune-no-cudagraphs",
|
||||||
)
|
)
|
||||||
compile_kwargs["mode"] = mode
|
compile_kwargs["mode"] = mode
|
||||||
logger.info(f"Compiling transformer with mode: {mode}")
|
logger.info(f"Compiling transformer with mode: {mode}")
|
||||||
|
|||||||
+5
-2
@@ -616,8 +616,11 @@ class Hunyuan3DPaintTexGenStage(PipelineStage):
|
|||||||
ddim_timesteps=30,
|
ddim_timesteps=30,
|
||||||
).to(self.device)
|
).to(self.device)
|
||||||
if server_args.enable_torch_compile:
|
if server_args.enable_torch_compile:
|
||||||
compile_mode = os.environ.get(
|
dit_config = getattr(server_args.pipeline_config, "dit_config", None)
|
||||||
"SGLANG_TORCH_COMPILE_MODE", "max-autotune-no-cudagraphs"
|
compile_mode = os.environ.get("SGLANG_TORCH_COMPILE_MODE") or getattr(
|
||||||
|
dit_config,
|
||||||
|
"torch_compile_mode",
|
||||||
|
"max-autotune-no-cudagraphs",
|
||||||
)
|
)
|
||||||
logger.info("Compiling paint transformer with mode: %s", compile_mode)
|
logger.info("Compiling paint transformer with mode: %s", compile_mode)
|
||||||
self.transformer.compile(mode=compile_mode, fullgraph=False, dynamic=None)
|
self.transformer.compile(mode=compile_mode, fullgraph=False, dynamic=None)
|
||||||
|
|||||||
+18
-5
@@ -235,7 +235,12 @@ class MOVADenoisingStage(PipelineStage):
|
|||||||
partial = (1 - guidance_scale) * neg
|
partial = (1 - guidance_scale) * neg
|
||||||
return cfg_model_parallel_all_reduce(partial)
|
return cfg_model_parallel_all_reduce(partial)
|
||||||
|
|
||||||
def _maybe_enable_torch_compile(self, module: nn.Module, server_args: ServerArgs):
|
def _maybe_enable_torch_compile(
|
||||||
|
self,
|
||||||
|
module: nn.Module,
|
||||||
|
server_args: ServerArgs,
|
||||||
|
model_config: object | None = None,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Compile a module with torch.compile, and enable inductor overlap tweak if available.
|
Compile a module with torch.compile, and enable inductor overlap tweak if available.
|
||||||
No-op if torch compile is disabled or the object is not a nn.Module.
|
No-op if torch compile is disabled or the object is not a nn.Module.
|
||||||
@@ -266,8 +271,10 @@ class MOVADenoisingStage(PipelineStage):
|
|||||||
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
_inductor_cfg.reorder_for_compute_comm_overlap = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
mode = os.environ.get(
|
mode = os.environ.get("SGLANG_TORCH_COMPILE_MODE") or getattr(
|
||||||
"SGLANG_TORCH_COMPILE_MODE", "max-autotune-no-cudagraphs"
|
model_config,
|
||||||
|
"torch_compile_mode",
|
||||||
|
"max-autotune-no-cudagraphs",
|
||||||
)
|
)
|
||||||
compile_kwargs["mode"] = mode
|
compile_kwargs["mode"] = mode
|
||||||
logger.info("Compiling %s with mode: %s", module.__class__.__name__, mode)
|
logger.info("Compiling %s with mode: %s", module.__class__.__name__, mode)
|
||||||
@@ -278,8 +285,14 @@ class MOVADenoisingStage(PipelineStage):
|
|||||||
def _maybe_compile_dits(self, server_args: ServerArgs):
|
def _maybe_compile_dits(self, server_args: ServerArgs):
|
||||||
if self._torch_compiled or not server_args.enable_torch_compile:
|
if self._torch_compiled or not server_args.enable_torch_compile:
|
||||||
return
|
return
|
||||||
for module in filter(None, [self.video_dit, self.video_dit_2, self.audio_dit]):
|
module_configs = [
|
||||||
self._maybe_enable_torch_compile(module, server_args)
|
(self.video_dit, server_args.pipeline_config.dit_config),
|
||||||
|
(self.video_dit_2, server_args.pipeline_config.dit_config),
|
||||||
|
(self.audio_dit, server_args.pipeline_config.audio_dit_config),
|
||||||
|
]
|
||||||
|
for module, model_config in module_configs:
|
||||||
|
if module is not None:
|
||||||
|
self._maybe_enable_torch_compile(module, server_args, model_config)
|
||||||
self._torch_compiled = True
|
self._torch_compiled = True
|
||||||
|
|
||||||
def verify_input(self, batch: Req, server_args: ServerArgs) -> VerificationResult:
|
def verify_input(self, batch: Req, server_args: ServerArgs) -> VerificationResult:
|
||||||
|
|||||||
Reference in New Issue
Block a user