-
Notifications
You must be signed in to change notification settings - Fork 117
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
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. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1032 +/- ##
==========================================
- Coverage 82.10% 82.10% -0.01%
==========================================
Files 183 183
Lines 47924 47932 +8
Branches 8632 8634 +2
==========================================
+ Hits 39348 39354 +6
- Misses 6410 6413 +3
+ Partials 2166 2165 -1
|
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.
Only some nits left, PR looks great!
|
||
def elemwise_fn(*inputs): | ||
Elemwise._check_runtime_broadcast(node, inputs) | ||
shaped_inputs = torch.broadcast_tensors(*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.
Nit: more precise name:
shaped_inputs = torch.broadcast_tensors(*inputs) | |
broadcasted_inputs = torch.broadcast_tensors(*inputs) |
Also needs to be changed below
# @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.
Remove todo, not something that should be addressed in this impl, but for specific Ops, so if anything should exist as a github issue?
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.
nope i agree with you.
I loosen the failing test in #988 ; this should be good after that. |
def elemwise_fn(*inputs): | ||
Elemwise._check_runtime_broadcast(node, inputs) | ||
return base_fn(*inputs) | ||
if hasattr(scalar_op, "nfunc_spec") and hasattr(torch, scalar_op.nfunc_spec[0]): |
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 do the same trick for scipy.x
you did in another PR?
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.
...but then I have to write a new test for this PR 😅
97d6bdc
to
1dd6322
Compare
1dd6322
to
c7e8a64
Compare
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/