-
Notifications
You must be signed in to change notification settings - Fork 89
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
Can rules make decisions based on which primal method is used? #237
Labels
design
Requires some design before changes are made
type constraints
Potentially raises a question about how tightly to constrain argument types for a rule. See #232
Comments
e.g. something like this: function rrule(::typeof(det), x::Union{Number, AbstractMatrix})
F = if which(det, Tuple{typeof(x)}) === which(det, Tuple{AbstractMatrix})
lu(x; check = false)
else
x
end
Ω = det(F)
function det_pullback(ΔΩ)
return NO_FIELDS, Ω * ΔΩ * inv(F)'
end
return Ω, det_pullback
end This is type-unstable though, and the |
It seems to me that the "correct" way to distinguish these cases is just standard dispatch:
The rationale would be that if "det via LU" is a good enough fallback for the primal function, then it should also be good enough for the derivative. |
Maybe related JuliaDiff/ChainRulesCore.jl#155 |
nickrobinson251
added
design
Requires some design before changes are made
type constraints
Potentially raises a question about how tightly to constrain argument types for a rule. See #232
labels
Dec 28, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
design
Requires some design before changes are made
type constraints
Potentially raises a question about how tightly to constrain argument types for a rule. See #232
Can we safely detect if a primal function is going to hit a specific default and use that to change the logic in the
frule
orrrule
?For example, the
rrule
fordet(A)
callsinv(A)
. If we know that the primal function that would be hit is thedet(A::AbstractMatrix)
definition ingeneric.jl
, then we know that the primal is using thelu
decomposition to compute the determinant, and we can reuse that to compute the inverse faster. But if a specialized primal method was being hit, then we probably just want to call the primal and invert separately since that primal is probably more efficient for that type thanlu
.The text was updated successfully, but these errors were encountered: