-
Notifications
You must be signed in to change notification settings - Fork 137
Make convolve mode symbolic to avoid unnecessary large convolution in gradient graph #1522
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
Merged
ricardoV94
merged 4 commits into
pymc-devs:main
from
ricardoV94:make_convolve_mode_symbolic
Jul 8, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bcbb18a
Simplify python implementation of ScalarFromTensor
ricardoV94 4c22301
local_subtensor_make_vector: don't return make_vector when slice keep…
ricardoV94 07c998e
Allow Blockwise to create dummy core nodes with outer inputs, if thes…
ricardoV94 9026dd8
Make convolve mode symbolic to avoid unnecessary large convolution in…
ricardoV94 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import jax | ||
|
||
from pytensor.link.jax.dispatch import jax_funcify | ||
from pytensor.tensor.basic import get_underlying_scalar_constant_value | ||
from pytensor.tensor.exceptions import NotScalarConstantError | ||
from pytensor.tensor.signal.conv import Convolve1d | ||
|
||
|
||
@jax_funcify.register(Convolve1d) | ||
def jax_funcify_Convolve1d(op, node, **kwargs): | ||
mode = op.mode | ||
_, _, full_mode = node.inputs | ||
try: | ||
full_mode = get_underlying_scalar_constant_value(full_mode) | ||
except NotScalarConstantError: | ||
raise NotImplementedError( | ||
"Cannot compile Convolve1D to jax without static mode" | ||
) | ||
static_mode = "full" if full_mode else "valid" | ||
|
||
def conv1d(data, kernel): | ||
return jax.numpy.convolve(data, kernel, mode=mode) | ||
def conv1d(data, kernel, _runtime_full_mode): | ||
# _runtime_full_mode is not used, as we only support static mode | ||
return jax.numpy.convolve(data, kernel, mode=static_mode) | ||
|
||
return conv1d |
This file contains hidden or 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 hidden or 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 hidden or 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.
That
[()]
syntax is really uglyThere 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.
It's how you index/update a 0d array in numpy
Uh oh!
There was an error while loading. Please reload this page.
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.
You can also use
None
I believe.Edit: It only works for assignment. If this is really what they want you to do in this case, that sucks. But c'est la vie.
Uh oh!
There was an error while loading. Please reload this page.
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.
The idea is you're indexing an array without indices / dimensions, so you can't say pick first entry of first dimension (there are no dims). Anyway surprised it bothers you too much