-
Notifications
You must be signed in to change notification settings - Fork 14
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
ReverseDiff support #144
base: main
Are you sure you want to change the base?
ReverseDiff support #144
Conversation
v, pb = _rrule(sc, argv, paramsv, _returns_scalar(sc)) | ||
return v, Δ -> begin | ||
_Δ = Base.tail(pb(collect(Δ))) | ||
_Δ = Base.tail(pb(collect(Δ))) |
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.
If you comment this line out, you get the correct gradient. deepcopy
ing everything didn't fix this so I am not sure what's going on.
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.
So call it once, it works. Call it twice, it breaks.
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.
deepcopy
isn't likely to help on pointers.
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.
perhaps the _rrule
function should be a struct which stores the initial pointer address and starts from there every time it's called
I would suggest taking this approach: That is, in Julia versions without package extensions, LoopVectorization.jl loads the extension files. I think it'd make sense to give |
yes I will do that as soon as it works well |
offset += 1 | ||
else | ||
l = length(y) | ||
v[offset + 1 : offset + l] = vec(y) |
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.
Note that vec
allocates if !isa(y,AbstractVector)
This looks performance sensitive. Could use an @inbounds
?
But also, why?
This seems internal. We should probably only be rruling relatively high level SimpleChains calls, that hide things like params
getting called?
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.
It was called in the log prior calculation.
This PR implements ReverseDiff support which uncovered a spooky bug. Here is a reproducer that gives a wrong gradient. I will explain the spooky part and how to get the correct gradient in a comment.