From f0ca0671c70fae6d1562127e3330eeaedf4abb3f Mon Sep 17 00:00:00 2001 From: Gregory Shtrasberg <156009573+gshtras@users.noreply.github.com> Date: Tue, 10 Feb 2026 15:45:38 -0600 Subject: [PATCH] [Feature] Warn about unrecognized environment variables (#33581) Signed-off-by: Gregory Shtrasberg --- tests/config/test_config_generation.py | 24 ++++++++++++++++++++++++ vllm/engine/arg_utils.py | 12 ++++++++++++ vllm/envs.py | 9 +++++++++ 3 files changed, 45 insertions(+) diff --git a/tests/config/test_config_generation.py b/tests/config/test_config_generation.py index 23ceb920ca..225ac0f222 100644 --- a/tests/config/test_config_generation.py +++ b/tests/config/test_config_generation.py @@ -78,3 +78,27 @@ def test_ray_runtime_env(monkeypatch: pytest.MonkeyPatch): ) ray.shutdown() + + +def test_unrecognized_env(): + import os + + # Test that if fail_on_environ_validation is True, then an error + # is raised when an unrecognized vLLM environment variable is set + os.environ["VLLM_UNRECOGNIZED_ENV_VAR"] = "some_value" + engine_args = EngineArgs( + fail_on_environ_validation=True, + ) + with pytest.raises(ValueError, match="Unknown vLLM environment variable detected"): + engine_args.create_engine_config() + + # Test that if fail_on_environ_validation is False, then no error is raised + engine_args = EngineArgs() + engine_args.create_engine_config() + + # Test that when the unrecognized env var is removed, no error is raised + os.environ.pop("VLLM_UNRECOGNIZED_ENV_VAR", None) + engine_args = EngineArgs( + fail_on_environ_validation=True, + ) + engine_args.create_engine_config() diff --git a/vllm/engine/arg_utils.py b/vllm/engine/arg_utils.py index c7c78ffd8e..2d1e2feb9b 100644 --- a/vllm/engine/arg_utils.py +++ b/vllm/engine/arg_utils.py @@ -593,6 +593,8 @@ class EngineArgs: "weight_transfer_config", ) + fail_on_environ_validation: bool = False + def __post_init__(self): # support `EngineArgs(compilation_config={...})` # without having to manually construct a @@ -1239,6 +1241,14 @@ class EngineArgs: help="Log aggregate rather than per-engine statistics " "when using data parallelism.", ) + + parser.add_argument( + "--fail-on-environ-validation", + help="If set, the engine will raise an error if " + "environment validation fails.", + default=False, + action=argparse.BooleanOptionalAction, + ) return parser @classmethod @@ -1396,6 +1406,8 @@ class EngineArgs: device_config = DeviceConfig(device=cast(Device, current_platform.device_type)) + envs.validate_environ(self.fail_on_environ_validation) + # Check if the model is a speculator and override model/tokenizer/config # BEFORE creating ModelConfig, so the config is created with the target model # Skip speculator detection for cloud storage models (eg: S3, GCS) since diff --git a/vllm/envs.py b/vllm/envs.py index 3af85be0a1..314f427588 100755 --- a/vllm/envs.py +++ b/vllm/envs.py @@ -1606,6 +1606,15 @@ def is_set(name: str): raise AttributeError(f"module {__name__!r} has no attribute {name!r}") +def validate_environ(hard_fail: bool) -> None: + for env in os.environ: + if env.startswith("VLLM_") and env not in environment_variables: + if hard_fail: + raise ValueError(f"Unknown vLLM environment variable detected: {env}") + else: + logger.warning("Unknown vLLM environment variable detected: %s", env) + + def compile_factors() -> dict[str, object]: """Return env vars used for torch.compile cache keys.