[Diffusion][Attention] Support per-role attention backend via CLI (#2681)
Signed-off-by: gcanlin <canlinguosdu@gmail.com> Signed-off-by: Hongsheng Liu <liuhongsheng4@huawei.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
1 parent
26d481fc84
commit
11c4c7f0ff
29 files changed
+1262
-106
No files matched your search
@@ -0,0 +1,43 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Global diffusion config — mirrors vLLM's set_current_vllm_config pattern.
|
||||
|
||||
Set once during model initialisation so that every ``Attention`` layer can
|
||||
read the ``OmniDiffusionConfig`` without coupling ``__init__`` to the
|
||||
runtime ``ForwardContext``.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import contextmanager
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm_omni.diffusion.data import OmniDiffusionConfig
|
||||
|
||||
_current_diffusion_config: OmniDiffusionConfig | None = None
|
||||
|
||||
|
||||
@contextmanager
|
||||
def set_current_diffusion_config(config: OmniDiffusionConfig):
|
||||
"""Context manager that sets the global diffusion config for model init."""
|
||||
global _current_diffusion_config
|
||||
old = _current_diffusion_config
|
||||
_current_diffusion_config = config
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
_current_diffusion_config = old
|
||||
|
||||
|
||||
def get_current_diffusion_config() -> OmniDiffusionConfig:
|
||||
"""Return the current diffusion config or raise."""
|
||||
assert _current_diffusion_config is not None, (
|
||||
"Diffusion config is not set. Wrap model construction with set_current_diffusion_config()."
|
||||
)
|
||||
return _current_diffusion_config
|
||||
|
||||
|
||||
def get_current_diffusion_config_or_none() -> OmniDiffusionConfig | None:
|
||||
"""Return the current diffusion config, or ``None`` if not set."""
|
||||
return _current_diffusion_config
|
||||
Reference in new issue
Block a user