Description
Bug report
PyTorch Dynamo constructs code objects with non-standard constants. This is unusual, but seems to work with the default (non-free threaded build) of CPython.
However, it crashes in the free threaded build due to a few assertions when we try to de-dupe (intern) and immortalize constants:
In compare_constants
:
Lines 2671 to 2672 in 3dd3675
In `hash_const:
Lines 2692 to 2694 in 3dd3675
We should more gracefully handle unexpected code object constants in the free threading build. I think the interning code should behave like _PyCode_ConstantKey()
where unhandled objects types are treated as unequal if they are not the same instance (i.e., identity comparison for unexpected types).
Linked PRs
- gh-130851: Don't crash when deduping unusual code constants. #130853
- [3.13] gh-130851: Don't crash when deduping unusual code constants (GH-130853) #130880
- gh-130851: Skip test_unusual_constants under refleak checker #130899
- gh-130851: Only intern constants of types generated by the compiler #130901
- [3.13] gh-130851: Only intern constants of types generated by the compiler (GH-130901) #130953