[Feat] support hsdp for Bagel (#3150)

Signed-off-by: siyuan.lei <siyuanlei37@gmail.com>
Signed-off-by: lsyyyyy <siyuanlei37@gmail.com>
Signed-off-by: 汪志鹏 <wangzhipeng628@gmail.com>
Co-authored-by: 汪志鹏 <wangzhipeng628@gmail.com>
This commit is contained in:
lsyyyyyand汪志鹏 authored and GitHub committed 2026-05-08 15:20:42 +08:00
1 parent ea4cf77f56
commit 32663f21d5
7 files changed
+131 -32

No files matched your search

@@ -34,6 +34,7 @@ from vllm_omni.diffusion.data import OmniDiffusionConfig
from vllm_omni.diffusion.distributed.hsdp import HSDPInferenceConfig
from vllm_omni.diffusion.model_loader.gguf_adapters import get_gguf_adapter
from vllm_omni.diffusion.models.diffusers_adapter.pipeline_diffusers_adapter import DiffusersAdapterPipeline
from vllm_omni.diffusion.offloader.module_collector import ModuleDiscovery
from vllm_omni.diffusion.registry import initialize_model
if TYPE_CHECKING:
@@ -278,7 +279,7 @@ class DiffusersPipelineLoader:
with set_default_torch_dtype(od_config.dtype):
if od_config.parallel_config.use_hsdp:
model = self._load_model_with_hsdp(
od_config, load_format=load_format, custom_pipeline_name=custom_pipeline_name
od_config, target_device=device, load_format=load_format, custom_pipeline_name=custom_pipeline_name
)
else:
with target_device:
@@ -529,6 +530,7 @@ class DiffusersPipelineLoader:
def _load_model_with_hsdp(
self,
od_config: OmniDiffusionConfig,
target_device: torch.device,
load_format: str = "default",
custom_pipeline_name: str | None = None,
) -> nn.Module:
@@ -578,4 +580,19 @@ class DiffusersPipelineLoader:
for name, trans in transformers_to_shard:
logger.debug("Applying HSDP to %s", name)
apply_hsdp_to_model(trans, hsdp_config)
# # HSDP only shards transformer modules. All other runtime modules must
# # be placed on the execution device explicitly after sharding.
discovered_modules = ModuleDiscovery.discover(model)
modules_to_move: list[nn.Module] = []
if discovered_modules.vaes is not None:
modules_to_move.extend(discovered_modules.vaes)
if discovered_modules.encoders is not None:
modules_to_move.extend(discovered_modules.encoders)
if discovered_modules.resident_modules is not None:
modules_to_move.extend(discovered_modules.resident_modules)
for module in modules_to_move:
module.to(target_device)
return model