-
Notifications
You must be signed in to change notification settings - Fork 102
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
Allow for more elemwise torch functions using broadcast_tensor
and vmap
#1032
base: main
Are you sure you want to change the base?
Allow for more elemwise torch functions using broadcast_tensor
and vmap
#1032
Conversation
I need to add a test, but I want to get feedback on #1031 before continuing. |
broadcast_tensor
and vmap
I'll fix the tests. |
if shaped_inputs[0].dim() == 1: | ||
ufunc = torch.vmap(base_fn) | ||
else: | ||
dims = (tuple(range(shaped_inputs[0].dim())),) |
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 don't think this is correct. You need to apply vmap repeatedly to make it vectorize across multiple dimensions
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're correct, my bad. I misunderstood the docs and wrote a bad local test.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1032 +/- ##
==========================================
- Coverage 81.90% 81.89% -0.01%
==========================================
Files 182 182
Lines 47879 47887 +8
Branches 8620 8619 -1
==========================================
+ Hits 39214 39216 +2
- Misses 6492 6498 +6
Partials 2173 2173
|
# @todo: This will fail for anything that calls | ||
# `.item()` |
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.
We usually use # TODO:
not # @todo:
return base_fn(*inputs) | ||
else: | ||
|
||
def elemwise_fn(*inputs): |
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.
We need a test for this branch. You can create a new test ScalarOp and dispatch something specifically in PyTorch (in the test suite) to test this?
Description
In the event the operator
Elemwise
is broadcasting over doesn't have a direct torch function, we can leveragevmap
andbroadcast_tensors
to replicate the ufunc machinery.Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pytensor--1032.org.readthedocs.build/en/1032/