Skip to content

Use AbstractPPL AD interface in tests.#460

Merged
yebai merged 3 commits into
mainfrom
replace-di-with-abstractppl
May 21, 2026
Merged

Use AbstractPPL AD interface in tests.#460
yebai merged 3 commits into
mainfrom
replace-di-with-abstractppl

Conversation

@yebai
Copy link
Copy Markdown
Member

@yebai yebai commented Apr 23, 2026

Replacing #458

TODO

  • uncomment min / LTS tests.
  • remove AbstractPPL pinned sources.

@github-actions
Copy link
Copy Markdown
Contributor

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

@yebai yebai force-pushed the replace-di-with-abstractppl branch 3 times, most recently from 876b60e to a0d363b Compare May 18, 2026 14:13
@testset "Mooncake bijector AD" begin
for c in generate_ad_testcases(), adtype in adtypes
run_ad_case(c, adtype)
# AbstractPPL's Mooncake extension routes `AutoMooncakeForward` through
Copy link
Copy Markdown
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 Mooncake bug -- hopefully it will get fixed as part of chalk-lab/Mooncake.jl#1151

@yebai yebai force-pushed the replace-di-with-abstractppl branch 5 times, most recently from a7a9eb1 to 4ccf99a Compare May 19, 2026 16:56
`src/vector/test_utils.jl` and `test/test_resources.jl` route all AD calls
through `AbstractPPL.prepare` + `value_and_jacobian!!` / `value_and_gradient!!`
in place of `DifferentiationInterface.jacobian` / `DI.gradient`. The package
no longer depends on DifferentiationInterface directly; it remains a transitive
test dep so AbstractPPL can dispatch to the DI extension for the
`AutoForwardDiff` reference and for any other adtype that lacks a direct
AbstractPPL extension.

Other changes that follow from the routing switch:

- `Project.toml` and the per-integration-suite `Project.toml`s bump
  `AbstractPPL = "0.15"` and add `ADTypes = "1"`; DI moves to a test-only dep.
- `src/vector/test_utils.jl`: `test_optics` and `test_logjac` skip the
  AD-based check for discrete distributions — `AbstractPPL.prepare` rejects
  the integer vectors that `to_vec(d)` returns, and those checks are
  tautological for identity link transforms anyway.
- `test/integration_tests/mooncake/main.jl`: PlanarLayer-inverse cases under
  `AutoMooncakeForward` hit Mooncake's batched NDual code path, which has no
  rule for `find_alpha`, so mark them `broken=true`.
- `test/integration_tests/enzyme/main.jl`: the triple-nested product cases
  throw an Enzyme runtime `TypeError` that `@test_broken` doesn't reliably
  catch; switch to `skip=true` so non-AD checks still run.
- `docs/src/defining_examples.md`: the StereographicProj example now uses
  `ForwardDiff.jacobian` directly instead of `DI.jacobian`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yebai yebai force-pushed the replace-di-with-abstractppl branch from 4ccf99a to 795cb59 Compare May 19, 2026 20:37
@yebai yebai requested a review from sunxd3 May 19, 2026 21:39
@yebai
Copy link
Copy Markdown
Member Author

yebai commented May 20, 2026

@sunxd3, this should be ready for a final look.

Copy link
Copy Markdown
Member

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

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

sorry for nagging,

## Testing
Because the scope of a vector bijector is very well-defined, there is a well-established testing framework to verify correctness of an implementation (`Bijectors.VectorBijectors.test_all()`), which you can use in the test suite.
This function contains additional keyword arguments to control the exact testing procedure.
For example, you can test that the transformations do not cause extra allocations, should you know this to be the case for your bijector (note that this is not always possible).
For more information about generally testing bijectors (and in particular how to test Jacobians for transformations that modify the number of dimensions), see [the documentation on examples of defining bijectors](@ref bijectors-defining-examples).
One of the most tricky parts of testing Bijectors is ensuring that the transforms are compatible with automatic differentiation.
This is important for DynamicPPL: we need to be able to compute the gradient of the log-density with respect to (possibly transformed) parameters, which may include the log-abs-det-Jacobian of the transformation.
`test_all` accepts an `adtypes` keyword argument and defaults to `[AutoForwardDiff()]`, so the main test suite exercises ForwardDiff as the reference backend.
ReverseDiff, Mooncake, and Enzyme are covered by standalone integration suites under `test/integration_tests/<backend>/`, each of which passes its own `adtypes` list through to `test_all`.
It is acceptable to skip tests for a particular backend if there are genuine upstream bugs, especially with ReverseDiff, which is not actively maintained.
Where possible it is best to ensure that all backends are supported, and to use `@test_broken` to mark any known issues with specific backends.

need to be updated again on because default_adtypes is now empty

Comment thread docs/Project.toml
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yebai
Copy link
Copy Markdown
Member Author

yebai commented May 21, 2026

All addressed @sunxd3!

@yebai yebai merged commit d758493 into main May 21, 2026
18 of 21 checks passed
@yebai yebai deleted the replace-di-with-abstractppl branch May 21, 2026 09:49
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.

2 participants