Skip to content

Polygraphy - fix POLYGRAPHY_ASK_BEFORE_INSTALL=0 still enabling the install prompt - #4836

Open
VaggelisGian wants to merge 2 commits into
NVIDIA:mainfrom
VaggelisGian:fix-pgy-ask-before-install-env
Open

Polygraphy - fix POLYGRAPHY_ASK_BEFORE_INSTALL=0 still enabling the install prompt#4836
VaggelisGian wants to merge 2 commits into
NVIDIA:mainfrom
VaggelisGian:fix-pgy-ask-before-install-env

Conversation

@VaggelisGian

Copy link
Copy Markdown

What does this PR do?

POLYGRAPHY_ASK_BEFORE_INSTALL could not be disabled. In tools/Polygraphy/polygraphy/config.py, the flag was parsed as:

ASK_BEFORE_INSTALL = bool(os.environ.get("POLYGRAPHY_ASK_BEFORE_INSTALL", "0" != "0"))

The default argument is the boolean expression "0" != "0" (evaluates to False), instead of the string "0". Because bool("0") is True, any value present in the environment - including 0 - enabled the install prompt, and there was no way to turn it off.

The fix moves the comparison outside the call, matching the idiom used by the sibling flags in the same file:

ASK_BEFORE_INSTALL = bool(os.environ.get("POLYGRAPHY_ASK_BEFORE_INSTALL", "0") != "0")

Testing

New test module tests/test_config.py::TestConfigEnvVars::test_ask_before_install, covering unset, 0 and 1 values via importlib.reload with environment restore.

Commands and output on this machine (after the fix):

$ cd tools/Polygraphy
$ python -m pytest tests/test_config.py -v

tests\test_config.py::TestConfigEnvVars::test_ask_before_install PASSED   [100%]
======================== 1 passed, 1 warning in 0.03s ========================

Before the fix the test fails: with POLYGRAPHY_ASK_BEFORE_INSTALL=0 in the environment the reloaded config reports ASK_BEFORE_INSTALL == True. The single warning in the output (Marks applied to fixtures have no effect, from tests/conftest.py) is pre-existing on main and unrelated.

Environment

TensorRT OSS main (10d15ae), polygraphy sources run from the repo.
Python 3.12, tensorrt 11.2.1.2 (pip wheel), polygraphy 0.53.4,
NVIDIA RTX 5060 Ti, driver 591.86, Windows 11 Pro.

Issue

Per CONTRIBUTING.md, bugfixes start as an issue approved by TensorRT engineers before code review. I could not find an existing issue covering this; happy to file one and link it here if maintainers prefer that flow, or please advise whether this PR can proceed directly.

The default value passed to os.environ.get was the boolean expression
"0" != "0" instead of the string "0", so the lookup could never return
a falsy default and bool("0") is True. Setting POLYGRAPHY_ASK_BEFORE_INSTALL=0
thereby enabled the prompt it was meant to disable. Use the same
get(KEY, "0") != "0" idiom as the neighboring flags, and cover all three
cases (unset, 0, 1) with a regression test that reloads the config module.

Test Plan:
  cd tools/Polygraphy
  PYTHONPATH=$PWD python -m pytest tests/test_config.py -v
    fails before the fix on the =0 case (assert not True), passes after
  PYTHONPATH=$PWD python -m pytest tests/test_config.py tests/comparator tests/common -q
    identical failure set to the suites alone (all pre-existing environment
    failures), proving no reload side effects or ordering dependence

Signed-off-by: Vaggelis <baggelis100@gmail.com>
@VaggelisGian
VaggelisGian requested a review from a team as a code owner August 24, 2026 10:59
Upstream appends entries for unreleased changes to the existing
undated version section rather than opening a new heading.

Signed-off-by: Vaggelis <baggelis100@gmail.com>
"""

ASK_BEFORE_INSTALL = bool(os.environ.get("POLYGRAPHY_ASK_BEFORE_INSTALL", "0" != "0"))
ASK_BEFORE_INSTALL = bool(os.environ.get("POLYGRAPHY_ASK_BEFORE_INSTALL", "0") != "0")

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.

This is actually already fixed internally and would go out with the next release, but thanks for fixing it here!

@VaggelisGian

Copy link
Copy Markdown
Author

Thanks for the quick review and approval! Good to know it is also fixed internally for the next release - if you would rather take that one and close this PR, that works fine on my end. Either way is fine.

@pranavm-nvidia

Copy link
Copy Markdown
Collaborator

Thanks for the quick review and approval! Good to know it is also fixed internally for the next release - if you would rather take that one and close this PR, that works fine on my end. Either way is fine.

@VaggelisGian the fix is the same, but I like your test better. We can merge your PR and I'll integrate it with the internal changes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants