EnzymeAD / Enzyme.jl

Julia bindings for the Enzyme automatic differentiator
https://enzyme.mit.edu
MIT License
455 stars 63 forks source link

`no method matching reverse` with truncated Beta distribution #2010

Closed mhauru closed 2 weeks ago

mhauru commented 3 weeks ago

MWE:

import Enzyme; using Distributions
func = (a, b, α, β, x) -> logpdf(truncated(Beta(α, β), a, b), x)
args = (0.1, 0.9, 1.1, 1.3, 0.4)
Enzyme.gradient(Enzyme.Reverse, Enzyme.Const(func), args...)

Output:

ERROR: MethodError: no method matching reverse(::EnzymeCore.EnzymeRules.RevConfigWidth{…}, ::EnzymeCore.Const{…}, ::Type{…}, ::Any, ::EnzymeCore.Const{…}, ::EnzymeCore.Const{…}, ::EnzymeCore.Active{…})

Closest candidates are:
  reverse(::EnzymeCore.EnzymeRules.RevConfig, ::EnzymeCore.Const{Colon}, ::Any, ::Nothing, ::EnzymeCore.Annotation{T1}, ::EnzymeCore.Annotation{T2}, ::EnzymeCore.Annotation{T3}) where {T1<:AbstractFloat, T2<:AbstractFloat, T3<:AbstractFloat}
   @ Enzyme ~/.julia/dev/Enzyme/src/internal_rules.jl:1320
  reverse(::EnzymeCore.EnzymeRules.RevConfig, ::EnzymeCore.Const{typeof(Enzyme.pmap)}, ::Type{EnzymeCore.Const{Nothing}}, ::Any, ::BodyTy, ::Any, ::EnzymeCore.Annotation...) where {BodyTy, N}
   @ Enzyme ~/.julia/dev/Enzyme/src/internal_rules.jl:392
  reverse(::EnzymeCore.EnzymeRules.RevConfig, ::EnzymeCore.Const{Type{BigFloat}}, ::Type{<:Union{EnzymeCore.BatchDuplicated, EnzymeCore.BatchDuplicatedNoNeed, EnzymeCore.Duplicated, EnzymeCore.DuplicatedNoNeed}}, ::Any, ::Any...)
   @ Enzyme ~/.julia/dev/Enzyme/src/internal_rules.jl:1426
  ...

Stacktrace:
  [1] generic_methodinstance(ft::Type, tt::Type, world::UInt64)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/GnbhK/src/jlgen.jl:67
  [2] nested_codegen!(mode::Enzyme.API.CDerivativeMode, mod::LLVM.Module, f::Function, tt::Type, world::UInt64)
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/compiler.jl:1138
  [3] enzyme_custom_common_rev
    @ ~/.julia/dev/Enzyme/src/rules/customrules.jl:1042 [inlined]
  [4]
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/rules/customrules.jl:1574
  [5] enzyme_custom_rev_cfunc(B::Ptr{…}, OrigCI::Ptr{…}, gutils::Ptr{…}, tape::Ptr{…})
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/rules/llvmrules.jl:48
  [6] EnzymeCreatePrimalAndGradient(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{…}, TA::Enzyme.TypeAnalysis, returnValue::Bool, dretUsed::Bool, mode::Enzyme.API.CDerivativeMode, runtimeActivity::Bool, width::Int64, additionalArg::Ptr{…}, forceAnonymousTape::Bool, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{…}, augmented::Ptr{…}, atomicAdd::Bool)
    @ Enzyme.API ~/.julia/dev/Enzyme/src/api.jl:253
  [7] enzyme!(job::GPUCompiler.CompilerJob{…}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::NTuple{…}, returnPrimal::Bool, expectedTapeType::Type, loweredArgs::Set{…}, boxedArgs::Set{…})
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/compiler.jl:4000
  [8] codegen(output::Symbol, job::GPUCompiler.CompilerJob{…}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, toplevel::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/compiler.jl:7099
  [9] codegen
    @ ~/.julia/dev/Enzyme/src/compiler.jl:5932 [inlined]
 [10] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/compiler.jl:8207
 [11] _thunk
    @ ~/.julia/dev/Enzyme/src/compiler.jl:8207 [inlined]
 [12] cached_compilation
    @ ~/.julia/dev/Enzyme/src/compiler.jl:8248 [inlined]
 [13] thunkbase(ctx::LLVM.Context, mi::Core.MethodInstance, ::Val{…}, ::Type{…}, ::Type{…}, tt::Type{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Type{…}, ::Val{…}, ::Val{…})
    @ Enzyme.Compiler ~/.julia/dev/Enzyme/src/compiler.jl:8380
 [14] #s2072#19069
    @ ~/.julia/dev/Enzyme/src/compiler.jl:8517 [inlined]
 [15]
    @ Enzyme.Compiler ./none:0
 [16] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
    @ Core ./boot.jl:602
 [17] autodiff
    @ ~/.julia/dev/Enzyme/src/Enzyme.jl:473 [inlined]
 [18] macro expansion
    @ ~/.julia/dev/Enzyme/src/Enzyme.jl:1677 [inlined]
 [19] gradient(::EnzymeCore.ReverseMode{…}, ::EnzymeCore.Const{…}, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64)
    @ Enzyme ~/.julia/dev/Enzyme/src/Enzyme.jl:1660
 [20] top-level scope
    @ REPL[10]:6
Some type information was truncated. Use `show(err)` to see complete types.

Current Enzyme main, v0.13.12.

wsmoses commented 2 weeks ago

Seemingly resolved on main, reopen if not