[diffusion] chore: make torch.compile opt-in for speed mode (#34173)
This commit is contained in:
@@ -25,9 +25,9 @@ class ModelDeploymentConfig:
|
||||
auto_enable_cfg_parallel: bool = True
|
||||
# degree 1 keeps CFG parallel disabled and leaves GPUs available for SP
|
||||
auto_cfg_parallel_degree_by_num_gpus: tuple[tuple[int, int], ...] = ()
|
||||
# Let performance_mode=speed opt into torch.compile unless the model has
|
||||
# established that the compiled path changes its numerical contract.
|
||||
speed_mode_enable_torch_compile_by_default: bool = True
|
||||
# torch.compile is model opt-in because it can be slower than eager for
|
||||
# diffusion workloads dominated by already-optimized kernels
|
||||
speed_mode_enable_torch_compile_by_default: bool = False
|
||||
supports_cfg_parallel: bool = True
|
||||
|
||||
def get_auto_cfg_parallel_degree(self, num_gpus: int) -> int:
|
||||
|
||||
@@ -78,9 +78,7 @@ class ServerArgsAutoTuner:
|
||||
and not args.enable_torch_compile
|
||||
and not args.is_arg_explicitly_set("enable_torch_compile")
|
||||
):
|
||||
# speed means fastest: compile by default. An explicit
|
||||
# --enable-torch-compile false still wins (e.g. models where
|
||||
# compile is slower or changes the numerical contract).
|
||||
# only models with a validated compile win opt in by default
|
||||
args.enable_torch_compile = True
|
||||
logger.info(
|
||||
"performance_mode=speed enables torch.compile "
|
||||
|
||||
@@ -24,6 +24,9 @@ from sglang.multimodal_gen.configs.pipeline_configs.ltx_2 import (
|
||||
from sglang.multimodal_gen.configs.pipeline_configs.minimax_h3 import (
|
||||
MiniMaxH3PipelineConfig,
|
||||
)
|
||||
from sglang.multimodal_gen.configs.pipeline_configs.model_deployment_config import (
|
||||
ModelDeploymentConfig,
|
||||
)
|
||||
from sglang.multimodal_gen.configs.pipeline_configs.mova import MOVAPipelineConfig
|
||||
from sglang.multimodal_gen.configs.pipeline_configs.qwen_image import (
|
||||
QwenImagePipelineConfig,
|
||||
@@ -1590,7 +1593,7 @@ class TestOffloadDefaults(unittest.TestCase):
|
||||
self.assertFalse(args.text_encoder_cpu_offload)
|
||||
self.assertFalse(args.image_encoder_cpu_offload)
|
||||
|
||||
def test_speed_mode_enables_torch_compile_by_default(self):
|
||||
def test_speed_mode_keeps_torch_compile_off_by_default(self):
|
||||
args = self._from_dict_with_pipeline_config(
|
||||
QwenImagePipelineConfig(),
|
||||
kwargs={
|
||||
@@ -1599,20 +1602,40 @@ class TestOffloadDefaults(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
self.assertTrue(args.enable_torch_compile)
|
||||
|
||||
def test_speed_mode_preserves_explicit_torch_compile_off(self):
|
||||
args = self._from_dict_with_pipeline_config(
|
||||
QwenImagePipelineConfig(),
|
||||
kwargs={
|
||||
"model_path": "Qwen/Qwen-Image",
|
||||
"performance_mode": "speed",
|
||||
"enable_torch_compile": False,
|
||||
},
|
||||
)
|
||||
|
||||
self.assertFalse(args.enable_torch_compile)
|
||||
|
||||
def test_speed_mode_preserves_explicit_torch_compile_setting(self):
|
||||
for enabled in (False, True):
|
||||
with self.subTest(enabled=enabled):
|
||||
args = self._from_dict_with_pipeline_config(
|
||||
QwenImagePipelineConfig(),
|
||||
kwargs={
|
||||
"model_path": "Qwen/Qwen-Image",
|
||||
"performance_mode": "speed",
|
||||
"enable_torch_compile": enabled,
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(args.enable_torch_compile, enabled)
|
||||
|
||||
def test_speed_mode_honors_model_torch_compile_opt_in(self):
|
||||
with patch.object(
|
||||
QwenImagePipelineConfig,
|
||||
"get_model_deployment_config",
|
||||
return_value=ModelDeploymentConfig(
|
||||
speed_mode_enable_torch_compile_by_default=True
|
||||
),
|
||||
):
|
||||
args = self._from_dict_with_pipeline_config(
|
||||
QwenImagePipelineConfig(),
|
||||
kwargs={
|
||||
"model_path": "Qwen/Qwen-Image",
|
||||
"performance_mode": "speed",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertTrue(args.enable_torch_compile)
|
||||
|
||||
def test_speed_mode_uses_minimax_h3_compile_policy(self):
|
||||
for explicit, expected in ((None, False), (True, True)):
|
||||
kwargs = {
|
||||
|
||||
Reference in New Issue
Block a user