feat: use native Mooncake HVP in forward-over-reverse - #1042
Conversation
HVP in forward-over-reverse
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1042 +/- ##
===========================================
- Coverage 47.66% 26.65% -21.01%
===========================================
Files 136 132 -4
Lines 8044 8006 -38
===========================================
- Hits 3834 2134 -1700
- Misses 4210 5872 +1662
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Tried out with using CUDA
using Mooncake
using DifferentiationInterface
using LinearAlgebra
const DI = DifferentiationInterface
logp(x) = -0.5f0 * sum(abs2, x)
x_gpu = CUDA.CuArray(randn(Float32, 8))
v_gpu = CUDA.CuArray(ones(Float32, 8))
cache = DI.prepare_hvp(logp, AutoMooncake(), x_gpu, (v_gpu,)) # failsAs it fails with a diff error. Same one on PMCMC, using Mooncake
using CUDA
using Random
logp(x) = -0.5f0 * sum(abs2, x)
x_gpu = CUDA.CuArray(randn(Float32, 8))
v_gpu = CUDA.CuArray(ones(Float32, 8))
cache = prepare_hvp_cache(logp, x_gpu)
value_and_hvp!!(cache, logp, v_gpu, x_gpu)But reading 1248 upstream this wouldn't work anyway yet |
|
I wasn't clear: when you use DI for a Mooncake HVP, you have to explicitly build a |
|
Oh my bad, also on me, I wasn't looking closely. I'll redo the example to ensure I get the same error |
|
Hrm actually getting a different error: using CUDA
using Mooncake
using DifferentiationInterface
using LinearAlgebra
const DI = DifferentiationInterface
logp(x) = -0.5f0 * sum(abs2, x)
x_gpu = CUDA.CuArray(randn(Float32, 8))
v_gpu = CUDA.CuArray(ones(Float32, 8))
mk_so = SecondOrder(AutoMooncakeForward(), AutoMooncake())
cache = DI.prepare_hvp(logp, mk_so, x_gpu, (v_gpu,))
Hv_gpu = similar(x_gpu)
hvp_returned = DI.hvp!(
logp,
(Hv_gpu,),
cache,
mk_so,
x_gpu,
(v_gpu,),
) |
|
Woops, silly me. It should be better now |
Fixes #990 (can't use
Mooncake.hessianyet because it is restrictive type-wise)