Skip to content
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

What happens to value_and_gradient!! if the output is not a Float64? #116

Closed
gdalle opened this issue Apr 6, 2024 · 5 comments
Closed

Comments

@gdalle
Copy link

gdalle commented Apr 6, 2024

https://github.com/withbayes/Tapir.jl/blob/f5e2b90cd17fd3127dd0fd8dfa617bc112275626/src/interface.jl#L17-L24

@willtebbutt
Copy link
Member

A non-ideal, but fairly decipherable, error. For example:

rule = build_rrule(identity, randn(5))
Tapir.value_and_gradient!!(rule, identity, randn(5))

yields

ERROR: AssertionError: _typeof(tangent(out)) == T
Stacktrace:
 [1] value_and_pullback!!(::Tapir.DerivedRule{…}, ::Float64, ::CoDual{…}, ::CoDual{…})
   @ Tapir ~/ml/ad_playground/Taped.jl/src/interface.jl:11
 [2] value_and_gradient!!(::Tapir.DerivedRule{…}, ::CoDual{…}, ::CoDual{…})
   @ Tapir ~/ml/ad_playground/Taped.jl/src/interface.jl:23
 [3] value_and_gradient!!(::Tapir.DerivedRule{…}, ::Function, ::Vector{…})
   @ Tapir ~/ml/ad_playground/Taped.jl/src/interface.jl:60
 [4] top-level scope
   @ REPL[38]:1
Some type information was truncated. Use `show(err)` to see complete types.

@gdalle
Copy link
Author

gdalle commented Apr 6, 2024

Wouldn't it be possible to grab the type T of the output, assuming it's a scalar type, and use one(T) as the pullback seed?

@willtebbutt
Copy link
Member

Provided you also constrain it to a known collection of "real-valued" types (Float16, Float32, BigFloat, etc), I agree that should work.

I'm not really testing on anything other than Float64 at the minute for the sake of expedience though, which is why I've gone with 1.0. When I widen the range of types that I'm confident we have decent support for, I'll widen the permissible types.

@gdalle
Copy link
Author

gdalle commented Apr 6, 2024

Sounds good! I was mostly curious

@willtebbutt
Copy link
Member

Cool. Please feel free to re-open if there's anything else to chat about on this point :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants