-
Notifications
You must be signed in to change notification settings - Fork 33
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
Differentiability of Spatial Gradients #598
Comments
@vchuravy we are running into some problems differentiating through the divergence function defined here SpeedyWeather.jl/src/SpeedyTransforms/spectral_gradients.jl Lines 57 to 102 in c63fb6e
This is the CPU version of the code (with scalar indexing and a running index too) but before I rewrite this towards KernelAbstractions is there anything that pops up why Enzyme would struggle to differentiate this? |
It's not the Doing it with anonymous functions instead of function closures at least doesn't get an error. I didn't check correctness yet, though. So doing this works kernel = flipsign ? (add ? (o, a, b, c) -> o-(a-b+c) : (o, a, b, c) -> -(a-b+c)) :
(add ? (o, a, b, c) -> o+(a-b+c) : (o, a, b, c) -> a-b+c) but this (our version in the main code) doesn't: kernel(o, a, b, c) = flipsign ? (add ? o-(a-b+c) : -(a-b+c)) :
(add ? o+(a-b+c) : a-b+c ) But yeah, I couldn't condense this down to a MWE yet. Because in simpler cases it's works to hand over a function like the one below. |
After/with #589, I continued my hunt for differentiability with Enzyme a bit. With the transforms (more or less) differentiable, I found the first error from Enzyme at the spatial gradients, more precisely
_divergence!
.As it is, Enzyme seems to have a problem with the way we write these methods with function kernels/closures that are conditional. Because as the following shows, Enzyme only yields an error when we use a kernel with a conditional closure as we commonly do in our code for these functions:
Not sure why that's the case. I post it here, to document it, let's see if I still have some time before my vacation to condense this down to a MWE for the Enzyme devs. So far my attempts to do a quick MWE have not been successful, because very simple examples do actually work, like the following causes no issue:
All of that being said, maybe we also have to do a slightly different way of computing those divergences with a GPU/KernelAbstractions version anyway. So I won't invest too much effort into this now.
The text was updated successfully, but these errors were encountered: