[RLHF] use worker_extension_cls for compatibility with V0 and V1 (#14185)
Signed-off-by: youkaichao <youkaichao@gmail.com>
This commit is contained in:
@@ -1366,6 +1366,7 @@ class ParallelConfig:
|
||||
# will be determined based on the platform.
|
||||
worker_cls: str = "auto"
|
||||
sd_worker_cls: str = "auto"
|
||||
worker_extension_cls: str = ""
|
||||
|
||||
# world_size is TPxPP, it affects the number of workers we create.
|
||||
world_size: int = field(init=False)
|
||||
@@ -1523,6 +1524,9 @@ class ParallelConfig:
|
||||
raise ValueError("Unable to use nsight profiling unless workers "
|
||||
"run with Ray.")
|
||||
|
||||
assert isinstance(self.worker_extension_cls, str), (
|
||||
"worker_extension_cls must be a string (qualified class name).")
|
||||
|
||||
|
||||
@dataclass
|
||||
class SchedulerConfig:
|
||||
|
||||
@@ -202,6 +202,7 @@ class EngineArgs:
|
||||
override_pooler_config: Optional[PoolerConfig] = None
|
||||
compilation_config: Optional[CompilationConfig] = None
|
||||
worker_cls: str = "auto"
|
||||
worker_extension_cls: str = ""
|
||||
|
||||
kv_transfer_config: Optional[KVTransferConfig] = None
|
||||
|
||||
@@ -1015,6 +1016,13 @@ class EngineArgs:
|
||||
type=str,
|
||||
default="auto",
|
||||
help='The worker class to use for distributed execution.')
|
||||
parser.add_argument(
|
||||
'--worker-extension-cls',
|
||||
type=str,
|
||||
default="",
|
||||
help='The worker extension class on top of the worker cls, '
|
||||
'it is useful if you just want to add new functions to the worker '
|
||||
'class without changing the existing functions.')
|
||||
parser.add_argument(
|
||||
"--generation-config",
|
||||
type=nullable_str,
|
||||
@@ -1209,6 +1217,7 @@ class EngineArgs:
|
||||
ray_workers_use_nsight=self.ray_workers_use_nsight,
|
||||
distributed_executor_backend=self.distributed_executor_backend,
|
||||
worker_cls=self.worker_cls,
|
||||
worker_extension_cls=self.worker_extension_cls,
|
||||
)
|
||||
|
||||
max_model_len = model_config.max_model_len
|
||||
|
||||
@@ -558,10 +558,37 @@ class WorkerWrapperBase:
|
||||
worker_class = resolve_obj_by_qualname(
|
||||
self.vllm_config.parallel_config.worker_cls)
|
||||
else:
|
||||
logger.warning(
|
||||
"passing worker_cls as a class object is strongly deprecated,"
|
||||
" as the serialization of class objects can be tricky and"
|
||||
" error-prone. To be safe, please keep the class in a separate"
|
||||
" module and pass the qualified name of the class as a string."
|
||||
)
|
||||
assert isinstance(self.vllm_config.parallel_config.worker_cls,
|
||||
bytes)
|
||||
worker_class = cloudpickle.loads(
|
||||
self.vllm_config.parallel_config.worker_cls)
|
||||
if self.vllm_config.parallel_config.worker_extension_cls:
|
||||
worker_extension_cls = resolve_obj_by_qualname(
|
||||
self.vllm_config.parallel_config.worker_extension_cls)
|
||||
extended_calls = []
|
||||
if worker_extension_cls not in worker_class.__bases__:
|
||||
# check any conflicts between worker and worker_extension_cls
|
||||
for attr in dir(worker_extension_cls):
|
||||
if attr.startswith("__"):
|
||||
continue
|
||||
assert not hasattr(worker_class, attr), (
|
||||
f"Worker class {worker_class} already has an attribute"
|
||||
f" {attr}, which conflicts with the worker"
|
||||
f" extension class {worker_extension_cls}.")
|
||||
if callable(getattr(worker_extension_cls, attr)):
|
||||
extended_calls.append(attr)
|
||||
# dynamically inherit the worker extension class
|
||||
worker_class.__bases__ = worker_class.__bases__ + (
|
||||
worker_extension_cls, )
|
||||
logger.info(
|
||||
"Injected %s into %s for extended collective_rpc calls %s",
|
||||
worker_extension_cls, worker_class, extended_calls)
|
||||
with set_current_vllm_config(self.vllm_config):
|
||||
# To make vLLM config available during worker initialization
|
||||
self.worker = worker_class(**kwargs)
|
||||
|
||||
Reference in New Issue
Block a user