Skip to content

JET + Mooncake fixes for 1.12 #921

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
61 changes: 61 additions & 0 deletions .github/workflows/DocTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# We want to only run doctests on a single version of Julia, because
# things like error messages / output can change between versions and
# is fragile to test against.
name: Doctests

on:
push:
branches:
- main
pull_request:
merge_group:
types: [checks_requested]

# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read

# Cancel existing tests on the same PR if a new commit is added to a pull request
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: julia-actions/setup-julia@v2
with:
version: '1'

- uses: julia-actions/cache@v2

- uses: julia-actions/julia-buildpkg@v1

- name: Run doctests
shell: julia --color=yes --depwarn=yes --project=docs {0}
run: |
# Develop currently checked out version of DynamicPPL
using Pkg
Pkg.develop(path=pwd())
Pkg.instantiate()

using Documenter, DynamicPPL, Distributions

DocMeta.setdocmeta!(
DynamicPPL,
:DocTestSetup,
:(using DynamicPPL, Distributions);
recursive=true,
)
doctestfilters = [
# Ignore the source of a warning in the doctest output, since this is dependent on host.
# This is a line that starts with "└ @ " and ends with the line number.
r"└ @ .+:[0-9]+",
]

doctest(DynamicPPL; manual=false, doctestfilters=doctestfilters)
10 changes: 10 additions & 0 deletions .github/workflows/JuliaPre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ permissions:
jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
test_group:
- Group1
- Group2

steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
Expand All @@ -22,3 +30,5 @@ jobs:
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
GROUP: ${{ matrix.test_group }}
4 changes: 3 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## 0.36.4

Added compatibility with DifferentiationInterface.jl 0.7.
Added compatibility with DifferentiationInterface.jl 0.7, and also with JET.jl 0.10.

The JET compatibility entry should only affect you if you are using DynamicPPL on the Julia 1.12 pre-release.

## 0.36.3

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DocStringExtensions = "0.9"
EnzymeCore = "0.6 - 0.8"
ForwardDiff = "0.10.12"
InteractiveUtils = "1"
JET = "0.9"
JET = "0.9, 0.10"
KernelAbstractions = "0.9.33"
LinearAlgebra = "1.6"
LogDensityProblems = "2"
Expand Down
3 changes: 2 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
AbstractPPL = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand All @@ -23,7 +24,7 @@ DocumenterMermaid = "0.1, 0.2"
DynamicPPL = "0.36"
FillArrays = "0.13, 1"
ForwardDiff = "0.10"
JET = "0.9"
JET = "0.9, 0.10"
LogDensityProblems = "2"
MCMCChains = "5, 6"
StableRNGs = "1"
6 changes: 1 addition & 5 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -41,14 +39,12 @@ Compat = "4.3.0"
DifferentiationInterface = "0.6.41, 0.7"
Distributions = "0.25"
DistributionsAD = "0.6.3"
Documenter = "1"
EnzymeCore = "0.6 - 0.8"
ForwardDiff = "0.10.12"
JET = "0.9"
JET = "0.9, 0.10"
LogDensityProblems = "2"
MCMCChains = "6.0.4"
MacroTools = "0.5.6"
Mooncake = "0.4.95"
OrderedCollections = "1"
ReverseDiff = "1"
StableRNGs = "1"
Expand Down
17 changes: 11 additions & 6 deletions test/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ using DynamicPPL: LogDensityFunction
@testset "Automatic differentiation" begin
# Used as the ground truth that others are compared against.
ref_adtype = AutoForwardDiff()
test_adtypes = [
AutoReverseDiff(; compile=false),
AutoReverseDiff(; compile=true),
AutoMooncake(; config=nothing),
]

test_adtypes = if IS_PRERELEASE
[AutoReverseDiff(; compile=false), AutoReverseDiff(; compile=true)]
else
[
AutoReverseDiff(; compile=false),
AutoReverseDiff(; compile=true),
AutoMooncake(; config=nothing),
]
end

@testset "Unsupported backends" begin
@model demo() = x ~ Normal()
Expand All @@ -16,7 +21,7 @@ using DynamicPPL: LogDensityFunction
)
end

@testset "Correctness: ForwardDiff, ReverseDiff, and Mooncake" begin
@testset "Correctness" begin
@testset "$(m.f)" for m in DynamicPPL.TestUtils.DEMO_MODELS
rand_param_values = DynamicPPL.TestUtils.rand_prior_true(m)
vns = DynamicPPL.TestUtils.varnames(m)
Expand Down
30 changes: 12 additions & 18 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ using Bijectors
using DifferentiationInterface
using Distributions
using DistributionsAD
using Documenter
using ForwardDiff
using LogDensityProblems
using MacroTools
using MCMCChains
using Mooncake: Mooncake
using StableRNGs
using ReverseDiff
using Zygote
Expand All @@ -34,10 +32,18 @@ using OrderedCollections: OrderedSet

using DynamicPPL: getargs_dottilde, getargs_tilde

# These flags are set in CI
const GROUP = get(ENV, "GROUP", "All")
const AQUA = get(ENV, "AQUA", "true") == "true"
Random.seed!(100)

# Detect if prerelease version, if so, we skip some tests
const IS_PRERELEASE = !isempty(VERSION.prerelease)
if !IS_PRERELEASE
Pkg.add("Mooncake")
using Mooncake: Mooncake
end

Random.seed!(100)
include("test_util.jl")

@testset verbose = true "DynamicPPL.jl" begin
Expand Down Expand Up @@ -81,26 +87,14 @@ include("test_util.jl")
end
@testset "ad" begin
include("ext/DynamicPPLForwardDiffExt.jl")
include("ext/DynamicPPLMooncakeExt.jl")
if !IS_PRERELEASE
include("ext/DynamicPPLMooncakeExt.jl")
end
include("ad.jl")
end
@testset "prob and logprob macro" begin
@test_throws ErrorException prob"..."
@test_throws ErrorException logprob"..."
end
@testset "doctests" begin
DocMeta.setdocmeta!(
DynamicPPL,
:DocTestSetup,
:(using DynamicPPL, Distributions);
recursive=true,
)
doctestfilters = [
# Ignore the source of a warning in the doctest output, since this is dependent on host.
# This is a line that starts with "└ @ " and ends with the line number.
r"└ @ .+:[0-9]+",
]
doctest(DynamicPPL; manual=false, doctestfilters=doctestfilters)
end
end
end
Loading