Skip to content

[TRTLLM-18143][feat] Add get_env_flag, a strict parser for on/off env switches - #21212

Open
yijingl-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
yijingl-nvidia:user/yijingl/env-flag-parser
Open

yijingl-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
yijingl-nvidia:user/yijingl/env-flag-parser

Conversation

@yijingl-nvidia

@yijingl-nvidia yijingl-nvidia commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR adds get_env_flag(name, default) to tensorrt_llm/_utils.py, one strict parser for on/off environment switches.

Before this PR, each module parsed its switches by hand. Most turned on only for the exact string 1, so X=true meant off. Some used != "0", so X=false meant on. A typo silently picked one of the two paths. get_env_flag reads a switch the same way wherever it is used:

  • Unset or blank returns default.
  • 1/true/yes/on return True, and 0/false/no/off return False, in any case and with surrounding whitespace ignored.
  • Any other value raises a ValueError that names the variable.

This PR changes no existing switch. The Kimi K3 merge-back PRs that follow read their new switches with get_env_flag. The first commit is @hvagadia's from feat/k3_26.08.

Why this PR is smaller than before

The first version of this PR did much more. Besides adding get_env_flag, it moved 182 existing switches in 121 files over to it, read some per-request switches once at startup, and gave TRTLLM_ENABLE_PDL one shared helper. That touched about 195 files across most of the codebase, and GitHub asked for approval from about 15 code owner teams and people. A change that wide is hard to review well in one sitting and close to impossible to get fully approved.

So this PR now only adds the parser. The full conversion is kept in draft #21819. Existing switches will move to get_env_flag a few functions or one module at a time, in small PRs that each need only the owners of the code they touch. The first-round comments on get_env_flag itself are addressed here; the comments on the conversion carry over to #21819.

Test Coverage

1 test file added:

  • tests/unittest/utils/test_get_env_flag.py: CPU only, listed in l0_cpu.yml.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@yijingl-nvidia
yijingl-nvidia force-pushed the user/yijingl/env-flag-parser branch from a0a3c93 to 23046d3 Compare October 29, 2026 22:59
@yijingl-nvidia yijingl-nvidia changed the title [None][feat] Add get_env_flag, a strict parser for boolean env switches [None][feat] Add get_env_flag and read on/off env switches with it Oct 29, 2026
@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81726 [ run ] triggered by Bot. Commit: 23046d3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81726 [ run ] completed with state FAILURE. Commit: 23046d3
/LLM/main/L0_MergeRequest_PR pipeline #67386 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82908 [ run ] triggered by Bot. Commit: 070b062 Link to invocation

@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

All review comments so far are addressed: each of the 56 review threads has a reply and is resolved. The current head, 070b062, is rebased on main, and CI is running on it.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82881 [ run ] completed with state ABORTED. Commit: f2c706d

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82908 [ run ] completed with state SUCCESS. Commit: 070b062
/LLM/main/L0_MergeRequest_PR pipeline #68471 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@yuxianq yuxianq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Attention part LGTM

@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82997 [ run ] triggered by Bot. Commit: d227dd2 Link to invocation

@erictsai-nv erictsai-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

modeling_v2 changes LGTM; they are mechanical and the unset path is unchanged. Nit: qwen4_exp still parses TRTLLM_MODELING_V2_PLE_HOST_OFFLOAD and TRTLLM_MODELING_V2_MOE_PREFILL_COPY by hand.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82997 [ run ] completed with state SUCCESS. Commit: d227dd2
/LLM/main/L0_MergeRequest_PR pipeline #68552 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Either:

  • Wait for the PR to be fully approved — the label is added automatically once approval is complete. Having unresolved open comments is fine, or
  • If needed, ask a member of NVIDIA/trt-llm-ci-approvers to add the label manually.
    Then re-trigger CI with the same bot command (no rebase needed).

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@yijingl-nvidia
yijingl-nvidia force-pushed the user/yijingl/env-flag-parser branch from d227dd2 to bd2434e Compare November 6, 2026 17:50
@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83127 [ run ] triggered by Bot. Commit: bd2434e Link to invocation

hvagadia and others added 2 commits November 6, 2026 10:00
get_env_flag reads an on/off environment variable the same way everywhere.
Unset or blank gives the caller's default, 1/true/yes/on and 0/false/no/off
(any case, surrounding whitespace ignored) give True and False, and any
other value raises a ValueError that names the variable. A typo then fails
loudly instead of silently selecting the other code path.

The Kimi K3 merge-back PRs that follow read their switches with it.

Signed-off-by: Harshil Vagadia <[email protected]>
Signed-off-by: Yijing Li <[email protected]>
- Overloads give get_env_flag(name, True) the type bool, so callers with a
  bool default need no Optional check.
- The docstring lists the args, return values and the ValueError.
- The error message is built from the accepted value lists.
- Tests add type hints, check the whole error message and reject the one-letter
  forms y and t.

Signed-off-by: Yijing Li <[email protected]>
@yijingl-nvidia
yijingl-nvidia force-pushed the user/yijingl/env-flag-parser branch from bd2434e to c62f4ed Compare November 6, 2026 18:13
@yijingl-nvidia yijingl-nvidia removed the api-compatible Accepted LLM API contract change that is backwards-compatible label Nov 6, 2026
@yijingl-nvidia yijingl-nvidia changed the title [None][feat] Add get_env_flag and read on/off env switches with it [None][feat] Add get_env_flag, a strict parser for on/off env switches Nov 6, 2026
@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83137 [ run ] triggered by Bot. Commit: c62f4ed Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83127 [ run ] completed with state ABORTED. Commit: bd2434e

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #83137 [ run ] completed with state SUCCESS. Commit: c62f4ed
/LLM/main/L0_MergeRequest_PR pipeline #68688 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@yijingl-nvidia yijingl-nvidia changed the title [None][feat] Add get_env_flag, a strict parser for on/off env switches [TRTLLM-18143][feat] Add get_env_flag, a strict parser for on/off env switches Nov 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants