Closed roflmaostc closed 3 months ago
You could try with a larger stack size, e.g.,
y = Task(64 * 1024^2) do
Enzyme.autodiff(Enzyme.ReverseWithPrimal, Duplicated(f, make_zero(f)), Duplicated(pp, dp))
end |> schedule |> fetch
?
This works
kernel! = f_kernel!(get_backend(measurement))
function f(pp)
buffer .= .- measurement
kernel!(buffer, pp, x, ndrange=(N, length(measurement)))
return sum(abs2, buffer)
end
So I suppose the issue is somehow that kernel construct from KA?
@MilesCranmer I think this is just probably an accidental infinite recursion where the object isn't added to the "seen" set when it ought be
Fixed by https://github.com/EnzymeAD/Enzyme.jl/pull/1665.
Note that you will then hit an issue where a type unstable MixedDuplicated of a closure is not yet supported.
julia> @time fg2!(2, copy(params0), params0)
ERROR: MethodError: no method matching Duplicated(::var"#f_kernel!#10"{var"#gpu_f_kernel!#9", var"#cpu_f_kernel!#8"}, ::Base.RefValue{var"#f_kernel!#10"{var"#gpu_f_kernel!#9", var"#cpu_f_kernel!#8"}})
Closest candidates are:
Duplicated(::T1, ::T1) where T1
@ EnzymeCore ~/git/Enzyme.jl/lib/EnzymeCore/src/EnzymeCore.jl:66
Duplicated(::T1, ::T1, ::Bool) where T1
@ EnzymeCore ~/git/Enzyme.jl/lib/EnzymeCore/src/EnzymeCore.jl:66
Stacktrace:
[1] runtime_generic_augfwd(activity::Type{Val{…}}, width::Val{1}, ModifiedBetween::Val{(true, true)}, RT::Val{@NamedTuple{…}}, f::var"#f_kernel!#10"{var"#gpu_f_kernel!#9", var"#cpu_f_kernel!#8"}, df::Base.RefValue{var"#f_kernel!#10"{…}}, primal_1::CPU, shadow_1_1::Nothing)
@ Enzyme.Compiler ~/git/Enzyme.jl/src/rules/jitrules.jl:313
[2] f
@ ./REPL[17]:11 [inlined]
[3] f
@ ./REPL[17]:0 [inlined]
[4] diffejulia_f_1728_inner_1wrap
@ ./REPL[17]:0
[5] macro expansion
@ ~/git/Enzyme.jl/src/compiler.jl:6646 [inlined]
[6] enzyme_call
@ ~/git/Enzyme.jl/src/compiler.jl:6246 [inlined]
[7] CombinedAdjointThunk
@ ~/git/Enzyme.jl/src/compiler.jl:6123 [inlined]
[8] autodiff
@ ~/git/Enzyme.jl/src/Enzyme.jl:314 [inlined]
[9] autodiff
@ ~/git/Enzyme.jl/src/Enzyme.jl:338 [inlined]
[10] (::var"#fg!#12"{var"#f#11"{Int64, Vector{Float64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Vector{Float64}}})(F::Int64, G::Vector{Float64}, p::Vector{Float64})
@ Main ./REPL[17]:23
[11] macro expansion
@ ./timing.jl:279 [inlined]
[12] top-level scope
@ ./REPL[21]:1
Feel free to open an issue for the follow up issue, but I'm going to close this one as completed once the box fix lands
Hi,
the following code errors.
If I move
kernel! = f_kernel!(get_backend(measurement))
outside off
and capture over it, then it does not error:Julia 1.10.4
Best,
Felix