[Perf] Wan2.2 I2V optimization: convert datatype from FP32 to BF16 in vae (#2391)
Signed-off-by: KexiongYu <yukexiong1@huawei.com> Signed-off-by: Canlin Guo <961750412@qq.com> Co-authored-by: Canlin Guo <961750412@qq.com>
This commit is contained in:
1 parent
cb6a8739c1
commit
ec082add35
7 files changed
+123
-11
No files matched your search
@@ -1,12 +1,16 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from contextlib import nullcontext
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
from vllm.logger import init_logger
|
||||
from vllm.platforms import Platform
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
class OmniPlatformEnum(Enum):
|
||||
"""Enum for supported Omni platforms."""
|
||||
@@ -113,6 +117,23 @@ class OmniPlatform(Platform):
|
||||
def get_free_memory(cls, device: torch.device | None = None) -> int:
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def create_autocast_context(
|
||||
cls,
|
||||
*,
|
||||
device_type: str,
|
||||
dtype: torch.dtype,
|
||||
enabled: bool = True,
|
||||
):
|
||||
if not enabled:
|
||||
return nullcontext()
|
||||
|
||||
try:
|
||||
return torch.autocast(device_type=device_type, dtype=dtype, enabled=True)
|
||||
except (RuntimeError, TypeError, ValueError) as exc:
|
||||
logger.warning("autocast unavailable for device_type=%s dtype=%s: %s", device_type, dtype, exc)
|
||||
return nullcontext()
|
||||
|
||||
@classmethod
|
||||
def supports_cpu_offload(cls) -> bool:
|
||||
return True
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from contextlib import nullcontext
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
@@ -106,6 +107,24 @@ class NPUOmniPlatform(OmniPlatform, NPUPlatform):
|
||||
device_props = torch.npu.get_device_properties(device_id)
|
||||
return device_props.total_memory
|
||||
|
||||
@classmethod
|
||||
def create_autocast_context(cls, *, device_type, dtype, enabled=True):
|
||||
if device_type != "npu":
|
||||
return super().create_autocast_context(
|
||||
device_type=device_type,
|
||||
dtype=dtype,
|
||||
enabled=enabled,
|
||||
)
|
||||
if not enabled:
|
||||
return nullcontext()
|
||||
|
||||
# NPU-specific fallback
|
||||
try:
|
||||
return torch.npu.amp.autocast(dtype=dtype)
|
||||
except (RuntimeError, TypeError, ValueError) as exc:
|
||||
logger.warning("autocast unavailable for device_type=%s dtype=%s: %s", device_type, dtype, exc)
|
||||
return nullcontext()
|
||||
|
||||
@classmethod
|
||||
def get_profiler_cls(cls) -> str:
|
||||
return "vllm_omni.platforms.npu.profiler.NPUTorchProfilerWrapper"
|
||||
Reference in new issue
Block a user