Skip to content

Registered Enzyme rejects indexed-invariant tables over hcat of a parameter and a bound column (EnzymeRuntimeActivityError since 0.1.203) #59

Open

Description

@nsiccha

Summary

Since ReactiveKernels 0.1.203, native nested plates reuse scalar log / log1p / exp work on an array that every outer cell reads, by building runtime-sized tables before the outer loop. When that array is a column concatenation of a parameter vector and bound data, for example the whole-event capture mixture hcat(p, absent) with absent = zeros(T), ordinary Enzyme Reverse preparation fails on registered Enzyme (0.13.219, Enzyme_jll 0.0.307, Julia 1.13.1):

EnzymeRuntimeActivityError: Detected potential need for runtime activity.
Constant memory is stored (or returned) to a differentiable variable and correctness cannot be guaranteed with static activity analysis.
Mismatched activity for:   store ptr addrspace(10) %"absent::Array", ...

The derivative is defined. The same lowering differentiates on the Enzyme dogfood line (nsiccha/Enzyme.jl, checked at 720f5124 and 1ed42fb), without a copy of the constant column.

Cause

The table builder receives the lazy concatenation, a struct holding the parameter vector beside the constant vector, by reference in a function Julia does not inline. Registered Enzyme's static activity analysis cannot prove the constant field inactive once that slot escapes into the call. The same concatenation read inline inside the event loop, the lowering before 0.1.203, differentiates on registered Enzyme.

Reproducer (Enzyme only)

benchmark/repro_enzyme_lazy_hcat_table_const_column.jl. Output on Julia 1.13.1:

--- registered
Enzyme 0.13.219
static Reverse: EnzymeRuntimeActivityError
    Mismatched activity for:   store ptr addrspace(10) %"absent::Array", ptr %6, align 8, !dbg !65, !tbaa !31, !alias.scope !35, !noalias !66 const val: ptr addrspace(10) %"absent::Array"
runtime activity: max |gradient - closed form| = 0.0
--- dogfood
Enzyme 0.13.220
static Reverse: max |gradient - closed form| = 0.0
runtime activity: max |gradient - closed form| = 0.0

Effect in ReactiveKernels

  • prepare_sampler(...; backend = AutoEnzyme(; mode = Enzyme.Reverse)) of the PosteriorDB Mt_data-Mt_model port fails on registered Enzyme, for the default non-allocating sampler and the allocating one alike. With only the 0.1.203 table pass disabled, it prepares and matches the reference gradients to 4.3e-15. On dogfood, with the pass, it matches to 7.2e-15.
  • packages/ReactiveKernelsPPL/test/test_whole_event_invariants.jl ("natural whole-event invariant expressions") errors on registered Enzyme. Core test/test_indexed_invariants.jl passes there (133/133): its tables read all-parameter matrices.

Resolution

This is an Enzyme limitation. ReactiveKernels adds no workaround, and the test stays strict. Close this issue when a registered Enzyme release differentiates the reproducer under static Reverse, then remove the pointer comment in that test and the matching note in the consumer guidance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions