I have tested with FullSpecialize.
The code was changed to:
f_ode(du, u, p, t) = f(du, u, p, t, Val(N))
jac_sparsity = jac_sparsity_adtypes(u0, f_ode, p)
fun = ODEFunction(f_ode, jac_prototype=jac_sparsity)
prob = ODEProblem{true, SciMLBase.FullSpecialize}(fun, u0, tspan, p)
function loss(p, sensealg)
prob_remake = remake(prob, u0 = eltype(p).(u0), p = p)
sum(solve(prob_remake, algo, saveat=0.1, sensealg=sensealg, abstol=abstol, reltol=reltol, maxiters=1000_000_000))
end
Nevertheless the resulting plot is basically identical to the previous one.
