Skip to content

Commit f01d066

Browse files
wangxiyuanSzymonOzog
authored andcommitted
[Platform] add pre_register_and_update function (vllm-project#12432)
Signed-off-by: wangxiyuan <[email protected]> Signed-off-by: SzymonOzog <[email protected]>
1 parent e80ff77 commit f01d066

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

vllm/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3063,7 +3063,8 @@ class VllmConfig:
30633063
kv_transfer_config: KVTransferConfig = field(default=None,
30643064
init=True) # type: ignore
30653065
# some opaque config, only used to provide additional information
3066-
# for the hash computation, mainly used for testing and debugging.
3066+
# for the hash computation, mainly used for testing, debugging or out of
3067+
# tree config registration.
30673068
additional_config: SupportsHash = field(default=None,
30683069
init=True) # type: ignore
30693070
instance_id: str = ""

vllm/engine/arg_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from vllm.executor.executor_base import ExecutorBase
2121
from vllm.logger import init_logger
2222
from vllm.model_executor.layers.quantization import QUANTIZATION_METHODS
23+
from vllm.plugins import load_general_plugins
2324
from vllm.transformers_utils.utils import check_gguf_file
2425
from vllm.usage.usage_lib import UsageContext
2526
from vllm.utils import FlexibleArgumentParser, StoreBoolean
@@ -204,6 +205,8 @@ class EngineArgs:
204205

205206
calculate_kv_scales: Optional[bool] = None
206207

208+
additional_config: Optional[Dict[str, Any]] = None
209+
207210
def __post_init__(self):
208211
if not self.tokenizer:
209212
self.tokenizer = self.model
@@ -985,6 +988,14 @@ def add_cli_args(parser: FlexibleArgumentParser) -> FlexibleArgumentParser:
985988
'be loaded from the model checkpoint if available. '
986989
'Otherwise, the scales will default to 1.0.')
987990

991+
parser.add_argument(
992+
"--additional-config",
993+
type=json.loads,
994+
default=None,
995+
help="Additional config for specified platform in JSON format. "
996+
"Different platforms may support different configs. Make sure the "
997+
"configs are valid for the platform you are using. The input format"
998+
" is like '{\"config_key\":\"config_value\"}'")
988999
return parser
9891000

9901001
@classmethod
@@ -1046,6 +1057,9 @@ def create_load_config(self) -> LoadConfig:
10461057
def create_engine_config(self,
10471058
usage_context: Optional[UsageContext] = None
10481059
) -> VllmConfig:
1060+
from vllm.platforms import current_platform
1061+
current_platform.pre_register_and_update()
1062+
10491063
if envs.VLLM_USE_V1:
10501064
self._override_v1_engine_args(usage_context)
10511065

@@ -1289,6 +1303,7 @@ def create_engine_config(self,
12891303
prompt_adapter_config=prompt_adapter_config,
12901304
compilation_config=self.compilation_config,
12911305
kv_transfer_config=self.kv_transfer_config,
1306+
additional_config=self.additional_config,
12921307
)
12931308

12941309
if envs.VLLM_USE_V1:
@@ -1349,6 +1364,12 @@ def add_cli_args(parser: FlexibleArgumentParser,
13491364
parser.add_argument('--disable-log-requests',
13501365
action='store_true',
13511366
help='Disable logging requests.')
1367+
# Initialize plugin to update the parser, for example, The plugin may
1368+
# adding a new kind of quantization method to --quantization argument or
1369+
# a new device to --device argument.
1370+
load_general_plugins()
1371+
from vllm.platforms import current_platform
1372+
current_platform.pre_register_and_update(parser)
13521373
return parser
13531374

13541375

vllm/platforms/interface.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
if TYPE_CHECKING:
1515
from vllm.config import VllmConfig
16+
from vllm.utils import FlexibleArgumentParser
1617
else:
1718
VllmConfig = None
19+
FlexibleArgumentParser = None
1820

1921
logger = init_logger(__name__)
2022

@@ -223,6 +225,22 @@ def seed_everything(cls, seed: Optional[int] = None) -> None:
223225
np.random.seed(seed)
224226
torch.manual_seed(seed)
225227

228+
@classmethod
229+
def pre_register_and_update(cls,
230+
parser: Optional[FlexibleArgumentParser] = None
231+
) -> None:
232+
"""
233+
Do some pre-registeration or update action for the current platform.
234+
235+
This function is called before global VllmConfig is initialized or cli
236+
arguments are parsed. It's used for out-of-tree platforms to register or
237+
update the configuration.
238+
239+
For example, the out-of-tree quantization config can be imported and
240+
registered here dynamically.
241+
"""
242+
pass
243+
226244
@classmethod
227245
def check_and_update_config(cls, vllm_config: VllmConfig) -> None:
228246
"""

0 commit comments

Comments
 (0)