-
Notifications
You must be signed in to change notification settings - Fork 36
ChainTransform AD performance #466
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
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## master #466 +/- ##
==========================================
- Coverage 93.16% 93.09% -0.08%
==========================================
Files 52 52
Lines 1259 1275 +16
==========================================
+ Hits 1173 1187 +14
- Misses 86 88 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Looks good. I also don't think it's breaking as it is
@@ -28,23 +28,23 @@ end | |||
Base.length(t::ChainTransform) = length(t.transforms) | |||
|
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.
Do you think we could add a constructor ChainTransform(transforms...) = ChainTransform(tuple(transforms...))
or that would be breaking with the ChainTransform(v, \theta)
constructor?
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.
Hmm yeah, I think that would break that
the output of the primal is an acceptable cotangent to be passed to the corresponding | ||
pullback. | ||
""" | ||
function ad_constant_allocs_heuristic( |
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 am afraid I don't really understand why we want to check that the number of allocations is equal?
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. I should add more docs then. The logic is:
- if we've implemented this well, the number of allocations shouldn't change for different input sizes (although the total amount of memory allocated obviously will)
- a really common way for performance to be bad is some kind of type instability that introduces at least one allocation per kernelmatrix element
- We can measure the number of allocations really quickly
It's definitely not a sufficient condition for us to know that we've got good performance, but we at least know that the number of allocations is independent of the size of the output of kernelmatrix
, which rules out a decent number of performance bugs.
Does this make sense?
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 this is much clearer thanks! If you put this in the docstring we are good to go :)
@theogf let me know whether my explanation of the testing is sufficient, and I'll add a docstring + merge |
Will squash + merge when CI passes |
Summary
The
ChainTransform
has some performance issues on master.Evidence:
master:
This branch:
Proposed changes
_map
rather thanmap
, because that's the APINote that the way I'm testing that this change has been successful is by checking that the number of allocations required to compute the
kernelmatrix
, its forwards-pass and pullback (using Zygote) is invariant to the size of input vector considered. I plan to roll this out more widely in the coming days.What alternatives have you considered?
None
Breaking changes
This only widens the set of permissible types in the
ChainTransform
, and which one gets used by default. On the basis of this, my inclination is to suggest that we shouldn't consider this breaking, but I might have missed something obvious.