[dynamo][dicts] Decentralize and Improve key hash implementation for Dict variable tracker#169204
[dynamo][dicts] Decentralize and Improve key hash implementation for Dict variable tracker#169204anijain2305 wants to merge 15 commits intogh/anijain2305/963/basefrom
Conversation
…Dict variable tracker [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/169204
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 867cb44 with merge base 390790b ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…tation for Dict variable tracker" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
|
@pytorchbot merge -i |
…tation for Dict variable tracker" Fixes #167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" Fixes #167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" Fixes #167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
…tation for Dict variable tracker" Fixes #167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…rch#167742)" This reverts commit d78f52b. Reverted pytorch#167742 on behalf of https://github.com/huydhn due to Sorry, I need to revert this to cleanly revert pytorch#169204. Please rebase and reland this ([comment](pytorch#167742 (comment)))
…ion for Dict variable tracker (pytorch#169204)" This reverts commit c04e2c6. Reverted pytorch#169204 on behalf of https://github.com/huydhn due to This has been reverted internally ([comment](pytorch#169204 (comment)))
…Dict variable tracker (pytorch#169204) Fixes pytorch#167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. Pull Request resolved: pytorch#169204 Approved by: https://github.com/jansel
…Dict variable tracker (#169204) Fixes #167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. Pull Request resolved: #169204 Approved by: https://github.com/jansel ghstack dependencies: #169233
…ion for Dict variable tracker (#169204)" This reverts commit 8414958. Reverted #169204 on behalf of https://github.com/wdvr due to failing test/test_fx.py::TestFXAPIBackwardCompatibility::test_public_api_surface [GH job link](https://github.com/pytorch/pytorch/actions/runs/19803784913/job/56735267443) [HUD commit link](https://hud.pytorch.org/pytorch/pytorch/commit/84149583d483e9c973c9a0feda70e4f3964947b0) consistently ([comment](#169204 (comment)))
…Dict variable tracker (#169204) Fixes #167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. Pull Request resolved: #169204 Approved by: https://github.com/jansel
)" This reverts commit d78f52b. Reverted #167742 on behalf of https://github.com/huydhn due to Sorry, I need to revert this to cleanly revert #169204. Please rebase and reland this ([comment](#167742 (comment)))
…ion for Dict variable tracker (#169204)" This reverts commit c04e2c6. Reverted #169204 on behalf of https://github.com/huydhn due to This has been reverted internally ([comment](#169204 (comment)))
…Dict variable tracker (#169204) Fixes #167956 ## Summary This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in _HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses. ## Motivation The previous implementation had several issues: 1. Centralized logic: All hashability checks and hash computations were centralized in dicts.py, making it difficult to add support for new hashable types 2. Maintainability: Adding a new hashable type required modifying multiple locations in _HashableTracker (underlying_value, _eq_impl, and the is_hashable function) 3. Scattered knowledge: Type-specific hashing logic was separated from the type's own implementation 4. Limited extensibility: No clear protocol for VariableTracker subclasses to declare themselves as hashable ## Changes New Protocol Methods Added three new methods to the VariableTracker base class: 1. is_python_hashable(): Returns whether the underlying Python object is hashable 2. get_python_hash(): Computes the hash value for the underlying Python object 3. is_python_equal(other): Checks Python-level equality between two VariableTrackers The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate. ## Simplified _HashableTracker The _HashableTracker class in ConstDictVariable is now much simpler: - Removed underlying_value property (centralized type handling) - Removed _eq_impl static method (centralized equality logic) - Simplified __hash__() to delegate to vt.get_python_hash() - Simplified __eq__() to delegate to vt.is_python_equal() ## Decentralized Implementations Implemented the new protocol methods across relevant VariableTracker subclasses: - ConstantVariable, TensorVariable, TupleVariable, ListVariable - FrozensetVariable, FrozenDataClassVariable - BuiltinVariable, UserFunctionVariable, SkipFunctionVariable - FunctoolsPartialVariable, WeakRefVariable - NumpyVariable, NNModuleVariable, MethodWrapperVariable - TorchInGraphFunctionVariable, TorchHigherOrderOperatorVariable - TypingVariable, UserDefinedObjectVariable, UserDefinedClassVariable - SymNodeVariable, EnumVariable ## Enhanced Test Coverage Added 14 new test cases covering various hashable types as dictionary keys: - range, tuples, enums, frozensets - Typing constructs (e.g., typing.Union) - NumPy dtypes, method wrappers - Torch builtin functions, frozen dataclasses - Custom objects with __hash__ - Negative test for unhashable types (lists) ## Improved Error Messages Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type. Pull Request resolved: #169204 Approved by: https://github.com/jansel
Stack from ghstack (oldest at bottom):
Fixes #167956
Summary
This PR decentralizes and improves the hash implementation for dictionary keys in Dynamo's ConstDictVariable tracker. Instead of maintaining a centralized list of hashable types and custom equality logic in
_HashableTracker, we now delegate hashability checks, hash computation, and equality comparison to individual VariableTracker subclasses.
Motivation
The previous implementation had several issues:
Changes
New Protocol Methods
Added three new methods to the VariableTracker base class:
The base implementation raises unimplemented() with helpful error messages, and subclasses override these methods as appropriate.
Simplified _HashableTracker
The _HashableTracker class in ConstDictVariable is now much simpler:
Decentralized Implementations
Implemented the new protocol methods across relevant VariableTracker subclasses:
Enhanced Test Coverage
Added 14 new test cases covering various hashable types as dictionary keys:
Improved Error Messages
Updated error messages to be more informative when encountering unhashable types, showing both the Python type and the VariableTracker type.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @Lucaskabela @jataylo