Enable Diffusion Image models asynchronous output (#4981)

Signed-off-by: zzh <943967662@qq.com>
Co-authored-by: dengyunyang <584797741@qq.com>
This commit is contained in:
zzhanddengyunyang authored and GitHub committed 2026-07-29 17:21:55 +00:00
1 parent f2d9eb1630
commit dba05c3517
22 files changed
+1440 -72

No files matched your search

+11
View File
@@ -273,6 +273,17 @@ class CudaOmniPlatform(OmniPlatform, CudaPlatformBase):
def synchronize(cls) -> None:
torch.accelerator.synchronize()
@classmethod
def record_device_event(cls) -> torch.Event | None:
"""Record a device event on the default stream to mark tensor readiness."""
try:
event = torch.Event()
event.record()
return event
except Exception:
logger.warning("Failed to record device event for cross-stream sync")
return None
@classmethod
def get_free_memory(cls, device: torch.device | None = None) -> int:
free, _ = torch.cuda.mem_get_info(device)
+18
View File
@@ -190,6 +190,24 @@ class OmniPlatform(Platform):
def synchronize(cls) -> None:
raise NotImplementedError
# ── Async diffusion output: cross-stream sync ──
@classmethod
def record_device_event(cls):
"""Record a device event on the default stream to mark tensor readiness.
On platforms where distributed communication (e.g. HCCL) may use
internal streams not visible to the default stream, this method
should synchronize the default stream before recording the event
to ensure the event captures all completed work including
cross-device communication results.
Returns ``None`` by default so that platforms without a native
implementation (ROCm, XPU, MUSA) fall through to a safe no-op.
Override in platform subclasses to provide real event support.
"""
return None
@classmethod
def get_free_memory(cls, device: torch.device | None = None) -> int:
raise NotImplementedError
+10
View File
@@ -152,6 +152,16 @@ class MUSAOmniPlatform(OmniPlatform, MUSAPlatformBase):
"""Synchronize all MUSA operations."""
torch.musa.synchronize()
@classmethod
def record_device_event(cls) -> torch.Event | None:
try:
event = torch.musa.Event()
event.record()
return event
except Exception:
logger.warning("Failed to record MUSA device event for cross-stream sync")
return None
@classmethod
def get_free_memory(cls, device: torch.device | None = None) -> int:
free, _ = torch.musa.mem_get_info(device)
+19
View File
@@ -175,6 +175,25 @@ class NPUOmniPlatform(OmniPlatform, NPUPlatform):
def synchronize(cls) -> None:
torch.npu.synchronize()
@classmethod
def record_device_event(cls) -> torch.Event | None:
"""Record a NPU event on the default stream to mark tensor readiness.
On NPU/Ascend with HCCL, distributed communication may use internal
streams not visible to the default stream. Synchronize the default
stream first so that HCCL results are written back before we record
the event, ensuring d2h_stream.wait_event() captures the complete
output data.
"""
try:
torch.npu.current_stream().synchronize()
event = torch.npu.Event()
event.record()
return event
except Exception:
logger.warning("Failed to record NPU event for cross-stream sync")
return None
@classmethod
def get_free_memory(cls, device: torch.device | None = None) -> int:
free, _ = torch.npu.mem_get_info(device)
+10
View File
@@ -145,6 +145,16 @@ class RocmOmniPlatform(OmniPlatform, RocmPlatform):
def synchronize(cls) -> None:
torch.accelerator.synchronize()
@classmethod
def record_device_event(cls) -> torch.Event | None:
try:
event = torch.Event()
event.record()
return event
except Exception:
logger.warning("Failed to record device event for cross-stream sync")
return None
@classmethod
def get_free_memory(cls, device: torch.device | None = None) -> int:
free, _ = torch.cuda.mem_get_info(device)
+10
View File
@@ -99,6 +99,16 @@ class XPUOmniPlatform(OmniPlatform, XPUPlatform):
def synchronize(cls) -> None:
torch.xpu.synchronize()
@classmethod
def record_device_event(cls) -> torch.Event | None:
try:
event = torch.xpu.Event()
event.record()
return event
except Exception:
logger.warning("Failed to record XPU device event for cross-stream sync")
return None
@classmethod
def get_free_memory(cls, device: torch.device | None = None) -> int:
free, _ = torch.xpu.mem_get_info(device)