-
Notifications
You must be signed in to change notification settings - Fork 32
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
Introduction of model_typed
and model_warntype
in DebugUtils
#708
Conversation
`model_warntype` for the checking of the model's evaluator
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #708 +/- ##
==========================================
+ Coverage 81.90% 84.35% +2.44%
==========================================
Files 30 30
Lines 4200 4211 +11
==========================================
+ Hits 3440 3552 +112
+ Misses 760 659 -101 ☔ View full report in Codecov by Sentry. |
Pull Request Test Coverage Report for Build 11779219137Details
💛 - 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.
I think it is very helpful. Also happy to depend on InteractiveUtils
.
@willtebbutt you might want to help review this PR too.
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.
I really like this, and agree that InteractiveUtils is a perfectly fine dep to have.
So, I think that the concept is basically fine. Will this stuff automatically appear in the docs, or do we need to add it in manually?
While I think you should feel free to merge this PR without this, could I ask whether you would consider exposing a function which returns the function + arguments that you pass to fargs, kwargs = get_args_for_analysis(model, varinfo, context)) with the same default values for I guess the implementation would be something like function get_args_for_analysis(model, varinfo=default_thing, context=default_thing)
args, kargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
return (f, args...), kwargs
end The reason to want this, is that
|
Yep, can do @willtebbutt ! |
Wait; why is that function you defined simpler than just doing |
Added |
…rfjelde/code-warntype
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
It's a simpler interface, rather than implementation. It's about ensuring that we have a single source of truth that you can point people towards (and put in the docs) that says "here is everything you need -- we promise that this is the thing that you should profile for performance", as opposed to having to know that the edit: having now looked at this a bit more closely, am I correct that you can always do: fargs, kwargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
fargs[1](fargs[2:end]...; kwargs...) in order to evaluate the correct thing? |
Also, I've just realised that this functionality is not tested, and doesn't appear in the docs. It would be good to add a unit test which just runs Also, could you please add these to a debug section in the docs? |
Nah, it's model.f(args...; kwargs...) The evaluator |
Added docs and testing @willtebbutt |
…rfjelde/code-warntype
I don't feel especially strongly either way. Personally, I like having it with the arguments because for Mooncake.jl-related stuff, where the distinction between function and argument is not really there (e.g. when using |
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 ready to go once the patch version has been bumped.
As I said, I don't want my other request to get in the way of getting this released. I'm happy to re-review if you do want to implement that as part of this PR though @torfjelde . I'll open an issue about it if you don't fancy doing it as part of this PR.
to (what seems like) escaping issues
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
`gen_evaluator_call_with_types` + added docs, as requested by my dear @willtebbutt
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
LGTM. Thanks for indulging my requests!
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.
Sorry, I was hasty. Just realised that there's a problem with the docstring.
src/debug_utils.jl
Outdated
|
||
# Returns | ||
A 2-tuple with the following elements: | ||
- `ftype::Type`: The function type of the evaluator. This is either `model.f` or `Core.kwcall`, depending on whether |
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 function doesn't actually return the type of the function in question, it returns the function itself. I don't mind which one we do, but this docstring should be fixed before merging!
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.
Might be good to add a unit test to make sure that this is actually doing whatever the docstring asserts is happening.
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.
Oh damn, good catch!
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.
Thanks for fixing -- LGTM.
I wanted to do some checking of type-stability for a model. Unfortunately, this is quite annoying to do in a way where you can inspect the inferred types of the model's evaluator function.
Hence I was thinking it might be useful to have a few simple methods which just does the set up + calls
@code_warntype
onmodel.f
(and similarly for@code_typed
). This PR therefore introducesmodel_warntype
andmodel_typed
in theDebugUtils
module which does exactly this.I think this is particularly useful for users who wants to check type-stability of their model, which IMO should be able to do so without extensive knowledge of DynamicPPL internals.
The downside: have to add InteractiveUtils.jl as a direct dep (though it's part of base, so should be fine).
Thoughts?