[dynamo] Use polyfill to implement comparison operators (#144485)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/144485
Approved by: https://github.com/jansel
This commit is contained in:
Animesh Jain
2025-01-28 18:22:33 -08:00
committed by PyTorch MergeBot
parent 3e135993bd
commit d1f82de2bf
17 changed files with 287 additions and 139 deletions

View File

@ -15,6 +15,7 @@ from ..bytecode_transformation import create_call_function, create_instruction
from ..exc import raise_observed_exception, unimplemented
from ..source import AttrSource
from ..utils import (
cmp_name_to_op_mapping,
get_fake_value,
guard_if_dyn,
istype,
@ -136,6 +137,18 @@ class BaseListVariable(VariableTracker):
[self] + list(args),
kwargs,
)
elif name in cmp_name_to_op_mapping:
left = self
right = args[0]
if not isinstance(left, BaseListVariable) and not isinstance(
right, BaseListVariable
):
return variables.ConstantVariable.create(NotImplemented)
return variables.UserFunctionVariable(polyfills.list_cmp).call_function(
tx,
[variables.BuiltinVariable(cmp_name_to_op_mapping[name]), left, right],
{},
)
return super().call_method(tx, name, args, kwargs)