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
Optional profiling #41
Conversation
If param 'profile' is FALSE, all profiling statements are removed from the stan model code before compilation Removal of profiling statements in other files in include paths not yet supported
Codecov Report
@@ Coverage Diff @@
## main #41 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 13 13
Lines 641 648 +7
=====================================
- Misses 641 648 +7
Continue to review full report at Codecov.
|
One more interesting thing to note: Generally, switching from profiling to no profiling requires a recompilation of the stan model. However, once the model has been compiled with I lack a deeper understanding of what goes on during profiling under the hood, but it seems that the profiling statements are handled separately from the main stan C code. If we don't want to confuse users with the recompilation, we could hence change the model instantiation function such that if |
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.
This is really great and will be super useful going forward.
Not surprised that the likelihood is so dominant compute wise (though I would expect that to change with more flexible models where more delay distributions need to be calculated). #40 has reinforced my view that optimisation wise most of run-time in the likelihood (that we can do something about) is linked to the coversion from hazard to probability but you are correct being able to profile within functions would be useful to confirm this. Do you think (and can you in fact do this) it is worth inserting some profiling into the generated quantities to see if optimisation is worth doing with that code. Part of me wants it to remain relatively clear but if that comes at a big speed cost then it isn't worth it.
Left some very minor comments on this PR. There are also some issues that the automated linting is flagging that would be good to correct to keep a consistent style. We should maybe talk about setting up automated PR tools to allow styling, redocing etc using github actions.
/document |
/style |
Changed names of the profiling sections. There is always a prefix now that states the corresponding stan block: "transformed", "model", "generated". Moreover, changed the names of the sections to be more concise and like variables.
@seabbs I added profiling statements to the generated quantities section. If you think everything is fine, you can already merge into |
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.
This looks good to go in main
to me. Will merge and can do another PR for in function profiling (which will be very nice to have).
This PR implements optional profiling of nowcasting models. Profiling of stan models as offered by cmdstan is useful for debugging and performance optimization (see https://mc-stan.org/cmdstanr/articles/profiling.html). However, it also comes with a slight overhead, making it suboptimal to have profiling activated by default. Stan does not offer an option to turn profiling on and off at the moment. This PR implements a workaround which allows to keep the profiling statements in the same model that will be used for deployment by adding a corresponding option to enw_model. If
profile=FALSE
, all profiling statements are removed from the model code before compilation.Some basic profiling statements are added to epinowcast.stan for illustration.
Further details:
profile=FALSE
.profile=FALSE
. Extending to these include files at a later stage should not be too difficult however.