-
Notifications
You must be signed in to change notification settings - Fork 129
Refactor infer_shape
method of Ops to find output shapes using gufunc_signature
#1294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Aarsh-Wankar
wants to merge
8
commits into
pymc-devs:main
Choose a base branch
from
Aarsh-Wankar:infer_shape_1257
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−37
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1d93510
Refactor infer_shape methods to utilize _gufunc_to_out_shape for outp…
Aarsh-Wankar 81899de
Redacted changes for Ops with non-conclusive gufunc_signature
Aarsh-Wankar 7931668
fixed ruff format
Aarsh-Wankar 870b900
Refactor _gufunc_to_out_shape for giving priority to Constant dimensi…
Aarsh-Wankar c161452
Remove error handling for inconsistent dimensions in _gufunc_to_out_s…
Aarsh-Wankar 7b44445
Implement infer_shape method in Op class and remove redundant impleme…
Aarsh-Wankar 707c82e
fixed circular import
Aarsh-Wankar a5f6ce4
Raise ShapeError instead of NotImplementedError for unimplemented inf…
Aarsh-Wankar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should try to prioritize input dimensions that are constant when there are multiple ones with the same letter, as it will generate a better shape graph.
Also fail explicitly if the shape can't be inferred from the signature alone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I raise a
ValueError
when a single dimension in thegufunc_signature
(saym
) is assigned two values in the inputshapes
? I am raising aValueError
when the shape cannot be inferred from the signature. Here is my new function:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shapes are symbolic you can't always compare them to know if they match, you can only do that for constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so if
shapes
list can contain symbolic values, can we first convert the symbolic variable to atensor_variable
usingas_tensor_variables
and then use.equals
method to compare them? Specifically, in the function above, we make this change:This is how the output looks like then: (The shapes input contains integers here)
Can there be a better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, if they are symbolic, unless they are constants, you can't know if they are equivalent, so raising an error is incorrect. User may have defined
x = pt.vector("x"); y =pt.vector("y"); out = x + y
. You will not know if x and y have identical shapes until the user compiles a function and provides values for them.The logic for giving priority to constants is already in the Blockwise infer_shape, you should be able to just grab it and refactor it. We just want to simplify the graph returned, if there are two inputs with the same letters, and one of them has a constant shape. In that case we pick the constant one.
Checking if two inputs agree is not the critical thing here, although we can do that. You can only do that if
isinstance(shapes[0][j], Constant)
andisinstance(shapes[1][j], Constant)
in which case you can then checkshapes[0][j].data == shapes[1][j].data
if you want to raise an informative error when they are inconsistent.Also no reason to convert to
as_tensor_variable
, they should beScalarVariable
s IIRC. Could be wrong here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the code from the
infer_shape
ofBlockwise
class, and used it to write the function. This gives priority toConstants
. Is the output typelist[tuple[Any, ...]]
fine?