-
-
Notifications
You must be signed in to change notification settings - Fork 175
perf: dynamic (un)flattening code generation #1119
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
|
@patrick-kidger This is ~80% of the way there. I think it's a tiny bit slower than the other PR but still gets equinox into the same ballpark as straight JAX. The same test file, with the methods on the equinox module removed, should benchmark this PR. This PR is missing the (A third alternative would be to mypyc Module and let |
|
I really like this approach. If there's a need for greater speed then codegen sounds like a great way to get things to be fast-by-default. I definitely don't have time to pursue this myself but I'll happily merge this once it's ready. |
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.
For @patrick-kidger, a short report on current status:
I've cleaned up the PR code a lot and moved it to a separate module.
With the current PR https://github.com/user-attachments/files/22870041/overhead.ipynb.zip benchmarks great. It's about as fast as raw arrays and optimized pytrees. So that's good.
The part that I haven't been able to solve is the massive performance hit associated with getting and setting the WRAPPER_FIELD_NAMES. I've commented in all the changes necessary to use the wrapper fields.
|
Awesome! I really like the look of this PR. The performance hit on the extra magic attributes – I think the common case is that none of these are present on the instance, and that instead they are class attributes. Perhaps this could be exploited, so that e.g. flattening check their presence and sets a boolean flag, and then unflattening skips this codepath if it is not required? |
|
The last commit needs a lot of cleanup, but if the |
|
@patrick-kidger is |
125d66a to
4939d92
Compare
|
Ok. Final approximate timings on that performance notebook:
So this PR is a ~50% improvement ((12.5 - 10) / (12.5 - 7.7)) but there's still another 2.3 µs to go. |
patrick-kidger
left a comment
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, many nits! But I basically really like this, it looks pretty much like exactly what we want to me.
db187d5 to
60820e2
Compare
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
60820e2 to
714a0c2
Compare
|
@patrick-kidger I think the only possibly unresolved comments are #1119 (comment) and #1119 (comment), but IMO they're good to go. |
|
I tested this on |
|
Nice! Just in case some of the weirder cases (overriding fields with properties etc) catch us out. |
There is an error in |
|
The diffrax errata were fixed in patrick-kidger/diffrax#696, and should not occur on |
|
Awesome! Merged 🎉 |
I haven't implemented the full logic, like the use of
_FLATTEN_SENTINEL.