- 
                Notifications
    You must be signed in to change notification settings 
- Fork 230
Use typed varinfo in Prior #2649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Turing.jl documentation for PR #2649 is available at: | 
| Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@            Coverage Diff             @@
##             main    #2649      +/-   ##
==========================================
- Coverage   85.70%   85.64%   -0.06%     
==========================================
  Files          22       22              
  Lines        1434     1442       +8     
==========================================
+ Hits         1229     1235       +6     
- Misses        205      207       +2     ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
61db751    to
    faf1318      
    Compare
  
    806c82d    to
    8af36e1      
    Compare
  
    faf1318    to
    422fc68      
    Compare
  
    8af36e1    to
    806c82d      
    Compare
  
    | Pull Request Test Coverage Report for Build 17377681902Details
 
 
 💛 - Coveralls | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct in thinking that this breaks prior sampling for
@model function f()
    x ~ Normal()
    if x > 0
        y ~ Normal()
    else
        z ~ Normal()
    end
endbut not for
@model function f()
    x ~ Normal()
    if x > 0
        y.a ~ Normal()
    else
        y.b ~ Normal()
    end
end?
If yes, I'm happy.
| Actually, both are broken, for different reasons. The first one seems to never change, the second just doesn't run. I'll have to investigate this further, I'm a bit confused as to why either of them are broken. | 
| This works: @model function f()
    x ~ Normal()
    if x > 0
        y ~ Normal()
    else
        z ~ Normal()
    end
endIt's because  MH and NUTS don't work on this model, only Prior does. This doesn't work: @model function f()
    x ~ Normal()
    y = (; a = 1.0, b = 1.0) # need this line so that it can assign to y.a or y.b
    if x > 0
        y.a ~ Normal()
    else
        y.b ~ Normal()
    end
endThe key  MH and NUTS also don't work on this model. | 
| I confirmed that both example models work on current release, when sampling with  I don't really mind losing @model function f()
    x ~ Normal()
    if x > 0
        y ~ Normal()
    else
        z ~ Normal()
    end
endI think that's syntax that we mostly don't support anyway. The one mostly I care about is actually @model function f()
    x ~ Normal()
    y = Vector{Float64}(undef, x > 0 ? 1 : 2)
    if x > 0
        y[1] ~ Normal()
    else
        y[1] ~ Normal()
        y[2] ~ Normal()
    end
endThat might be fine on this PR as-is? I'm not sure if I care about @model function f()
    x ~ Normal()
    y = (; a = 1.0, b = 1.0) # need this line so that it can assign to y.a or y.b
    if x > 0
        y.a ~ Normal()
    else
        y.b ~ Normal()
    end
endI just didn't realise that it would behave differently from the Vector version when I proposed it as a test case. | 
| 
 Yup, that still works on this PR. The x/y/z model also works on this PR, but x/y.a/y.b doesn't. I think in terms of the code, this PR is mostly good to go. (I believe CI failures will be fixed by #2650.) But I'm a bit hesitant to merge into the upcoming minor version, because it does technically remove support for a few models. In general, for arbitrary dynamic models like these, I think the solution to make sampling work is to use untyped VarInfo. That's what Prior used to do, which is also the only reason why it 'supported' all these things. The long term solution would be to let people sample with whatever kind of varinfo they want. That was (is?) the purpose of the sample-with-LDF PRs I still have sitting around. But right now I'm kind of leaning towards not merging this until those are in, just in the interests of not gratuitously breaking things. The flip side of course is that this PR does improve performance by a lot and it will probably be months until sample-with-LDF is merged. | 
| Without thinking this through carefully, I wonder if the performance gains are more important that losing support for some pretty niche models. Actually, now that I said that, maybe those niche models include all models with dynamic use of submodels? Still kinda niche though. Regardless, happy to leave it out of this upcoming release with DPPL 0.37. | 
42a3ceb    to
    ec8f165      
    Compare
  
    | Is it time to revisit this with InitContext? | 
| 
 I think InitContext makes things prettier but it doesn't solve the issue of same-symbol-but-different-type-VarName ( @model function f()
    if randn() > 0
        y.a ~ Normal()
    else
        y.b ~ Normal()
    end
endThere are a couple of ways of solving this properly: 
 I don't have a strong opinion on (1); but it does seem to me that independently of (1) we should still fix (2). To this end, I'll open an issue on DynamicPPL and also cheekily stick this on the list of topics for the JuliaCon hackathon. | 
Base branch:
This PR: