Open avik-pal opened 2 days ago
```julia
ERROR: AssertionError: Base.isconcretetype(typ)
Stacktrace:
[1] abs_typeof(arg::LLVM.LoadInst, partial::Bool, seenphis::Set{LLVM.PHIInst})
@ Enzyme.Compiler /mnt/.julia/packages/Enzyme/RTS5U/src/absint.jl:557
[2] abs_typeof(arg::LLVM.LoadInst)
@ Enzyme.Compiler /mnt/.julia/packages/Enzyme/RTS5U/src/absint.jl:283
[3] 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 /mnt/.julia/packages/Enzyme/RTS5U/src/compiler.jl:7066
[4] codegen
@ /mnt/.julia/packages/Enzyme/RTS5U/src/compiler.jl:6146 [inlined]
[5] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
@ Enzyme.Compiler /mnt/.julia/packages/Enzyme/RTS5U/src/compiler.jl:8468
[6] _thunk
@ /mnt/.julia/packages/Enzyme/RTS5U/src/compiler.jl:8468 [inlined]
[7] cached_compilation
@ /mnt/.julia/packages/Enzyme/RTS5U/src/compiler.jl:8509 [inlined]
[8] thunkbase(ctx::LLVM.Context, mi::Core.MethodInstance, ::Val{…}, ::Type{…}, ::Type{…}, tt::Type{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Type{…}, ::Val{…}, ::Val{…})
@ Enzyme.Compiler /mnt/.julia/packages/Enzyme/RTS5U/src/compiler.jl:8641
[9] #s2105#19135
@ /mnt/.julia/packages/Enzyme/RTS5U/src/compiler.jl:8778 [inlined]
[10]
@ Enzyme.Compiler ./none:0
[11] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
@ Core ./boot.jl:707
[12] autodiff
@ /mnt/.julia/packages/Enzyme/RTS5U/src/Enzyme.jl:633 [inlined]
[13] autodiff
@ /mnt/.julia/packages/Enzyme/RTS5U/src/Enzyme.jl:512 [inlined]
[14] macro expansion
@ /mnt/.julia/packages/Enzyme/RTS5U/src/Enzyme.jl:2090 [inlined]
[15] gradient(::ForwardMode{…}, ::StatefulLuxLayer{…}, ::Reactant.TracedRArray{…}; chunk::Val{…}, shadows::Tuple{…})
@ Enzyme /mnt/.julia/packages/Enzyme/RTS5U/src/Enzyme.jl:1970
[16] #jacobian#133
@ /mnt/.julia/packages/Enzyme/RTS5U/src/Enzyme.jl:2177 [inlined]
[17] jacobian
@ /mnt/.julia/packages/Enzyme/RTS5U/src/Enzyme.jl:2176 [inlined]
[18] ∇potential(potential::StatefulLuxLayer{…}, x::Reactant.TracedRArray{…})
@ Main /mnt/software/lux/Lux.jl/docs/src/manual/nested_autodiff_reactant.md:17
[19] Fix1
@ ./operators.jl:1127 [inlined]
[20] #apply#24
@ /mnt/software/lux/Reactant.jl/src/utils.jl:37 [inlined]
[21] apply
@ /mnt/software/lux/Reactant.jl/src/utils.jl:36 [inlined]
[22] (::Tuple{})(none::Base.Fix1{typeof(∇potential), StatefulLuxLayer{…}}, none::Tuple{Reactant.TracedRArray{…}})
@ Base.Experimental ./
just for fun what if you do set_abi(Forward, ReactantABI)
That did work!
yeah so this is again stemming from "any abstract interpreter based shenanigans fails to go through type unstable code".
Here the actual resolution we did earlier is to make Forward be replaced by set_abi(Forward, ReactantABI) in our absint. This makes things way nicer (including doing the replacement at the callsite of autodiff/jacobian/etc), so any intermediates that are type unstable don't have any issues. Similarly, it means we can natively call it like above. Unfortunately this only applies at the top level absint.
Probably the solution here is to have the absint replace type unstable calls with my_call(...) which itself runs things again in an absint.
A non-minimal example taken from https://github.com/LuxDL/Lux.jl/issues/614