Skip to content

[PyTorch FE] Bug: _is_testing() always returns True for truthy inputs due to missing .lower() call #34563

@rishi-sangare

Description

@rishi-sangare

Problem

In backend_utils.py:86, the _is_testing() function compares a method reference instead of calling it:

def _is_testing(options) -> Optional[Any]:
    if options is not None and "testing" in options:
        is_testing = options["testing"]
        if bool(is_testing) and str(is_testing).lower not in ["false", "0"]:
            return True
    return False

str(is_testing).lower is a bound method object — it's never equal to "false" or "0", so the not in check always evaluates to True. This means any truthy value of options["testing"], including the string "false" or "0", will cause the function to return True.

Impact

_is_testing() is used in partition.py:138 to set allow_single_node_partition. Because the flag check is broken, passing {"testing": "false"} or {"testing": "0"} still enables testing mode, which changes partitioning behavior unexpectedly.

Fix

- if bool(is_testing) and str(is_testing).lower not in ["false", "0"]:
+ if bool(is_testing) and str(is_testing).lower() not in ["false", "0"]:

I can submit a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions