-
Notifications
You must be signed in to change notification settings - Fork 7
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
Issue with DI benchmarking #193
Comments
Thanks for finding this. Will investigate. |
Hmm I'm actually not able to reproduce locally. Could you provide the output of |
Okay indeed in a fresh environment with just Tapir and DI on the latest stable release of everything this doesn't happen. But it did happen in the benchmark environment of SciML/SciMLBenchmarks.jl#988. Investigating |
Apparently it has something to do with how DifferentiationInterfaceTest handles benchmarking, with julia> using DifferentiationInterface, DifferentiationInterfaceTest
julia> import Zygote, Tapir
julia> function paritytrig(x::AbstractVector{T}) where {T}
y = zero(T)
for i in eachindex(x)
if iseven(i)
y += sin(x[i])
else
y += cos(x[i])
end
end
return y
end
paritytrig (generic function with 1 method)
julia> backends = [
AutoTapir(safe_mode=true),
AutoZygote(),
];
julia> scenarios = [
GradientScenario(paritytrig; x=rand(2), y=0.0, nb_args=1, place=:inplace),
];
julia> data = benchmark_differentiation(backends, scenarios, logging=true);
[ Info: Compiling rule for Tuple{typeof(paritytrig), Vector{Float64}} in safe mode. Disable for best performance.
[ Info: Compiling rule for Tuple{typeof(paritytrig), Vector{Float64}} in safe mode. Disable for best performance.
[ Info: Compiling rule for Tuple{typeof(paritytrig), Vector{Float64}} in safe mode. Disable for best performance.
┌ Warning: Error during benchmarking
│ ba = AutoTapir()
│ scen = Scenario{:gradient,1,:inplace} paritytrig : Vector{Float64} -> Float64
│ e = deepcopy of Modules not supported
└ @ DifferentiationInterfaceTest ~/.julia/packages/DifferentiationInterfaceTest/qCkMA/src/tests/benchmark.jl:659
◐ Benchmarking Time: 0:00:25
julia> data
6×11 DataFramee: gradient - 1/1
Row │ backend scenario operator calls samples evals time allocs bytes gc_fraction compile_fraction
│ Abstract… Scenario… Symbol Int64 Int64 Int64 Float64 Float64 Float64 Float64 Float64
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ AutoTapir() Scenario{:gradient,1,:inplace} p… prepare_gradient -1 1 0 NaN NaN NaN NaN NaN
2 │ AutoTapir() Scenario{:gradient,1,:inplace} p… value_and_gradient! -1 1 0 NaN NaN NaN NaN NaN
3 │ AutoTapir() Scenario{:gradient,1,:inplace} p… gradient! -1 1 0 NaN NaN NaN NaN NaN
4 │ AutoZygote() Scenario{:gradient,1,:inplace} p… prepare_gradient 0 1 1 8.18e-7 0.0 0.0 0.0 0.0
5 │ AutoZygote() Scenario{:gradient,1,:inplace} p… value_and_gradient! 1 3606 1 1.899e-5 150.0 6048.0 0.0 0.0
6 │ AutoZygote() Scenario{:gradient,1,:inplace} p… gradient! 1 3610 1 1.8669e-5 144.0 5872.0 0.0 0.0 Environment: (jl_mSTJJ6) pkg> st
Status `/tmp/jl_mSTJJ6/Project.toml`
[a0c0ee7d] DifferentiationInterface v0.5.7
[a82114a7] DifferentiationInterfaceTest v0.5.0
[07d77754] Tapir v0.2.23
[e88e6eb3] Zygote v0.6.70
julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 8 default, 0 interactive, 4 GC (on 8 virtual cores)
Environment:
JULIA_EDITOR = code Will try to see if I can replicate the original error |
Ah, so it looks like I can't currently |
Okay. I'm now trying to figure out what's causing the world age probem. |
Sorry that I wasn't able to reproduce it, not sure how I managed to trigger it |
No problem. I'm also struggling to reliably reproduce. Are the tests running successfully on your end now, or still not working? |
Okay. Something about loading using DifferentiationInterface, DifferentiationInterfaceTest#, DataFrames, DataFramesMeta
import Tapir
# import Markdown, PrettyTables, Printf
function paritytrig(x::AbstractVector{T}) where {T}
y = zero(T)
for i in eachindex(x)
if iseven(i)
y += sin(x[i])
else
y += cos(x[i])
end
end
return y
end
extras = prepare_gradient(paritytrig, AutoTapir(safe_mode=true), randn(2)); If you don't load Precompiling Tapir
1 dependency successfully precompiled in 49 seconds. 123 already precompiled.
[ Info: Precompiling Tapir [07d77754-e150-4737-8c94-cd238a1fb45b]
┌ Warning: Module JET with build ID fafbfcfd-4a2e-9e0b-0000-37430629e6f6 is missing from the cache.
│ This may mean JET [c3a54625-cd67-489e-a8e7-0a5a0ff4e31b] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:1948
[ Info: Skipping precompilation since __precompile__(false). Importing Tapir [07d77754-e150-4737-8c94-cd238a1fb45b].
[ Info: Precompiling DifferentiationInterfaceTapirExt [0114fd55-92e5-5207-bbe9-7aed827b60c7]
┌ Warning: Module Tapir with build ID ffffffff-ffff-ffff-0000-375957f870c8 is missing from the cache.
│ This may mean Tapir [07d77754-e150-4737-8c94-cd238a1fb45b] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:1948
[ Info: Skipping precompilation since __precompile__(false). Importing DifferentiationInterfaceTapirExt [0114fd55-92e5-5207-bbe9-7aed827b60c7]. There are no warnings when I load DI + DITest |
If it's obvious to you what's going on, please let me know. Otherwise I'm going to continue debugging. |
Okay. If I remove |
No, especially because JET is a dependency of DifferentiationInterfaceTest (it's used for type stability checks). On the other hand does Tapir really need it as a dependency? See #122 |
Alas, it's pretty integral to our performance testing, and I'm not planning on splitting that testing out any time soon. We should just try to figure out what might be going on. |
I think it might be one of those cases where @aviatesk is needed |
In a somewhat concerning turn of events, if I load packages in a different order, things work: using DifferentiationInterface, DataFrames, DataFramesMeta
import Tapir, Enzyme
using DifferentiationInterfaceTest
import Markdown, PrettyTables, Printf
function paritytrig(x::AbstractVector{T}) where {T}
y = zero(T)
for i in eachindex(x)
if iseven(i)
y += sin(x[i])
else
y += cos(x[i])
end
end
return y
end
backends = [
AutoEnzyme(mode=Enzyme.Reverse),
AutoTapir(safe_mode=false),
]
scenarios = [
GradientScenario(paritytrig; x=rand(100), y=0.0, nb_args=1, place=:inplace),
GradientScenario(paritytrig; x=rand(10_000), y=0.0, nb_args=1, place=:inplace)
];
data = benchmark_differentiation(backends, scenarios, logging=true);
table = PrettyTables.pretty_table(
String,
data;
header=names(data),
formatters=PrettyTables.ft_printf("%.1e"),
)
Markdown.parse(table) |
I feel like there probably is something bad going on on Tapir.jl's end -- it's not obvious to me that it ought to matter whether we're able to precompile properly or not. |
A more minimal example of a failure: using DifferentiationInterfaceTest # if you don't load this, then precompilation works fine, and this is all fine
import Tapir
Tapir.tangent_type(Base.OneTo{Int64}) # note: this is a generated function. I don't know if that's important. |
Okay, so it looks like it's generated-function related, which is quite annoying. If I change the order in which certain functions are defined, then everything seems to be fine. I don't really understand why this is an issue, and I don't really know how to test that this doesn't become an issue again, or whether there are other such problems lurking around. @gdalle what do you think we should do here? |
I don't know, and I've never used generated functions so I'm afraid I can't help much. |
I really have no idea. I'd point out though that there are also precompilation issues with DIT when it's loaded after Tapir.jl, they just don't manifest in the same way. So I imagine you'll have the same precompilation issues if another package uses JET and you load up DIT. In this sense, I think we've both got problems. Would be helpful to know if @aviatest has thoughts on what might be going on -- I'm not really sure how to debug |
@aviatesk sorry for the ping, do you think you might be able to help here? |
SciML/SciMLBenchmarks.jl#988 works now. |
Hey there Tapir people, found this bug for you on the street, with Tapir v0.2.23
The text was updated successfully, but these errors were encountered: