-
Notifications
You must be signed in to change notification settings - Fork 145
Improve numba DimShuffle compile time #95
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
Conversation
b753226
to
deb6535
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #95 +/- ##
==========================================
+ Coverage 74.22% 74.41% +0.18%
==========================================
Files 174 179 +5
Lines 48734 49249 +515
Branches 10367 10422 +55
==========================================
+ Hits 36175 36649 +474
- Misses 10272 10295 +23
- Partials 2287 2305 +18
|
else: | ||
new_shape = numba_basic.tuple_setitem(new_shape, i, shuffle_shape[j]) | ||
return j + 1, new_shape | ||
def find_shape(array_shape): |
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 we shortcut when the output static shape is known?
pt.random.normal(size=(2, 3)).dimshuffle(1, 0).type.shape # (3, 2)
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 guess that might save a tiny bit of runtime and/or compile time, but if that were incorrect for some reason we would end up writing to arrays out of bounds. There is no error checking after this point.
I think it is safer to always infer the output shape from the 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.
In that case the graph would be inconsistent and should fail anyway.
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.
Yes, it should fail. But if we just assume the shapes are correct, we might just silently corrupt memory and not fail in an obvious way. :-)
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.
ah, sorry I somehow though this was the shape code for the llvm-elemwise...
Here the reshape should just fail if we provide something incorrect. So yes, I think we can use extra info we have here, I'll update the 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.
Either way it's probably a minor performance difference. I was more thinking out loud in what types of place can we benefit from static shape info.
Co-authored-by: Ricardo Vieira <[email protected]>
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.
LGTM
What exactly provides the compilation speedup?
I'm still trying to understand numba compile times better, but it seems in this case the transpose had quite some impact. And most of the time the transpose in DimShuffle is just a no-op (and we know it is), so we can remove it in those cases. |
Compile time for DimShuffle ops is pretty long:
Still ways to go, and unfortunately it doesn't seem to have as big an impact on the compile times for larger models as I hoped, but it is a start...
Going forward I think we should try to find more ops like this, where individually the compile time is large, and try some other things: