Polygraphy - fix POLYGRAPHY_ASK_BEFORE_INSTALL=0 still enabling the install prompt - #4836
Conversation
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>
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>
|
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. |
|
Note on the failing check: That Dockerfile no longer exists anywhere in the repository (removed on main back in the 10.13.2 release), so this step cannot succeed against any current tree. The failure predates this PR and is unrelated to the change, which only touches tools/Polygraphy. |
What does this PR do?
POLYGRAPHY_ASK_BEFORE_INSTALLcould not be disabled. Intools/Polygraphy/polygraphy/config.py, the flag was parsed as:The default argument is the boolean expression
"0" != "0"(evaluates toFalse), instead of the string"0". Becausebool("0")isTrue, any value present in the environment - including0- 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:
Testing
New test module
tests/test_config.py::TestConfigEnvVars::test_ask_before_install, covering unset,0and1values viaimportlib.reloadwith environment restore.Commands and output on this machine (after the fix):
Before the fix the test fails: with
POLYGRAPHY_ASK_BEFORE_INSTALL=0in the environment the reloaded config reportsASK_BEFORE_INSTALL == True. The single warning in the output (Marks applied to fixtures have no effect, fromtests/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.