Skip to content

[Bugfix] Register VLLM_BATCH_INVARIANT in envs.py to fix spurious unknown env var warning#35007

Merged
yewentao256 merged 32 commits intovllm-project:mainfrom
WindChimeRan:fix/register-batch-invariant-env
Mar 23, 2026
Merged

[Bugfix] Register VLLM_BATCH_INVARIANT in envs.py to fix spurious unknown env var warning#35007
yewentao256 merged 32 commits intovllm-project:mainfrom
WindChimeRan:fix/register-batch-invariant-env

Conversation

@WindChimeRan
Copy link
Copy Markdown
Contributor

@WindChimeRan WindChimeRan commented Feb 21, 2026

Purpose

Register VLLM_BATCH_INVARIANT in envs.py to suppress spurious warning.

VLLM_BATCH_INVARIANT is read via os.getenv() in batch_invariant.py but is never registered in envs.py's environment_variables dict. This causes validate_environ() to emit an "Unknown vLLM environment variable detected" warning every time the feature is used:

WARNING 02-20 23:18:09 [envs.py:1656] Unknown vLLM environment variable detected: VLLM_BATCH_INVARIANT

This PR adds the env var to both the type stub and the registry dict in envs.py.

Test Plan

import os
os.environ["VLLM_BATCH_INVARIANT"] = "1"

from vllm import LLM, SamplingParams

llm = LLM(
    model="Qwen/Qwen3-0.6B",
    max_model_len=128,
    attention_config={"backend": "FLASH_ATTN"},
)
print(llm.generate(["Hello"], SamplingParams(temperature=0, max_tokens=5))[0].outputs[0].text)

Verify no "Unknown vLLM environment variable" warning is emitted.

Test Result

Before: warning is emitted on every invocation with VLLM_BATCH_INVARIANT set.

WARNING 02-20 23:18:09 [envs.py:1656] Unknown vLLM environment variable detected: VLLM_BATCH_INVARIANT

After: no warning.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Signed-off-by: Ranran <1012869439@qq.com>
@dosubot
Copy link
Copy Markdown

dosubot bot commented Feb 21, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@mergify mergify bot added the bug Something isn't working label Feb 21, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request correctly registers the VLLM_BATCH_INVARIANT environment variable in vllm/envs.py to suppress the 'Unknown vLLM environment variable' warning. This is a necessary step for maintaining a clean log output when this feature is used. However, the implementation of the boolean conversion for this variable is less robust than the one it replaces in batch_invariant.py and could lead to a crash if a non-integer value (like 'true') is provided. Additionally, there is now duplicated logic for reading this environment variable between envs.py and batch_invariant.py, which should ideally be consolidated if circular dependencies can be avoided.

vllm/envs.py Outdated
Comment on lines +484 to +486
"VLLM_BATCH_INVARIANT": lambda: bool(
int(os.getenv("VLLM_BATCH_INVARIANT", "0"))
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation using int() will raise a ValueError and crash the application if the environment variable is set to a non-integer value such as "true" or "false". This is a regression in robustness compared to the original implementation in batch_invariant.py which handled this error gracefully. It is recommended to use a more robust parsing pattern consistent with other variables in this file (e.g., VLLM_USE_PRECOMPILED).

Suggested change
"VLLM_BATCH_INVARIANT": lambda: bool(
int(os.getenv("VLLM_BATCH_INVARIANT", "0"))
),
"VLLM_BATCH_INVARIANT": lambda: os.getenv("VLLM_BATCH_INVARIANT", "0")
.strip()
.lower()
in ("1", "true"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is overcomplicating things. my style is consistent with other envs. So it should be fine.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Feb 21, 2026

Hi @WindChimeRan, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work! The idea looks good

Please update the logic in _read_vllm_batch_invariant and related usage

Signed-off-by: ran <hzz5361@psu.edu>
auto-merge was automatically disabled March 22, 2026 22:48

Head branch was pushed to by a user without write access

Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please solve the pre-commit issue so that we can land this pr

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 23, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @WindChimeRan.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Mar 23, 2026
…variant-env

Signed-off-by: ran <hzz5361@psu.edu>
@WindChimeRan WindChimeRan force-pushed the fix/register-batch-invariant-env branch from 03ab562 to 0843198 Compare March 23, 2026 19:59
@mergify mergify bot removed the needs-rebase label Mar 23, 2026
@WindChimeRan
Copy link
Copy Markdown
Contributor Author

@yewentao256 All green!

@yewentao256 yewentao256 merged commit dc6908a into vllm-project:main Mar 23, 2026
91 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Done in NVIDIA Mar 23, 2026
RhizoNymph pushed a commit to RhizoNymph/vllm that referenced this pull request Mar 26, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
HenryTangDev pushed a commit to HenryTangMain/vllm that referenced this pull request Mar 27, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
khairulkabir1661 pushed a commit to khairulkabir1661/vllm that referenced this pull request Mar 27, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Monishver11 pushed a commit to Monishver11/vllm that referenced this pull request Mar 27, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Signed-off-by: Monishver Chandrasekaran <monishverchandrasekaran@gmail.com>
khairulkabir1661 added a commit to khairulkabir1661/vllm that referenced this pull request Mar 27, 2026
Update to match upstream changes from commit dc6908a (vllm-project#35007):
- Remove import of vllm_is_batch_invariant
- Change vllm_is_batch_invariant() to envs.VLLM_BATCH_INVARIANT

This fixes the inconsistency where origin/main uses the envs approach
but our branch was still using the old function call.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Signed-off-by: khairulkabir1661 <khairulkabir1661@users.noreply.github.com>
nithinvc pushed a commit to nithinvc/vllm that referenced this pull request Mar 27, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>

Signed-off-by: Nithin Chalapathi <nithin.ch10@gmail.com>
JiantaoXu pushed a commit to JiantaoXu/vllm that referenced this pull request Mar 28, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
vrdn-23 pushed a commit to vrdn-23/vllm that referenced this pull request Mar 30, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Signed-off-by: Vinay Damodaran <vrdn@hey.com>
EricccYang pushed a commit to EricccYang/vllm that referenced this pull request Apr 1, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Signed-off-by: EricccYang <yangyang4991@gmail.com>
liuchenbing2026 pushed a commit to liuchenbing2026/vllm that referenced this pull request Apr 4, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
rishitdholakia13 pushed a commit to rishitdholakia13/vllm that referenced this pull request Apr 7, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Signed-off-by: rishitdholakia13 <rishit+github@cohere.com>
puririshi98 pushed a commit to puririshi98/vllm that referenced this pull request Apr 7, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Signed-off-by: Rishi Puri <riship@nvidia.com>
big-yellow-duck pushed a commit to EmbeddedLLM/vllm that referenced this pull request Apr 8, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
mtparet pushed a commit to blackfuel-ai/vllm that referenced this pull request Apr 9, 2026
…nown env var warning (vllm-project#35007)

Signed-off-by: Ranran <1012869439@qq.com>
Signed-off-by: Ranran <hzz5361@psu.edu>
Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
WindChimeRan added a commit to vllm-project/vllm-metal that referenced this pull request Apr 11, 2026
similar fix to my upstream PR:
vllm-project/vllm#35007

* register all env vars in a vllm way
* dedicated `envs.py`
* update relevant unit tests


### The problem

**before**: unregistered envs warning
<img width="1168" height="259" alt="image"
src="https://github.com/user-attachments/assets/e447e7cc-d3bc-446e-9f5f-22850223f62b"
/>

**after**: the warning disappeared.

---------

Signed-off-by: ran <hzz5361@psu.edu>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working nvidia ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants