You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed on slack, I am sharing an MWE to reproduce the issues with some backends on the GPU that I hit. I believe that most of these failures are very representative of the failures that I have seen also when using the low-level API of each backend so I believe that, largely, these are not DI's fault. But as suggested, I am sharing these anyway:
MWE
using Flux: Flux
using CUDA: CUDA
using Chairmarks:@beusing DifferentiationInterface: DifferentiationInterface as DI
# various DI backends that support pullbackusing Zygote: Zygote
using Enzyme: Enzyme
using Tracker: Tracker
using ReverseDiff: ReverseDiff
using Diffractor: Diffractor
using FiniteDiff: FiniteDiff
using Tapir: Tapir
# Without this, Enzyme errors out with "You may be using a constant variable as temporary storage for active memory"
Enzyme.API.runtimeActivity!(true)
functionmain(device = Flux.gpu, test_forward_pass =false)
# this just a toy model; in the real setting, the model has ~1M parameters, ~512 inputs and outputs, and is a fully-convolutional network
model = Flux.Chain(Flux.Dense(10, 32, Flux.relu), Flux.Dense(32, 10)) |> device
data =randn(Float32, 10, 100) |> device
labels =randn(Float32, 10, 100) |> device
σ =1.0f0
dy1 =randn(size(data)) |> device
dy2 =randn(size(data)) |> device
original_size =size(data)
functionf(x_t)
(model(x_t) - labels) .^2/ σ^2end# some of the backends require a flat input so this is a helper wrapperfunctionf_flat(x_t)
f(reshape(x_t, original_size))[:]
end# testing forward pass to give a reference point@info"ForwardPass..."@time"✅ initial run"f(data)
println("detailed benchmark:")
@be(f(data)) |> display
# NOTE:# only tested on the GPU
backends = [
DI.AutoZygote(), # ~0.05s
DI.AutoEnzyme(), # compiles for quite long, then errors out due to augmented forward pass custom rule type mismatch.
DI.AutoTracker(), # errors with `Tracker.TrackedReal{Float32} is a mutable type
DI.AutoReverseDiff(), # errors due because it generates code that tries to multiply CPU and GPU arrays
DI.AutoDiffractor(), # ERROR: MethodError: no method matching ndims(::Tuple{Int64, Int64})
DI.AutoFiniteDiff(), # ~18s
DI.AutoTapir(), # ERROR: CUDA.CuPtr{Nothing} is a primitive type. Implement a method of `tangent_type` for it.
]
# creating a lazy Jacobian-vector product operatorfor backend in backends
try@info"VJP with DI.jl and $backend"local pullback_prep
@time"✅ initial run"let@time"preparing pullback object..." pullback_prep =
DI.prepare_pullback_same_point(f_flat, backend, data[:], dy1[:])
@time"using it once" DI.pullback(f_flat, backend, data[:], dy1[:], pullback_prep)
endprintln("detailed benchmark:")
@be(DI.pullback(f_flat, backend, data[:], dy2[:], pullback_prep)) |> display
catch e
@error"Error with $backend: $e"
Base.show_backtrace(stdout, backtrace())
endendnothingend
This output is what I get from using the latest registered version of all backends in combination with JuliaGPU/CUDA.jl#2422 to facilitate Enzyme reverse diff on the GPU.
As discussed on slack, I am sharing an MWE to reproduce the issues with some backends on the GPU that I hit. I believe that most of these failures are very representative of the failures that I have seen also when using the low-level API of each backend so I believe that, largely, these are not DI's fault. But as suggested, I am sharing these anyway:
MWE
Program Output
https://pastebin.com/9kf9qqhG
Version Info
This output is what I get from using the latest registered version of all backends in combination with JuliaGPU/CUDA.jl#2422 to facilitate Enzyme reverse diff on the GPU.
Click to see output of `]status -m `
The text was updated successfully, but these errors were encountered: