From c83c84b422a96d46460de60c18fa4c5427d6a444 Mon Sep 17 00:00:00 2001 From: Mick Date: Mon, 5 Oct 2026 21:56:52 +0800 Subject: [PATCH] [diffusion] chore: keep the DiT off component offload under explicit multi-GPU fsdp (#41722) Co-authored-by: Mick Qian Co-authored-by: Claude Opus 5.5 --- docs/cookbook/diffusion/Wan/Wan2.1.mdx | 2 +- docs/cookbook/diffusion/Wan/Wan2.2.mdx | 2 +- .../runtime/server_args/server_args.py | 15 ++++++- .../test/unit/test_server_args.py | 43 +++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/docs/cookbook/diffusion/Wan/Wan2.1.mdx b/docs/cookbook/diffusion/Wan/Wan2.1.mdx index 2c56405263..184de039f7 100644 --- a/docs/cookbook/diffusion/Wan/Wan2.1.mdx +++ b/docs/cookbook/diffusion/Wan/Wan2.1.mdx @@ -121,7 +121,7 @@ SGLANG_CACHE_DIT_ENABLED=true sglang serve --model-path Wan-AI/Wan2.1-T2V-14B-Di #### 4.2.2 GPU Optimization -- `--dit-cpu-offload`: Use CPU offload for DiT inference. Enable if you run out of memory with FSDP. +- `--dit-cpu-offload`: Keep DiT weights on the CPU and move them onto the GPU whole around each use. This takes the DiT out of FSDP, which shards only resident components. - `--text-encoder-cpu-offload`: Use CPU offload for text encoder inference. - `--image-encoder-cpu-offload`: Use CPU offload for image encoder inference. - `--vae-cpu-offload`: Use CPU offload for VAE. diff --git a/docs/cookbook/diffusion/Wan/Wan2.2.mdx b/docs/cookbook/diffusion/Wan/Wan2.2.mdx index a24355ed30..3ee5618663 100644 --- a/docs/cookbook/diffusion/Wan/Wan2.2.mdx +++ b/docs/cookbook/diffusion/Wan/Wan2.2.mdx @@ -212,7 +212,7 @@ sglang serve --model-path Wan-AI/Wan2.2-T2V-A14B-Diffusers #### 4.2.2 GPU Optimization -- `--dit-cpu-offload`: Use CPU offload for DiT inference. Enable if run out of memory with FSDP. +- `--dit-cpu-offload`: Keep DiT weights on the CPU and move them onto the GPU whole around each use. This takes the DiT out of FSDP, which shards only resident components. - `--text-encoder-cpu-offload`: Use CPU offload for text encoder inference. Enable if run out of memory with FSDP. - `--image-encoder-cpu-offload`: Use CPU offload for image encoder inference. Enable if run out of memory with FSDP. - `--vae-cpu-offload`: Use CPU offload for VAE. Enable if run out of memory. diff --git a/python/sglang/multimodal_gen/runtime/server_args/server_args.py b/python/sglang/multimodal_gen/runtime/server_args/server_args.py index ec22ef221d..6c53bb968d 100644 --- a/python/sglang/multimodal_gen/runtime/server_args/server_args.py +++ b/python/sglang/multimodal_gen/runtime/server_args/server_args.py @@ -940,6 +940,18 @@ class ServerArgs(DisaggServerArgsMixin): self.vae_cpu_offload = False return + if ( + self.use_fsdp_inference + and self.num_gpus > 1 + # with data parallelism the FSDP mesh would span the replicas + and self.dp_size == 1 + and self.dit_cpu_offload is None + # a GGUF or pre-quantized override may not support FSDP + and self.transformer_weights_path is None + ): + # FSDP shards only resident components; component offload would bypass it + self.dit_cpu_offload = False + # TODO: to be handled by each platform if current_platform.get_device_total_memory() / BYTES_PER_GB < 30: logger.info( @@ -2536,7 +2548,8 @@ class ServerArgs(DisaggServerArgsMixin): parser.add_argument( "--dit-cpu-offload", action=StoreBoolean, - help="Use CPU offload for DiT inference. Enable if run out of memory with FSDP.", + help="Keep DiT weights on the CPU and move them onto the GPU whole around each " + "use. This takes the DiT out of FSDP, which shards only resident components.", ) parser.add_argument( "--direct-gpu-weight-loading", 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 bf39dd91b3..0185511e1f 100644 --- a/python/sglang/multimodal_gen/test/unit/test_server_args.py +++ b/python/sglang/multimodal_gen/test/unit/test_server_args.py @@ -2156,6 +2156,49 @@ class TestOffloadDefaults(unittest.TestCase): ) self.assertTrue(args.use_fsdp_inference) + def test_explicit_multi_gpu_fsdp_keeps_the_dit_out_of_component_offload(self): + """Explicit multi-GPU FSDP shards the DiT unless its placement is set explicitly.""" + for dit_cpu_offload in (None, True): + with self.subTest(dit_cpu_offload=dit_cpu_offload): + kwargs = { + "model_path": "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers", + "num_gpus": 2, + "performance_mode": "auto", + "use_fsdp_inference": True, + } + if dit_cpu_offload is not None: + kwargs["dit_cpu_offload"] = dit_cpu_offload + args = self._from_dict_with_pipeline_config( + WanI2V480PConfig(), memory_gb=24, kwargs=kwargs + ) + + self.assertTrue(args.use_fsdp_inference) + self.assertEqual(args.dit_cpu_offload, dit_cpu_offload is True) + self.assertEqual( + args.should_use_fsdp_for_component("transformer"), + dit_cpu_offload is None, + ) + + def test_explicit_fsdp_keeps_the_dit_offload_default_where_it_cannot_shard(self): + for kwargs in ( + {"dp_size": 2}, + {"transformer_weights_path": "/models/wan-14b-q4.gguf"}, + ): + with self.subTest(**kwargs): + args = self._from_dict_with_pipeline_config( + WanI2V480PConfig(), + memory_gb=24, + kwargs={ + "model_path": "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers", + "num_gpus": 2, + "performance_mode": "auto", + "use_fsdp_inference": True, + **kwargs, + }, + ) + + self.assertTrue(args.dit_cpu_offload) + def test_auto_wan_layerwise_offload_preserves_explicit_dit_cpu_offload(self): args = self._from_dict_with_pipeline_config( WanT2V480PConfig(),