Skip to content

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Aug 14, 2025

This PR reworks most of Bijectors' CI setup to be more manageable.

  • Use DifferentiationInterface instead of directly calling ForwardDiff.gradient, etc.

  • Test all AD backends in a single CI job. The tests don't take very long at all so this is not a problem in terms of time. It also allows us to restructure the test_ad function so that we can more surgically disable / enable tests. The previous one was very awkward to work with.

  • Disable / enable failing Enzyme tests as needed to make CI pass without the use of continue-on-error. Where possible we use @test_throws instead of just skipping the test as that will let us know if and when a test begins to work

  • Separate doctests into a standalone CI job that only runs on 1.11. Doctest output can depend on Julia version so it can be very fragile running doctests on multiple different CI setups.

  • Cache the Julia environment in CI. Saves time.

  • Add a couple of CI runners on Windows.

Closes #373
Closes #347 (not directly, but I think the intent behind that was really 'clean up the Enzyme tests', and this PR does so)

Copy link
Contributor

Bijectors.jl documentation for PR #406 is available at:
https://TuringLang.github.io/Bijectors.jl/previews/PR406/

@penelopeysm penelopeysm changed the title Refactor AD tests Refactor CI Aug 14, 2025
@TuringLang TuringLang deleted a comment from github-actions bot Aug 14, 2025
@TuringLang TuringLang deleted a comment from github-actions bot Aug 14, 2025
@penelopeysm penelopeysm marked this pull request as draft August 14, 2025 22:43
@TuringLang TuringLang deleted a comment from github-actions bot Aug 15, 2025
@TuringLang TuringLang deleted a comment from github-actions bot Aug 15, 2025
@penelopeysm
Copy link
Member Author

penelopeysm commented Aug 15, 2025

Well look at that those green ticks, not had that for a while on Bijectors.

@penelopeysm penelopeysm marked this pull request as ready for review August 15, 2025 00:47
Copy link
Member Author

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments (hopefully helpful)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subsumed into CI.yml.

docs/make.jl Outdated
Comment on lines 19 to 20
# TODO: Remove this
warnonly=true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a replacement for strict=false which no longer works with Documenter.jl v1.0. It converts all docs errors into warnings. This is not good, but I didn't want fix this in this PR as well, it should be a separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how difficult a fix is it? As much as possible I think we should avoid merging broken things to main, it feels distinctly wrong unless it's an urgent fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#412 fixed this so I can actually remove it!

test_frule(Bijectors.find_alpha, x, y, z)
test_rrule(Bijectors.find_alpha, x, y, z)

if @isdefined Mooncake
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to test/ad/mooncake.jl

@test _xs == xs
end

function test_bijector_parameter_gradient(b::Bijectors.Transform, x, y=b(x))
Copy link
Member Author

@penelopeysm penelopeysm Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function was not being used anywhere so can be deleted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is no longer needed, the test_ad function is directly defined in test/runtests.jl

@TuringLang TuringLang deleted a comment from github-actions bot Aug 22, 2025
@TuringLang TuringLang deleted a comment from github-actions bot Aug 22, 2025
@TuringLang TuringLang deleted a comment from github-actions bot Aug 22, 2025
docs/make.jl Outdated
Comment on lines 19 to 20
# TODO: Remove this
warnonly=true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how difficult a fix is it? As much as possible I think we should avoid merging broken things to main, it feels distinctly wrong unless it's an urgent fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to do this? The whole enzyme stuff seems very messy still.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what you mean by messy / what could be done to make it less so? I think it seems as clean as it can be already.


x = rand(dist)
y = b(x)
@testset "VecCholeskyBijector: $backend_name" for (backend_name, adtype) in TEST_ADTYPES
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain TEST_ADTYPES array to me in more detail? Is this the best way to do things with this fixed array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much. The idea is that Bijectors provides these functions f and you want to make sure that it can be differentiated with all adtypes of interest. The same sort of loop is used elsewhere see e.g.

https://github.com/TuringLang/Turing.jl/blob/296f6540d069afd7347ad17680ea87cf7a666652/test/ad.jl#L240-L264

https://github.com/TuringLang/DynamicPPL.jl/blob/72491583d9b04f9e4689b756d0d593fa94caade1/test/ad.jl#L40-L47

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and each adtype corresponds to an AD backend of interest (plus some configuration options e.g. whether to use forward- or reverse-mode).

test/ad/flows.jl Outdated
end
test_ad(randn(11)) do θ
if ENZYME_FWD_AND_1p11
@test_throws Enzyme.Compiler.EnzymeInternalError test_ad(f, adtype, randn(7))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I'm linking right, should the finv and ginv be used or is this correctly referenced for what you want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks

@penelopeysm
Copy link
Member Author

These Enzyme tests are so frustratingly flaky, I had marked all the failures but between the time I made this PR and now there are different failures popping up.

@penelopeysm penelopeysm requested a review from sunxd3 September 26, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace ForwardDiff/ReverseDiff/Zygote/Mooncake/Enzyme gradient call with DifferentiationInterface. Move all Enzyme related tests into a seprate CI
2 participants