Fixes for collections.Counter (#159368)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/159368
Approved by: https://github.com/mlazos
ghstack dependencies: #159365, #159366
This commit is contained in:
Guilherme Leobas
2025-08-15 12:44:29 -03:00
committed by PyTorch MergeBot
parent 2542e71f3f
commit e5621b4d8b
12 changed files with 57 additions and 1 deletions

View File

@ -2543,6 +2543,13 @@ class BuiltinVariable(VariableTracker):
(operator.neg)(a.as_proxy()),
sym_num=None,
)
if (
isinstance(a, UserDefinedObjectVariable)
and a.call_obj_hasattr(tx, "__neg__").value # type: ignore[attr-defined]
):
return a.call_method(tx, "__neg__", [], {})
# None no-ops this handler and lets the driving function proceed
return None