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

no method matching -(::Base.RefValue{Float64}, ::Float64) #1608

Closed
mhauru opened this issue Jul 4, 2024 · 6 comments
Closed

no method matching -(::Base.RefValue{Float64}, ::Float64) #1608

mhauru opened this issue Jul 4, 2024 · 6 comments

Comments

@mhauru
Copy link
Contributor

mhauru commented Jul 4, 2024

MWE:

module MWE

import LogDensityProblems
using Turing: @model, MvNormal, LogDensityFunction

using Enzyme

@model function satellite_model_matrix(::Type{TV}=Matrix{Float64}) where {TV}
    @show TV
    P0 = vcat([0.1 0.0], [0.0 0.1])
    x = TV(undef, 2, 2)
    fill!(x, zero(eltype(x)))
    x[:, 2] ~ MvNormal(x[:, 1], P0)
    return nothing
end

model = satellite_model_matrix()

f = LogDensityFunction(model)
x = [1.0, 1.0]
Enzyme.autodiff(ReverseWithPrimal, LogDensityProblems.logdensity, Active, Const(f), Enzyme.Duplicated(x, zero(x)))

end

Output:

TV = Matrix{Float64}
TV = Matrix{Real}
ERROR: LoadError: MethodError: no method matching -(::Base.RefValue{Float64}, ::Float64)

Closest candidates are:
  -(::MutableArithmetics.Zero, ::Any)
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/SXYDN/src/rewrite.jl:67
  -(::Any, ::Manifolds.Identity{Manifolds.AdditionOperation})
   @ Manifolds ~/.julia/packages/Manifolds/ra7xd/src/groups/addition_operation.jl:17
  -(::ChainRulesCore.ZeroTangent, ::Any)
   @ ChainRulesCore ~/.julia/packages/ChainRulesCore/I1EbV/src/tangent_arithmetic.jl:101
  ...

