diff --git a/.github/workflows/Enzyme.yml b/.github/workflows/Enzyme.yml new file mode 100644 index 000000000..4fa32eef4 --- /dev/null +++ b/.github/workflows/Enzyme.yml @@ -0,0 +1,35 @@ +name: Enzyme on demo models + +on: + push: + branches: + - main + pull_request: + +# 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: + enzyme: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: julia-actions/setup-julia@v2 + with: + version: "1" + + - uses: julia-actions/cache@v2 + + - name: Run AD with Enzyme on demo models + working-directory: test/integration/enzyme + run: | + julia --project=. --color=yes -e 'using Pkg; Pkg.instantiate()' + julia --project=. --color=yes main.jl diff --git a/test/integration/enzyme/Project.toml b/test/integration/enzyme/Project.toml new file mode 100644 index 000000000..c26655fae --- /dev/null +++ b/test/integration/enzyme/Project.toml @@ -0,0 +1,9 @@ +[deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" +DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" +Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" +ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[sources] +DynamicPPL = {path = "../../../"} diff --git a/test/integration/enzyme/main.jl b/test/integration/enzyme/main.jl new file mode 100644 index 000000000..62b7ace4d --- /dev/null +++ b/test/integration/enzyme/main.jl @@ -0,0 +1,17 @@ +using DynamicPPL.TestUtils: DEMO_MODELS +using DynamicPPL.TestUtils.AD: run_ad +using ADTypes: AutoEnzyme +using Test: @test, @testset +import Enzyme: set_runtime_activity, Forward, Reverse +using ForwardDiff: ForwardDiff # run_ad uses FD for correctness test + +ADTYPES = Dict( + "EnzymeForward" => AutoEnzyme(; mode=set_runtime_activity(Forward)), + "EnzymeReverse" => AutoEnzyme(; mode=set_runtime_activity(Reverse)), +) + +@testset "$ad_key" for (ad_key, ad_type) in ADTYPES + @testset "$(model.f)" for model in DEMO_MODELS + @test run_ad(model, ad_type) isa Any + end +end