Skip to content

Add Enzyme testing as a separate CI action #950

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 6 commits into from
Jun 4, 2025
Merged
Changes from 1 commit
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
58 changes: 58 additions & 0 deletions .github/workflows/Enzyme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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

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

- name: Run AD with Enzyme on demo models
shell: julia --color=yes {0}
run: |
# Set up fresh environment
using Pkg
Pkg.activate(; temp=true)
Pkg.develop(path=".")
Pkg.add(["Enzyme", "ForwardDiff", "ADTypes", "Test"])

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
import 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