diff --git a/python/sglang/multimodal_gen/runtime/server_args_auto_tune.py b/python/sglang/multimodal_gen/runtime/server_args_auto_tune.py index 47477af62..8059c9532 100644 --- a/python/sglang/multimodal_gen/runtime/server_args_auto_tune.py +++ b/python/sglang/multimodal_gen/runtime/server_args_auto_tune.py @@ -73,6 +73,17 @@ class ServerArgsAutoTuner: if args.performance_mode == "speed": logger.info("Applying performance_mode=speed") + if 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 measures slower, like short-step Z-Image runs). + args.enable_torch_compile = True + logger.info( + "performance_mode=speed enables torch.compile " + "(pass --enable-torch-compile false to opt out)" + ) if args.num_gpus >= 2 and self._can_apply_fsdp_policy( require_memory_headroom=False ): diff --git a/python/sglang/multimodal_gen/test/unit/test_server_args.py b/python/sglang/multimodal_gen/test/unit/test_server_args.py index e70b8604a..644686b3c 100644 --- a/python/sglang/multimodal_gen/test/unit/test_server_args.py +++ b/python/sglang/multimodal_gen/test/unit/test_server_args.py @@ -1477,6 +1477,40 @@ 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): + 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_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_auto_mode_leaves_torch_compile_off(self): + args = self._from_dict_with_pipeline_config( + QwenImagePipelineConfig(), + kwargs={ + "model_path": "Qwen/Qwen-Image", + "performance_mode": "auto", + }, + ) + + self.assertFalse(args.enable_torch_compile) + def test_memory_mode_wan_uses_layerwise_offload(self): args = self._from_dict_with_pipeline_config( WanT2V480PConfig(),