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

Array output seems to be initialized but not filled #97

Closed
gdalle opened this issue Mar 24, 2024 · 8 comments
Closed

Array output seems to be initialized but not filled #97

gdalle opened this issue Mar 24, 2024 · 8 comments

Comments

@gdalle
Copy link
Collaborator

gdalle commented Mar 24, 2024

I caught this bug as part of my DifferentiationInterface.jl test suite. The first object returned by value_and_pullback!! looks like the result of Vector{Float64}(undef, n) instead of containing the actual function output. And it changes from run to run. Meanwhile the VJP is stable and correct:

julia> import Taped

julia> scalar_to_vector(x::Number) = [sin(x), sin(2x)]
scalar_to_vector (generic function with 1 method)

julia> r = Taped.build_rrule(scalar_to_vector, 1.0)
Taped.DerivedRule{Core.OpaqueClosure{Tuple{Taped.AugmentedRegister{Taped.CoDual{typeof(scalar_to_vector), Taped.NoTangent}, Taped.NoTangentRef}, Taped.AugmentedRegister{Taped.CoDual{Float64, Float64}, Base.RefArray{Float64, Vector{Float64}, Nothing}}}, Taped.AugmentedRegister{Taped.CoDual{Vector{Float64}, Vector{Float64}}, Base.RefArray{Vector{Float64}, Vector{Vector{Float64}}, Nothing}}}, Tuple{Taped.NoTangentStack, Taped.Stack{Float64}}, Core.OpaqueClosure{Tuple{Vector{Float64}, Taped.NoTangent, Float64}, Nothing}, Val{false}, Val{2}}((::Taped.AugmentedRegister{Taped.CoDual{typeof(scalar_to_vector), Taped.NoTangent}, Taped.NoTangentRef}, ::Taped.AugmentedRegister{Taped.CoDual{Float64, Float64}, Base.RefArray{Float64, Vector{Float64}, Nothing}})::Taped.AugmentedRegister{Taped.CoDual{Vector{Float64}, Vector{Float64}}, Base.RefArray{Vector{Float64}, Vector{Vector{Float64}}, Nothing}}->◌, (::Vector{Float64}, ::Taped.NoTangent, ::Float64)::Nothing->◌, (Taped.NoTangentStack(), Taped.Stack{Float64}(Float64[], 0)), Taped.Stack{Int32}(Int32[], 0), Val{false}(), Val{2}())

julia> Taped.value_and_pullback!!(r, [1.0, 2.0], scalar_to_vector, 3.0)
([0.0, 0.0], (Taped.NoTangent(), 2.8506886500010182))

julia> Taped.value_and_pullback!!(r, [1.0, 2.0], scalar_to_vector, 3.0)
([6.1801573873894e-310, 6.18027838103766e-310], (Taped.NoTangent(), 2.8506886500010182))

julia> Taped.value_and_pullback!!(r, [1.0, 2.0], scalar_to_vector, 3.0)
([5.0e-324, 0.0], (Taped.NoTangent(), 2.8506886500010182))

julia> 1.0 * cos(3.0) + 2.0 * 2cos(6.0)
2.8506886500010182
@willtebbutt
Copy link
Member

This is not nice. Will investigate.

@gdalle
Copy link
Collaborator Author

gdalle commented Mar 24, 2024

FYI you can now use Taped with DifferentiationInterface.jl, the functionality has been merged in
JuliaDiff/DifferentiationInterface.jl#92

It is not documented but that may allow you to catch more bugs if you want to try out our test suite

@willtebbutt
Copy link
Member

Amazing, thanks. I'll definitely give your test suite a go -- I'm sure there are holes in mine.

@willtebbutt
Copy link
Member

On this, could you point me towards the test suite that I should be looking at?

@gdalle
Copy link
Collaborator Author

gdalle commented Mar 24, 2024

  1. Clone the repo https://github.com/gdalle/DifferentiationInterface.jl/
  2. Open a REPL and activate the test environment with TestEnv.activate()
  3. Run https://github.com/gdalle/DifferentiationInterface.jl/blob/main/test/taped.jl
  4. The code you want to modify if things fail due to the bridging is at https://github.com/gdalle/DifferentiationInterface.jl/blob/main/ext/DifferentiationInterfaceTapedExt/DifferentiationInterfaceTapedExt.jl

@willtebbutt
Copy link
Member

Okay. This should now be fixed on main.

@gdalle
Copy link
Collaborator Author

gdalle commented Mar 24, 2024

cool, thanks!
I'll beef up our test suite in the coming days, will let you know if I run into any more trouble

@willtebbutt
Copy link
Member

Great. I'll close this. Please open more issues if you run into problems

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