[Diffusion] Integrate no-AllGather DLO with Host Weight Runtime (#6486)
Signed-off-by: Hongsheng Liu <liuhongsheng4@huawei.com> Signed-off-by: hsliuustc0106 <hsliuustc0106@users.noreply.github.com> Co-authored-by: hsliuustc0106 <hsliuustc0106@users.noreply.github.com>
This commit is contained in:
1 parent
8fdb719a41
commit
8360346a66
27 files changed
+1640
-51
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
import torch
|
||||
from vllm.logger import init_logger
|
||||
@@ -25,6 +25,7 @@ from .sequential_backend import (
|
||||
remove_sequential_offload,
|
||||
sequential_offload_component,
|
||||
)
|
||||
from .startup import OffloadStartupState, take_offload_startup_state
|
||||
from .tensor_utils import (
|
||||
dtype_size,
|
||||
is_dtensor,
|
||||
@@ -52,6 +53,9 @@ __all__ = [
|
||||
"apply_distributed_block_hook",
|
||||
"remove_distributed_block_hook",
|
||||
"get_offload_backend",
|
||||
"enable_offload_backend",
|
||||
"OffloadStartupState",
|
||||
"take_offload_startup_state",
|
||||
"get_offload_plan",
|
||||
"get_blocks_attr_names",
|
||||
"get_blocks_from_dit",
|
||||
@@ -137,3 +141,55 @@ def get_offload_backend(
|
||||
else:
|
||||
logger.error("Unknown offload strategy: %s", config.strategy)
|
||||
return None
|
||||
|
||||
|
||||
def enable_offload_backend(
|
||||
od_config: OmniDiffusionConfig,
|
||||
pipeline: torch.nn.Module,
|
||||
device: torch.device | None = None,
|
||||
) -> tuple[torch.nn.Module, OffloadBackend | None]:
|
||||
"""Create and enable the loader-selected backend transactionally.
|
||||
|
||||
The model runner only calls this generic offloader boundary. Loader-owned
|
||||
host plans and optional fresh-model recovery callbacks stay inside the
|
||||
startup state consumed here.
|
||||
"""
|
||||
|
||||
def enable_once(model: torch.nn.Module, state: OffloadStartupState | None) -> OffloadBackend | None:
|
||||
backend: OffloadBackend | None = None
|
||||
try:
|
||||
backend = get_offload_backend(
|
||||
od_config,
|
||||
device=device,
|
||||
host_weight_plan=state.host_weight_plan if state is not None else None,
|
||||
)
|
||||
if backend is not None:
|
||||
logger.info("Enabling offloader backend: %s", backend.__class__.__name__)
|
||||
backend.enable(model)
|
||||
elif state is not None:
|
||||
state.close_loader_ownership()
|
||||
return backend
|
||||
except Exception:
|
||||
if backend is not None:
|
||||
try:
|
||||
backend.disable()
|
||||
except Exception:
|
||||
logger.exception("Failed to clean up the offload backend after startup failure")
|
||||
if state is not None:
|
||||
state.close_loader_ownership()
|
||||
raise
|
||||
|
||||
startup_state = take_offload_startup_state(pipeline)
|
||||
try:
|
||||
return pipeline, enable_once(pipeline, startup_state)
|
||||
except Exception:
|
||||
if startup_state is None or not startup_state.allow_fresh_retry:
|
||||
raise
|
||||
assert startup_state.fresh_model_loader is not None
|
||||
logger.warning(
|
||||
"Loader-backed offload startup failed; retrying with a fresh canonical model",
|
||||
exc_info=True,
|
||||
)
|
||||
del pipeline
|
||||
pipeline = startup_state.fresh_model_loader()
|
||||
return pipeline, enable_once(pipeline, take_offload_startup_state(pipeline))
|
||||
Reference in new issue
Block a user