Move register_canonicalize to graph.rewriting.utils, Adjust function signature, and enhance AttributeError handling #613
+22
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
1.Function Relocation:
The
register_canonicalize
function has been relocated fromtensor.rewriting.basic
tograph.rewriting.utils
. The move encompasses all necessary imports to ensure seamless functionality in the new location.However, during this transition, issues were identified specifically related to implementation which I tried to fix and are described below.2.Type Mismatch Error Resolution:
The function signature of
register
function insideregister_canonicalize
was causing a type mismatch error. This was addressed by changing the input type toUnion[RewriteDatabase, NodeRewriter]
fromUnion[RewriteDatabase, Rewriter
]Before:
Error:
After:
3.AttributeError Fix:
In
register_canonicalize
, there were errors related to missing__name__
attributes fornode_rewriter:Union[RewriteDatabase, NodeRewriter, str]
This was resolved by using
getattr()
to handle cases where__name__
is not present .In cases where the attribute is not available,Name=None
. (We can think of implementing default name )before:
name = kwargs.pop("name", None) or node_rewriter.__name__
Error:
after:
name = kwargs.pop("name", None) or getattr(node_rewriter, "__name__", None)
Related Issue
register_canonicalize
and similar helpers to rewriting module #323Checklist
Type of change