Optimize configuration access with LRU cache in custom ops (#22204)

Signed-off-by: zitian zhao <zitian.zhao@tencentmusic.com>
This commit is contained in:
ZiTian.Zhao
2025-08-04 21:43:24 -07:00
committed by GitHub
parent bd3db7f469
commit 4b3e4474d7
2 changed files with 13 additions and 5 deletions
+9 -1
View File
@@ -15,7 +15,7 @@ from collections.abc import Mapping
from contextlib import contextmanager
from dataclasses import (MISSING, Field, asdict, field, fields, is_dataclass,
replace)
from functools import cached_property
from functools import cached_property, lru_cache
from importlib.util import find_spec
from typing import (TYPE_CHECKING, Any, Callable, ClassVar, Literal, Optional,
Protocol, TypeVar, Union, cast, get_args)
@@ -5123,6 +5123,14 @@ def set_current_vllm_config(vllm_config: VllmConfig,
finally:
_current_vllm_config = old_vllm_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_vllm_config()"""
return get_current_vllm_config().compilation_config
def get_current_vllm_config() -> VllmConfig: