Skip to content

Add gradient preparation to invalidation rate#522

Open
pat-alt wants to merge 3 commits intomainfrom
521-add-gradient-preparation-for-invalidation-rate
Open

Add gradient preparation to invalidation rate#522
pat-alt wants to merge 3 commits intomainfrom
521-add-gradient-preparation-for-invalidation-rate

Conversation

@pat-alt
Copy link
Member

@pat-alt pat-alt commented Feb 18, 2026

@gdalle I've tried what you suggested in #518, but the prepared gradient doesn't match the executed gradient:

/home/runner/work/CounterfactualExplanations.jl/CounterfactualExplanations.jl/test/generators/probe.jl:19
  Got exception outside of a @test
  PreparationMismatchError (inconsistent types between preparation and execution):
    - f: ✅
    - backend: ✅
    - x: ❌
      - prep: Matrix{Float32}
      - exec: Matrix{ForwardDiff.Dual{ForwardDiff.Tag{typeof(CounterfactualExplanations.Generators.pen_wrt_state), Float32}, Float32, 2}}
    - contexts: ✅
  If you are confident that this check is superfluous, you can disable it by running preparation with the keyword argument `strict=Val(false)` inside DifferentiationInterface.

Any idea what be going on? Note that this gradient computation is nested inside another gradient computation - perhaps that's the issue?

@pat-alt pat-alt linked an issue Feb 18, 2026 that may be closed by this pull request
@gdalle
Copy link

gdalle commented Feb 27, 2026

Any idea what be going on? Note that this gradient computation is nested inside another gradient computation - perhaps that's the issue?

Your diagnosis is correct, I think you might need to replace similar(ce_state) in your preparation step by an array of the correct dual eltype. It's one of the most cumbersome things about DI, and functions like overloaded_input_type may help you do that, but an MWE would be most useful.

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.

Add gradient preparation for invalidation rate

2 participants