[Misc] Merge diffusion forward context (#582)
Signed-off-by: iwzbi <wzbi@zju.edu.cn> Signed-off-by: Hongsheng Liu <liuhongsheng4@huawei.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
1 parent
b414a4d15e
commit
026f613e57
8 files changed
+16
-75
No files matched your search
@@ -5,9 +5,7 @@ import enum
|
||||
import os
|
||||
import random
|
||||
from collections.abc import Callable
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass, field, fields
|
||||
from functools import lru_cache
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
@@ -458,56 +456,6 @@ class OmniDiffusionConfig:
|
||||
return cls(**kwargs)
|
||||
|
||||
|
||||
_current_omni_diffusion_config: OmniDiffusionConfig | None = None
|
||||
_current_prefix: str | None = None
|
||||
|
||||
|
||||
@contextmanager
|
||||
def set_current_omni_diffusion_config(
|
||||
omni_diffusion_config: OmniDiffusionConfig, check_compile=False, prefix: str | None = None
|
||||
):
|
||||
"""
|
||||
Temporarily set the current vLLM-Omni config.
|
||||
Used during model initialization.
|
||||
We save the current vLLM-Omni config in a global variable,
|
||||
so that all modules can access it, e.g. custom ops
|
||||
can access the vLLM-Omni config to determine how to dispatch.
|
||||
"""
|
||||
global _current_omni_diffusion_config, _current_prefix
|
||||
old_omni_diffusion_config = _current_omni_diffusion_config
|
||||
old_prefix = _current_prefix
|
||||
# from vllm.compilation.counter import compilation_counter
|
||||
|
||||
# num_models_seen = compilation_counter.num_models_seen
|
||||
try:
|
||||
_current_omni_diffusion_config = omni_diffusion_config
|
||||
_current_prefix = prefix
|
||||
yield
|
||||
except Exception:
|
||||
raise
|
||||
else:
|
||||
if check_compile:
|
||||
raise RuntimeError("Compilation is not yet supported for OmniDiffusion")
|
||||
finally:
|
||||
_current_omni_diffusion_config = old_omni_diffusion_config
|
||||
_current_prefix = old_prefix
|
||||
# Clear the compilation config cache when context changes
|
||||
get_cached_compilation_config.cache_clear()
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_cached_compilation_config():
|
||||
"""Cache config to avoid repeated calls to get_current_omni_diffusion_config()"""
|
||||
return get_current_omni_diffusion_config().compilation_config
|
||||
|
||||
|
||||
def get_current_omni_diffusion_config() -> OmniDiffusionConfig:
|
||||
if _current_omni_diffusion_config is None:
|
||||
logger.warning_once("Current OmniDiffusionConfig is not set.")
|
||||
return OmniDiffusionConfig()
|
||||
return _current_omni_diffusion_config
|
||||
|
||||
|
||||
@dataclass
|
||||
class DiffusionOutput:
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user