Stacktrace:
  [1] _broadcast_getindex_evalf
    @ ./broadcast.jl:709 [inlined]
  [2] _broadcast_getindex
    @ ./broadcast.jl:682 [inlined]
  [3] getindex
    @ ./broadcast.jl:636 [inlined]
  [4] macro expansion
    @ ./broadcast.jl:1004 [inlined]
  [5] macro expansion
    @ ./simdloop.jl:77 [inlined]
  [6] copyto!
    @ ./broadcast.jl:1003 [inlined]
  [7] copyto!
    @ ./broadcast.jl:956 [inlined]
  [8] materialize!
    @ ./broadcast.jl:914 [inlined]
  [9] materialize!(dest::LinearAlgebra.Adjoint{…}, bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast ./broadcast.jl:911
 [10] reverse
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/internal_rules.jl:502 [inlined]
 [11] \
    @ ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/triangular.jl:1483 [inlined]
 [12] invquad
    @ ~/.julia/packages/PDMats/cAM9h/src/pdmat.jl:146 [inlined]
 [13] invquad
    @ ~/.julia/packages/PDMats/cAM9h/src/pdmat.jl:0 [inlined]
 [14] diffejulia_invquad_13399_inner_1wrap
    @ ~/.julia/packages/PDMats/cAM9h/src/pdmat.jl:0
 [15] macro expansion
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/compiler.jl:6606 [inlined]
 [16] enzyme_call
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/compiler.jl:6207 [inlined]
 [17] AdjointThunk
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/compiler.jl:6090 [inlined]
 [18] runtime_generic_rev(activity::Type{…}, width::Val{…}, ModifiedBetween::Val{…}, tape::Enzyme.Compiler.Tape{…}, f::typeof(PDMats.invquad), df::Nothing, primal_1::PDMats.PDMat{…}, shadow_1_1::PDMats.PDMat{…}, primal_2::Vector{…}, shadow_2_1::Vector{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/7ZLaZ/src/rules/jitrules.jl:447
 [19] sqmahal
    @ ~/.julia/packages/Distributions/ji8PW/src/multivariate/mvnormal.jl:267
 [20] _logpdf
    @ ~/.julia/packages/Distributions/ji8PW/src/multivariate/mvnormal.jl:143
 [21] logpdf
    @ ~/.julia/packages/Distributions/ji8PW/src/common.jl:263 [inlined]
 [22] invlink_with_logpdf
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/abstract_varinfo.jl:856
 [23] invlink_with_logpdf
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/abstract_varinfo.jl:850 [inlined]
 [24] assume
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/context_implementations.jl:221 [inlined]
 [25] tilde_assume
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/context_implementations.jl:60 [inlined]
 [26] tilde_assume
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/context_implementations.jl:57 [inlined]
 [27] tilde_assume!!
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/context_implementations.jl:138
 [28] satellite_model_matrix
    @ ~/projects/Enzyme-mwes/ref_minus_float/mwe.jl:13
 [29] _evaluate!!
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:968 [inlined]
 [30] evaluate_threadunsafe!!
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:941 [inlined]
 [31] evaluate!!
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:894 [inlined]
 [32] logdensity
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:100 [inlined]
 [33] logdensity
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:0 [inlined]
 [34] diffejulia_logdensity_42640_inner_1wrap
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:0
 [35] macro expansion
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/compiler.jl:6606 [inlined]
 [36] enzyme_call
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/compiler.jl:6207 [inlined]
 [37] CombinedAdjointThunk
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/compiler.jl:6084 [inlined]
 [38] autodiff
    @ ~/.julia/packages/Enzyme/7ZLaZ/src/Enzyme.jl:309 [inlined]
 [39] autodiff(::EnzymeCore.ReverseMode{…}, ::typeof(LogDensityProblems.logdensity), ::Type{…}, ::EnzymeCore.Const{…}, ::EnzymeCore.Duplicated{…})
    @ Enzyme ~/.julia/packages/Enzyme/7ZLaZ/src/Enzyme.jl:321
 [40] top-level scope
    @ ~/projects/Enzyme-mwes/ref_minus_float/mwe.jl:21
 [41] include(fname::String)
    @ Base.MainInclude ./client.jl:489
 [42] top-level scope
    @ REPL[13]:1

Sorry that the MWE isn't that minimal, involves the whole Turing @model stack. Let me know this needs further minimising and I can try.

Came up when trying to minimise TuringLang/DynamicPPL.jl#643, not sure if the cause is related.

Running the latest main of Enzyme.jl

@wsmoses
Copy link
Member

wsmoses commented Jul 4, 2024

yeah further minimization of this would definitely be helpful

@wsmoses
Copy link
Member

wsmoses commented Jul 6, 2024

@mhauru with the new linear algebra support landed on main I’m not sure this will be hit anymore if you want to retry

@mhauru
Copy link
Contributor Author

mhauru commented Jul 8, 2024

On Enzyme 0.0.132 and latest Enzyme.jl main the same MWE fails with the same error, although only after I enable Enzyme.API.runtimeActivity!(true). Without runtimeActivity it rather errors with

TV = Matrix{Float64}
ERROR: LoadError: Enzyme execution failed.
Mismatched activity for:   store {} addrspace(10)* %.fca.0.0.0.0.extract, {} addrspace(10)** %.fca.0.0.0.gep, align 8, !dbg !253, !noalias !240 const val:   %.fca.0.0.0.0.extract = extractvalue { { [1 x [8 x {} addrspace(10)*]], {} addrspace(10)*, {} addrspace(10)* } } %0, 0, 0, 0, 0, !dbg !97
Type tree: {[-1]:Pointer, [-1,0]:Pointer, [-1,0,0]:Pointer, [-1,0,0,-1]:Integer, [-1,0,8]:Integer, [-1,0,9]:Integer, [-1,0,10]:Integer, [-1,0,11]:Integer, [-1,0,12]:Integer, [-1,0,13]:Integer, [-1,0,14]:Integer, [-1,0,15]:Integer, [-1,0,16]:Integer, [-1,0,17]:Integer, [-1,0,18]:Integer, [-1,0,19]:Integer, [-1,0,20]:Integer, [-1,0,21]:Integer, [-1,0,22]:Integer, [-1,0,23]:Integer, [-1,0,24]:Integer, [-1,0,25]:Integer, [-1,0,26]:Integer, [-1,0,27]:Integer, [-1,0,28]:Integer, [-1,0,29]:Integer, [-1,0,30]:Integer, [-1,0,31]:Integer, [-1,0,32]:Integer, [-1,0,33]:Integer, [-1,0,34]:Integer, [-1,0,35]:Integer, [-1,0,36]:Integer, [-1,0,37]:Integer, [-1,0,38]:Integer, [-1,0,39]:Integer, [-1,8]:Pointer, [-1,8,0]:Pointer, [-1,8,0,-1]:Integer, [-1,8,8]:Integer, [-1,8,9]:Integer, [-1,8,10]:Integer, [-1,8,11]:Integer, [-1,8,12]:Integer, [-1,8,13]:Integer, [-1,8,14]:Integer, [-1,8,15]:Integer, [-1,8,16]:Integer, [-1,8,17]:Integer, [-1,8,18]:Integer, [-1,8,19]:Integer, [-1,8,20]:Integer, [-1,8,21]:Integer, [-1,8,22]:Integer, [-1,8,23]:Integer, [-1,8,24]:Integer, [-1,8,25]:Integer, [-1,8,26]:Integer, [-1,8,27]:Integer, [-1,8,28]:Integer, [-1,8,29]:Integer, [-1,8,30]:Integer, [-1,8,31]:Integer, [-1,8,32]:Integer, [-1,8,33]:Integer, [-1,8,34]:Integer, [-1,8,35]:Integer, [-1,8,36]:Integer, [-1,8,37]:Integer, [-1,8,38]:Integer, [-1,8,39]:Integer, [-1,16]:Pointer, [-1,16,0]:Pointer, [-1,16,0,-1]:Integer, [-1,16,8]:Integer, [-1,16,9]:Integer, [-1,16,10]:Integer, [-1,16,11]:Integer, [-1,16,12]:Integer, [-1,16,13]:Integer, [-1,16,14]:Integer, [-1,16,15]:Integer, [-1,16,16]:Integer, [-1,16,17]:Integer, [-1,16,18]:Integer, [-1,16,19]:Integer, [-1,16,20]:Integer, [-1,16,21]:Integer, [-1,16,22]:Integer, [-1,16,23]:Integer, [-1,16,24]:Integer, [-1,16,25]:Integer, [-1,16,26]:Integer, [-1,16,27]:Integer, [-1,16,28]:Integer, [-1,16,29]:Integer, [-1,16,30]:Integer, [-1,16,31]:Integer, [-1,16,32]:Integer, [-1,16,33]:Integer, [-1,16,34]:Integer, [-1,16,35]:Integer, [-1,16,36]:Integer, [-1,16,37]:Integer, [-1,16,38]:Integer, [-1,16,39]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer, [-1,40]:Integer, [-1,41]:Integer, [-1,42]:Integer, [-1,43]:Integer, [-1,44]:Integer, [-1,45]:Integer, [-1,46]:Integer, [-1,47]:Integer, [-1,48]:Integer, [-1,49]:Integer, [-1,50]:Integer, [-1,51]:Integer, [-1,52]:Integer, [-1,53]:Integer, [-1,54]:Integer, [-1,55]:Integer, [-1,56]:Integer, [-1,57]:Integer, [-1,58]:Integer, [-1,59]:Integer, [-1,60]:Integer, [-1,61]:Integer, [-1,62]:Integer, [-1,63]:Integer}
 llvalue=  %.fca.0.0.0.0.extract = extractvalue { { [1 x [8 x {} addrspace(10)*]], {} addrspace(10)*, {} addrspace(10)* } } %0, 0, 0, 0, 0, !dbg !97
You may be using a constant variable as temporary storage for active memory (https://enzyme.mit.edu/julia/stable/faq/#Activity-of-temporary-storage). If not, please open an issue, and either rewrite this variable to not be conditionally active or use Enzyme.API.runtimeActivity!(true) as a workaround for now

Stacktrace:
 [1] _evaluate!!
   @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:967
 [2] evaluate_threadunsafe!!
   @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:941
 [3] evaluate!!
   @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:894
 [4] logdensity
   @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:100
 [5] logdensity
   @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:0

Stacktrace:
  [1] throwerr(cstr::Cstring)
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/compiler.jl:1623
  [2] _evaluate!!
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:967 [inlined]
  [3] evaluate_threadunsafe!!
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:941 [inlined]
  [4] evaluate!!
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/model.jl:894 [inlined]
  [5] logdensity
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:100 [inlined]
  [6] logdensity
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:0 [inlined]
  [7] diffejulia_logdensity_3369_inner_1wrap
    @ ~/.julia/packages/DynamicPPL/ACaKr/src/logdensityfunction.jl:0
  [8] macro expansion
    @ ~/.julia/dev/Enzyme/src/compiler.jl:6622 [inlined]
  [9] enzyme_call
    @ ~/.julia/dev/Enzyme/src/compiler.jl:6223 [inlined]
 [10] CombinedAdjointThunk
    @ ~/.julia/dev/Enzyme/src/compiler.jl:6100 [inlined]
 [11] autodiff
    @ ~/.julia/dev/Enzyme/src/Enzyme.jl:309 [inlined]
 [12] autodiff(::EnzymeCore.ReverseMode{…}, ::typeof(LogDensityProblems.logdensity), ::Type{…}, ::EnzymeCore.Const{…}, ::EnzymeCore.Duplicated{…})
    @ Enzyme ~/.julia/dev/Enzyme/src/Enzyme.jl:321
 [13] top-level scope
    @ ~/projects/Enzyme-mwes/ref_minus_float/mwe.jl:118
 [14] include(fname::String)
    @ Base.MainInclude ./client.jl:489
 [15] top-level scope
    @ REPL[1]:1
in expression starting at /Users/mhauru/projects/Enzyme-mwes/ref_minus_float/mwe.jl:98
Some type information was truncated. Use `show(err)` to see complete types.

@wsmoses
Copy link
Member

wsmoses commented Jul 8, 2024

Original issue should be fixed on main (and just tagged), reopen if it persists.

@wsmoses wsmoses closed this as completed Jul 8, 2024
@mhauru
Copy link
Contributor Author

mhauru commented Jul 9, 2024

With runtimeActivity enabled, this now fails with the error of TuringLang/Turing.jl#1621 (BigFloats).

Without runtimeActivity, this still fails with the error I pasted in the above comment:

ERROR: Enzyme execution failed.
Mismatched activity for:   store {} addrspace(10)* %.fca.0.0.0.0.extract, {} addrspace(10)** %.fca.0.0.0.gep, align 8, !dbg !253, !noalias !240 const val:   %.fca.0.0.0.0.extract = extractvalue { { [1 x [8 x {} addrspace(10)*]], {} addrspace(10)*, {} addrspace(10)* } } %0, 0, 0, 0, 0, !dbg !97
Type tree: {[-1]:Pointer, [-1,0]:Pointer, [-1,0,0]:Pointer, [-1,0,0,-1]:Integer, [-1,0,8]:Integer, [-1,0,9]:Integer, [-1,0,10]:Integer, [-1,0,11]:Integer, [-1,0,12]:Integer, [-1,0,13]:Integer, [-1,0,14]:Integer, [-1,0,15]:Integer, [-1,0,16]:Integer, [-1,0,17]:Integer, [-1,0,18]:Integer, [-1,0,19]:Integer, [-1,0,20]:Integer, [-1,0,21]:Integer, [-1,0,22]:Integer, [-1,0,23]:Integer, [-1,0,24]:Integer, [-1,0,25]:Integer, [-1,0,26]:Integer, [-1,0,27]:Integer, [-1,0,28]:Integer, [-1,0,29]:Integer, [-1,0,30]:Integer, [-1,0,31]:Integer, [-1,0,32]:Integer, [-1,0,33]:Integer, [-1,0,34]:Integer, [-1,0,35]:Integer, [-1,0,36]:Integer, [-1,0,37]:Integer, [-1,0,38]:Integer, [-1,0,39]:Integer, [-1,8]:Pointer, [-1,8,0]:Pointer, [-1,8,0,-1]:Integer, [-1,8,8]:Integer, [-1,8,9]:Integer, [-1,8,10]:Integer, [-1,8,11]:Integer, [-1,8,12]:Integer, [-1,8,13]:Integer, [-1,8,14]:Integer, [-1,8,15]:Integer, [-1,8,16]:Integer, [-1,8,17]:Integer, [-1,8,18]:Integer, [-1,8,19]:Integer, [-1,8,20]:Integer, [-1,8,21]:Integer, [-1,8,22]:Integer, [-1,8,23]:Integer, [-1,8,24]:Integer, [-1,8,25]:Integer, [-1,8,26]:Integer, [-1,8,27]:Integer, [-1,8,28]:Integer, [-1,8,29]:Integer, [-1,8,30]:Integer, [-1,8,31]:Integer, [-1,8,32]:Integer, [-1,8,33]:Integer, [-1,8,34]:Integer, [-1,8,35]:Integer, [-1,8,36]:Integer, [-1,8,37]:Integer, [-1,8,38]:Integer, [-1,8,39]:Integer, [-1,16]:Pointer, [-1,16,0]:Pointer, [-1,16,0,-1]:Integer, [-1,16,8]:Integer, [-1,16,9]:Integer, [-1,16,10]:Integer, [-1,16,11]:Integer, [-1,16,12]:Integer, [-1,16,13]:Integer, [-1,16,14]:Integer, [-1,16,15]:Integer, [-1,16,16]:Integer, [-1,16,17]:Integer, [-1,16,18]:Integer, [-1,16,19]:Integer, [-1,16,20]:Integer, [-1,16,21]:Integer, [-1,16,22]:Integer, [-1,16,23]:Integer, [-1,16,24]:Integer, [-1,16,25]:Integer, [-1,16,26]:Integer, [-1,16,27]:Integer, [-1,16,28]:Integer, [-1,16,29]:Integer, [-1,16,30]:Integer, [-1,16,31]:Integer, [-1,16,32]:Integer, [-1,16,33]:Integer, [-1,16,34]:Integer, [-1,16,35]:Integer, [-1,16,36]:Integer, [-1,16,37]:Integer, [-1,16,38]:Integer, [-1,16,39]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer, [-1,40]:Integer, [-1,41]:Integer, [-1,42]:Integer, [-1,43]:Integer, [-1,44]:Integer, [-1,45]:Integer, [-1,46]:Integer, [-1,47]:Integer, [-1,48]:Integer, [-1,49]:Integer, [-1,50]:Integer, [-1,51]:Integer, [-1,52]:Integer, [-1,53]:Integer, [-1,54]:Integer, [-1,55]:Integer, [-1,56]:Integer, [-1,57]:Integer, [-1,58]:Integer, [-1,59]:Integer, [-1,60]:Integer, [-1,61]:Integer, [-1,62]:Integer, [-1,63]:Integer}
 llvalue=  %.fca.0.0.0.0.extract = extractvalue { { [1 x [8 x {} addrspace(10)*]], {} addrspace(10)*, {} addrspace(10)* } } %0, 0, 0, 0, 0, !dbg !97
You may be using a constant variable as temporary storage for active memory (https://enzyme.mit.edu/julia/stable/faq/#Activity-of-temporary-storage). If not, please open an issue, and either rewrite this variable to not be conditionally active or use Enzyme.API.runtimeActivity!(true) as a workaround for now

Any idea if that should be expected, i.e. if there's a reason why runtimeActivity would be necessary here?

I don't have the powers to reopen.

@wsmoses
Copy link
Member

wsmoses commented Jul 9, 2024

Can you open a new issue for the runtime activity issue (and this can be left as the ref subtract)

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