[Chore] Try remove init_cached_hf_modules (#31786)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -178,7 +178,6 @@ class WorkerWrapperBase:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vllm_config: VllmConfig,
|
||||
rpc_rank: int = 0,
|
||||
global_rank: int | None = None,
|
||||
) -> None:
|
||||
@@ -194,21 +193,10 @@ class WorkerWrapperBase:
|
||||
"""
|
||||
self.rpc_rank = rpc_rank
|
||||
self.global_rank = self.rpc_rank if global_rank is None else global_rank
|
||||
self.worker: WorkerBase | None = None
|
||||
|
||||
# do not store this `vllm_config`, `init_worker` will set the final
|
||||
# one.
|
||||
# TODO: investigate if we can remove this field in `WorkerWrapperBase`,
|
||||
# `init_cached_hf_modules` should be unnecessary now.
|
||||
self.vllm_config: VllmConfig | None = None
|
||||
|
||||
# `model_config` can be None in tests
|
||||
model_config = vllm_config.model_config
|
||||
if model_config and model_config.trust_remote_code:
|
||||
# note: lazy import to avoid importing torch before initializing
|
||||
from vllm.utils.import_utils import init_cached_hf_modules
|
||||
|
||||
init_cached_hf_modules()
|
||||
# Initialized after init_worker is called
|
||||
self.worker: WorkerBase
|
||||
self.vllm_config: VllmConfig
|
||||
|
||||
def shutdown(self) -> None:
|
||||
if self.worker is not None:
|
||||
@@ -241,27 +229,34 @@ class WorkerWrapperBase:
|
||||
Arguments are passed to the worker class constructor.
|
||||
"""
|
||||
kwargs = all_kwargs[self.rpc_rank]
|
||||
self.vllm_config = kwargs.get("vllm_config")
|
||||
assert self.vllm_config is not None, (
|
||||
|
||||
vllm_config: VllmConfig | None = kwargs.get("vllm_config")
|
||||
assert vllm_config is not None, (
|
||||
"vllm_config is required to initialize the worker"
|
||||
)
|
||||
self.vllm_config.enable_trace_function_call_for_thread()
|
||||
self.vllm_config = vllm_config
|
||||
|
||||
vllm_config.enable_trace_function_call_for_thread()
|
||||
|
||||
from vllm.plugins import load_general_plugins
|
||||
|
||||
load_general_plugins()
|
||||
|
||||
if isinstance(self.vllm_config.parallel_config.worker_cls, str):
|
||||
worker_class = resolve_obj_by_qualname(
|
||||
self.vllm_config.parallel_config.worker_cls
|
||||
parallel_config = vllm_config.parallel_config
|
||||
if isinstance(parallel_config.worker_cls, str):
|
||||
worker_class: type[WorkerBase] = resolve_obj_by_qualname(
|
||||
parallel_config.worker_cls
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
"passing worker_cls is no longer supported. Please pass keep the class in a separate module and pass the qualified name of the class as a string." # noqa: E501
|
||||
"passing worker_cls is no longer supported. "
|
||||
"Please pass keep the class in a separate module "
|
||||
"and pass the qualified name of the class as a string."
|
||||
)
|
||||
if self.vllm_config.parallel_config.worker_extension_cls:
|
||||
|
||||
if parallel_config.worker_extension_cls:
|
||||
worker_extension_cls = resolve_obj_by_qualname(
|
||||
self.vllm_config.parallel_config.worker_extension_cls
|
||||
parallel_config.worker_extension_cls
|
||||
)
|
||||
extended_calls = []
|
||||
if worker_extension_cls not in worker_class.__bases__:
|
||||
@@ -294,7 +289,7 @@ class WorkerWrapperBase:
|
||||
"This argument is needed for mm_processor_cache_type='shm'."
|
||||
)
|
||||
|
||||
mm_config = self.vllm_config.model_config.multimodal_config
|
||||
mm_config = vllm_config.model_config.multimodal_config
|
||||
if mm_config and mm_config.mm_processor_cache_type == "shm":
|
||||
raise ValueError(msg)
|
||||
else:
|
||||
@@ -303,7 +298,7 @@ class WorkerWrapperBase:
|
||||
self.mm_receiver_cache = None
|
||||
else:
|
||||
self.mm_receiver_cache = worker_receiver_cache_from_config(
|
||||
self.vllm_config,
|
||||
vllm_config,
|
||||
MULTIMODAL_REGISTRY,
|
||||
shared_worker_lock,
|
||||
)
|
||||
@@ -311,7 +306,6 @@ class WorkerWrapperBase:
|
||||
with set_current_vllm_config(self.vllm_config):
|
||||
# To make vLLM config available during worker initialization
|
||||
self.worker = worker_class(**kwargs)
|
||||
assert self.worker is not None
|
||||
|
||||
def initialize_from_config(self, kv_cache_configs: list[Any]) -> None:
|
||||
kv_cache_config = kv_cache_configs[self.global_rank]
|
||||
@@ -358,20 +352,15 @@ class WorkerWrapperBase:
|
||||
)
|
||||
|
||||
def execute_model(
|
||||
self,
|
||||
scheduler_output: SchedulerOutput,
|
||||
*args,
|
||||
**kwargs,
|
||||
self, scheduler_output: SchedulerOutput
|
||||
) -> ModelRunnerOutput | AsyncModelRunnerOutput | None:
|
||||
self._apply_mm_cache(scheduler_output)
|
||||
|
||||
assert self.worker is not None
|
||||
return self.worker.execute_model(scheduler_output, *args, **kwargs)
|
||||
return self.worker.execute_model(scheduler_output)
|
||||
|
||||
def reset_mm_cache(self) -> None:
|
||||
mm_receiver_cache = self.mm_receiver_cache
|
||||
if mm_receiver_cache is not None:
|
||||
mm_receiver_cache.clear_cache()
|
||||
|
||||
assert self.worker is not None
|
||||
self.worker.reset_mm_cache()
|
||||
|
||||
Reference in New Issue
Block a user