Hashing for constant and singleton SymInt/SymBool (#109170)

Bugfix:
- previously, SymBool does not implement `__eq__`, Python falls back to default `__eq__ `and `__hash__`
- in this PR, we make SymBool implement `__eq__`
- symbolic SymBool now raises an error when hashed just like SymInt/SymFloat

New feature:
- previously, SymInt and SymFloat are unhashable (even if you are singleton or constant)
- in this PR, SymInt and SymBool are hashable if singleton/constant

Stay the same:
- SymNode are hashable due to default Python behavior
Pull Request resolved: https://github.com/pytorch/pytorch/pull/109170
Approved by: https://github.com/ezyang
ghstack dependencies: #109169
This commit is contained in:
soulitzer
2023-09-19 18:21:11 -04:00
committed by PyTorch MergeBot
parent 5252fcb133
commit 8bc00dfffd
4 changed files with 99 additions and 16 deletions

View File

@ -1265,6 +1265,11 @@ void initJITBindings(PyObject* module) {
"is_symbolic",
[](const c10::SymNode& node) {
return node->is_symbolic();
})
.def(
"singleton_int",
[](const c10::SymNode& node) {
return node->singleton_int();
});
// clang-format on