[Feat][Diffusion]: Implement Component-Level VRAM Quota and Resource Domain Isolation (#1582)
Signed-off-by: vensen <vensenmu@gmail.com>
This commit is contained in:
1 parent
0e005817f7
commit
3306fa6611
3 files changed
+133
-2
No files matched your search
@@ -313,6 +313,63 @@ class OmniBase:
|
||||
|
||||
return config_path, stage_configs
|
||||
|
||||
def _coordinate_vram_resources(self) -> None:
|
||||
"""
|
||||
Coordinate VRAM resource reservations across stages based on their type and configs.
|
||||
Note: Current implementation supports per-device isolation. Advanced multi-GPU
|
||||
scenarios like TP or PP are planned as sleep mode ack Test Scenario.
|
||||
"""
|
||||
import torch
|
||||
from vllm.utils.mem_utils import GiB_bytes
|
||||
|
||||
from vllm_omni.diffusion.worker.diffusion_worker import DiffusionWorker
|
||||
|
||||
# Device ID
|
||||
reserved_gb_per_device: dict[int, float] = {}
|
||||
active_configs = self.stage_configs
|
||||
if hasattr(self, "_single_stage_id") and self._single_stage_id is not None:
|
||||
active_configs = [cfg for cfg in self.stage_configs if cfg.stage_id == self._single_stage_id]
|
||||
for cfg in active_configs:
|
||||
s_type = getattr(cfg, "stage_type", None)
|
||||
if s_type == "diffusion":
|
||||
prediction = DiffusionWorker.predict_resource_usage(cfg.engine_args)
|
||||
device_str = getattr(cfg.runtime, "devices", "0")
|
||||
try:
|
||||
devices = [int(d.strip()) for d in device_str.split(",")]
|
||||
except (ValueError, AttributeError):
|
||||
devices = [0]
|
||||
for d_id in devices:
|
||||
reserved_gb_per_device[d_id] = reserved_gb_per_device.get(d_id, 0.0) + prediction["total_gb"]
|
||||
logger.info(
|
||||
f"[Coordinator] Stage-{cfg.stage_id} ({s_type.capitalize()}) "
|
||||
f"on devices {devices} predicted budget: {prediction['total_gb']:.2f} GiB"
|
||||
)
|
||||
if not torch.cuda.is_available():
|
||||
# TODO: Add support for other accelerators (NPU/XPU)
|
||||
# as their specific memory management APIs are integrated.
|
||||
return
|
||||
for cfg in active_configs:
|
||||
if getattr(cfg, "stage_type", None) == "llm":
|
||||
# Get the master device ID where the LLM is located
|
||||
llm_device_str = getattr(cfg.runtime, "devices", "0")
|
||||
try:
|
||||
target_device = int(llm_device_str.split(",")[0].strip())
|
||||
except (ValueError, AttributeError):
|
||||
target_device = 0
|
||||
# The physical total of the card containing LLM
|
||||
physical_vram_gb = torch.cuda.get_device_properties(target_device).total_memory / GiB_bytes
|
||||
total_reserved_on_this_device = reserved_gb_per_device.get(target_device, 0.0)
|
||||
if total_reserved_on_this_device > 0:
|
||||
original_util = cfg.engine_args.get("gpu_memory_utilization", 0.9)
|
||||
reserved_util_ratio = total_reserved_on_this_device / physical_vram_gb
|
||||
adjusted_util = min(0.95, original_util + reserved_util_ratio)
|
||||
cfg.engine_args["gpu_memory_utilization"] = round(adjusted_util, 3)
|
||||
logger.info(
|
||||
f"[Coordinator] LLM Stage-{cfg.stage_id} on Device {target_device} dynamic boost: "
|
||||
f"{original_util} -> {cfg.engine_args['gpu_memory_utilization']} "
|
||||
f"(Compensating {reserved_util_ratio:.2f} ratio for resource domain isolation)"
|
||||
)
|
||||
|
||||
def _initialize_stages(self, model: str, kwargs: dict[str, Any]) -> None:
|
||||
"""Initialize stage list management."""
|
||||
self._inline_diffusion = False
|
||||
@@ -335,6 +392,9 @@ class OmniBase:
|
||||
# Resolve stage configs shared by orchestrator/headless paths.
|
||||
self.config_path, self.stage_configs = self._resolve_stage_configs(model, kwargs)
|
||||
|
||||
# This ensures all engines receive the corrected gpu_memory_utilization through engine_args.
|
||||
self._coordinate_vram_resources()
|
||||
|
||||
# Initialize connectors
|
||||
self.omni_transfer_config, self.connectors = initialize_orchestrator_connectors(
|
||||
self.config_path, worker_backend=worker_backend, shm_threshold_bytes=shm_threshold_bytes
|
||||
|
||||
Reference in new issue
Block a user