@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 07cab212f0
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 8, 01:15 UTC

[Misc] Add deprecated environment variable utilities (#33677)

Signed-off-by: carlory <baofa.fan@daocloud.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

杨朱 · Kiki committed Feb 20, 2026 at 13:33 UTC 07cab212f0dcc51cfe4e4f93b58935e8079f26b7
1 file changed +65
vllm/config/utils.py
+65
@@ -7,6 +7,7 @@ import enum
7 import hashlib
8 import inspect
9 import json
10 +import os
11 import pathlib
12 import textwrap
13 from collections.abc import Callable, Mapping, Sequence, Set
@@ -21,6 +22,7 @@ from pydantic.fields import Field as PydanticField
22 from pydantic.fields import FieldInfo
23 from typing_extensions import dataclass_transform, runtime_checkable
24
25 +import vllm.envs as envs
26 from vllm.logger import init_logger
27
28 logger = init_logger(__name__)
@@ -380,3 +382,66 @@ def handle_deprecated(
382
383 for new_name in new_names:
384 setattr(config, new_name, old_val)
385 +
386 +
387 +def get_from_deprecated_env_if_set(
388 + env_name: str,
389 + removal_version: str,
390 + field_name: str | None = None,
391 +) -> str | None:
392 + """
393 + Get value from deprecated environment variable with warning.
394 +
395 + Args:
396 + env_name: Name of the deprecated environment variable
397 + removal_version: Version when it will be removed
398 + field_name: Name of the field to suggest as alternative
399 +
400 + Returns:
401 + The environment variable value if set, None otherwise
402 + """
403 + if envs.is_set(env_name):
404 + value = os.environ.get(env_name)
405 + alt_msg = f" Please use {field_name} instead." if field_name else ""
406 + logger.warning_once(
407 + "Using %s environment variable is deprecated and will be removed in %s.%s",
408 + env_name,
409 + removal_version,
410 + alt_msg,
411 + )
412 + return value
413 + return None
414 +
415 +
416 +def set_from_deprecated_env_if_set(
417 + config: ConfigT,
418 + env_name: str,
419 + removal_version: str,
420 + field_name: str,
421 + to_bool: bool = False,
422 + to_int: bool = False,
423 +) -> None:
424 + """
425 + Set object field from deprecated environment variable with warning.
426 +
427 + Args:
428 + config: Config object to set the field on
429 + env_name: Name of the deprecated environment variable
430 + removal_version: Version when the env var will be removed
431 + field_name: Name of the field to set
432 + to_bool: Whether to convert the environment variable value to boolean
433 + to_int: Whether to convert the environment variable value to integer
434 + Returns:
435 + None
436 + """
437 + if to_bool and to_int:
438 + raise ValueError("Cannot convert to both boolean and integer.")
439 +
440 + env_value = get_from_deprecated_env_if_set(env_name, removal_version, field_name)
441 + if env_value is not None:
442 + field_value: str | bool | int = env_value
443 + if to_bool:
444 + field_value = env_value.lower() in ("1", "true")
445 + elif to_int:
446 + field_value = int(env_value)
447 + setattr(config, field_name, field_value)