|
21 | 21 | function DynamicPPL.Experimental._determine_varinfo_jet(
|
22 | 22 | model::DynamicPPL.Model; only_ddpl::Bool=true
|
23 | 23 | )
|
24 |
| - # First we try with the typed varinfo. |
| 24 | + # Generate a typed varinfo to test model type stability with |
25 | 25 | varinfo = DynamicPPL.typed_varinfo(model)
|
26 | 26 |
|
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( |
29 | 32 | model, varinfo; only_ddpl
|
30 | 33 | )
|
31 |
| - |
32 |
| - if !issuccess |
33 |
| - # Useful information for debugging. |
| 34 | + if !eval_issuccess |
34 | 35 | @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 |
36 | 49 | end
|
37 | 50 |
|
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) |
40 | 53 | varinfo
|
41 | 54 | else
|
42 | 55 | # Warn the user that we can't use the type stable one.
|
|
0 commit comments