You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purpose of the control_flow model is to demonstrate errors with compiled ReverseDiff:
using DynamicPPL, LogDensityProblems, Distributions, ADTypes, ForwardDiff, ReverseDiff
@modelfunctioncontrol_flow()
a ~Normal()
if a >0
b ~Normal()
else
b ~Beta(2, 2)
endend# Gradient preparation
model =control_flow()
adtype =AutoReverseDiff(; compile=true)
vi = DynamicPPL.unflatten(VarInfo(model), [0.5, -0.5]) # note: a > 0 and b < 0
ldf =LogDensityFunction(model, vi; adtype=adtype)
# For comparison
ldf_ref =LogDensityFunction(model, vi; adtype=AutoForwardDiff())
# Two sets of parameters
p1 = [0.5, -0.5] # a > 0, b < 0
p2 = [-0.5, 0.5] # a < 0, b > 0
julia> LogDensityProblems.logdensity_and_gradient(ldf, p1)
(-2.0878770664093453, [-0.5, 0.5])
julia> LogDensityProblems.logdensity_and_gradient(ldf_ref, p1)
(-2.0878770664093453, [-0.5, 0.5])
julia> LogDensityProblems.logdensity_and_gradient(ldf, p2)
(-2.0878770664093453, [0.5, -0.5])
julia> LogDensityProblems.logdensity_and_gradient(ldf_ref, p2)
(-0.6384734250965083, [0.5, 0.0])
As can be seen from the above, the gradient evaluates correctly at p1, but incorrectly at p2. The issue is that reproducing this is contingent on choosing the right set parameters to pass to the model; if we pass p1 it looks like compiled ReverseDiff runs fine.
The text was updated successfully, but these errors were encountered:
penelopeysm
changed the title
control_flow model
control_flow model runs unreliably
Apr 8, 2025
Although (as far as I can tell) it's not currently possible to control the values used to prepare the gradient in a Scenario JuliaDiff/DifferentiationInterface.jl#771
The purpose of the
control_flow
model is to demonstrate errors with compiled ReverseDiff:As can be seen from the above, the gradient evaluates correctly at
p1
, but incorrectly atp2
. The issue is that reproducing this is contingent on choosing the right set parameters to pass to the model; if we passp1
it looks like compiled ReverseDiff runs fine.The text was updated successfully, but these errors were encountered: