Skip to content

Commit 70bb2c4

Browse files
committed
Fix JETExt
1 parent d9292ad commit 70bb2c4

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

ext/DynamicPPLJETExt.jl

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,35 @@ end
2121
function DynamicPPL.Experimental._determine_varinfo_jet(
2222
model::DynamicPPL.Model; only_ddpl::Bool=true
2323
)
24-
# First we try with the typed varinfo.
24+
# Generate a typed varinfo to test model type stability with
2525
varinfo = DynamicPPL.typed_varinfo(model)
2626

27-
# Let's make sure that evaluation doesn't result in type errors.
28-
issuccess, result = DynamicPPL.Experimental.is_suitable_varinfo(
27+
# Check type stability of evaluation (i.e. DefaultContext)
28+
model = DynamicPPL.contextualize(
29+
model, DynamicPPL.setleafcontext(model.context, DynamicPPL.DefaultContext())
30+
)
31+
eval_issuccess, eval_result = DynamicPPL.Experimental.is_suitable_varinfo(
2932
model, varinfo; only_ddpl
3033
)
31-
32-
if !issuccess
33-
# Useful information for debugging.
34+
if !eval_issuccess
3435
@debug "Evaluation with typed varinfo failed with the following issues:"
35-
@debug result
36+
@debug eval_result
37+
end
38+
39+
# Check type stability of initialisation (i.e. InitContext)
40+
model = DynamicPPL.contextualize(
41+
model, DynamicPPL.setleafcontext(model.context, DynamicPPL.InitContext())
42+
)
43+
init_issuccess, init_result = DynamicPPL.Experimental.is_suitable_varinfo(
44+
model, varinfo; only_ddpl
45+
)
46+
if !init_issuccess
47+
@debug "Initialisation with typed varinfo failed with the following issues:"
48+
@debug init_result
3649
end
3750

38-
# If we didn't fail anywhere, we return the type stable one.
39-
return if issuccess
51+
# If neither of them failed, we can return the typed varinfo as it's type stable.
52+
return if (eval_issuccess && init_issuccess)
4053
varinfo
4154
else
4255
# Warn the user that we can't use the type stable one.

0 commit comments

Comments
 (0)