Skip to content

Fix CUDA tests #433

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

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions research/src/riemannian_hmc_utility.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Random, LinearAlgebra, ReverseDiff, ForwardDiff, VecTargets
using Random, LinearAlgebra, ReverseDiff, ForwardDiff, MCMCLogDensityProblems

# Fisher information metric
function gen_∂G∂θ_rev(Vfunc, x; f=identity)
_Hfunc = VecTargets.gen_hess(Vfunc, ReverseDiff.track.(x))
_Hfunc = MCMCLogDensityProblems.gen_hess(Vfunc, ReverseDiff.track.(x))
Hfunc = x -> _Hfunc(x)[3]
# QUES What's the best output format of this function?
return x -> ReverseDiff.jacobian(x -> f(Hfunc(x)), x) # default output shape [∂H∂x₁; ∂H∂x₂; ...]
Expand Down Expand Up @@ -37,7 +37,7 @@ end

function prepare_sample_target(hps, θ₀, ℓπ)
Vfunc = x -> -ℓπ(x) # potential energy is the negative log-probability
_Hfunc = VecTargets.gen_hess(Vfunc, θ₀) # x -> (value, gradient, hessian)
_Hfunc = MCMCLogDensityProblems.gen_hess(Vfunc, θ₀) # x -> (value, gradient, hessian)
Hfunc = x -> copy.(_Hfunc(x)) # _Hfunc do in-place computation, copy to avoid bug

fstabilize = H -> H + hps.λ * I
Expand Down Expand Up @@ -70,8 +70,8 @@ function prepare_sample(hps; rng=MersenneTwister(1110))

θ₀ = rand(rng, dim(target))

ℓπ = VecTargets.gen_logpdf(target)
∂ℓπ∂θ = VecTargets.gen_logpdf_grad(target, θ₀)
ℓπ = MCMCLogDensityProblems.gen_logpdf(target)
∂ℓπ∂θ = MCMCLogDensityProblems.gen_logpdf_grad(target, θ₀)

_, _, Gfunc, ∂G∂θfunc = prepare_sample_target(hps, θ₀, ℓπ)

Expand Down
4 changes: 2 additions & 2 deletions research/tests/riemannian_hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ using AdvancedHMC: neg_energy, energy

θ₀ = rand(rng, dim(target))

ℓπ = VecTargets.gen_logpdf(target)
∂ℓπ∂θ = VecTargets.gen_logpdf_grad(target, θ₀)
ℓπ = MCMCLogDensityProblems.gen_logpdf(target)
∂ℓπ∂θ = MCMCLogDensityProblems.gen_logpdf_grad(target, θ₀)

Vfunc, Hfunc, Gfunc, ∂G∂θfunc = prepare_sample_target(hps, θ₀, ℓπ)

Expand Down
2 changes: 1 addition & 1 deletion research/tests/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Comonicon, ReTest

using Pkg;
Pkg.add(; url="https://github.com/xukai92/VecTargets.jl.git");
Pkg.add(; url="https://github.com/chalk-lab/MCMCLogDensityProblems.jl.git");

# include the source code for experimental HMC
include("../src/relativistic_hmc.jl")
Expand Down
5 changes: 3 additions & 2 deletions test/CUDA/cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ using Pkg
Pkg.activate(@__DIR__)
Pkg.develop(; path=joinpath(@__DIR__, "..", ".."))

include(joinpath(@__DIR__, "..", "common.jl"))

using Test
using AdvancedHMC
using AdvancedHMC: DualValue, PhasePoint
using CUDA
using LogDensityProblems

include(joinpath(@__DIR__, "..", "common.jl"))

@testset "AdvancedHMC GPU" begin
n_chains = 1000
Expand Down
Loading