-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fix for #596 #597
Fix for #596 #597
Conversation
The type-instabilities had been observed before too, e.g. see the test case now uncommented in this PR, but hadn't investigated it yet and thought it was for different reasons, so big thanks to @willtebbutt for discovering this! |
Pull Request Test Coverage Report for Build 8989979287Details
💛 - Coveralls |
@yebai @devmotion @sunxd3 thoughts on this? I think the main issue is: do we want to introduce more magic (here we perform a simple transformation on very specific parameters)? As outlined above, I'm pro doing it for now as it will have significant impact on user code (type-stability and perf wise + will make some AD backends much faster) and I consider this a bugfix (given how we spout this pattern as a way of achieving signfiicnat performance gains). Long-term we might want to make these things explicit, but for now I like this. |
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.
Great!
we can always just remove the magic at a later stage and tell the user to use TypeWrap instead of Type going forward.
I think ideally we would not have to use TypeWrap
internally. But IMO the "magic" is better than exposing TypeWrap
, I think we should not require users to know about such details (and even if it would be in the docs I am sure the majority of users would unknowingly use Type
).
Does this just require a patch bump? |
Co-authored-by: David Widmann <[email protected]>
…es' into torfjelde/type-instabilities-fixes
Cheers @devmotion !
Done. |
I've been running some benchmarks locally with ForwardDiff, ReverseDiff, and Zygote, and it doesn't seem like there are any perf improvements 🙃 With the exception of models using EDIT: But there consistently less memory usage, so it's at least doing something:) |
Love this! |
So integration tests are failing because we're explicitly testing passing in types as arguments. It does raise the question as to whether we should make this breaking or not 🤔 Thoughts? |
Can we have both? That is, could we forward |
Was thinking about the same. But so now we generate 3 methods instead? And should we issue a dep warning? Or do we also add an evaluator with this, leading to 4 methods? |
Hmm on a second thought, I don't think we can 😕 If we try to keep the old method around, we will define the default method twice. Only if we remove the default values for the |
tbf there's probably no one using this functionality outside of Turing.jl's own tests, so probably isn't a huge problem to make a breaking change to it |
Sounds good. |
Is anything missing here? If not, let's try to get this merged. |
…es' into torfjelde/type-instabilities-fixes
src/compiler.jl
Outdated
@@ -599,7 +631,7 @@ is_splat_symbol(s::Symbol) = startswith(string(s), "#splat#") | |||
Builds the output expression. | |||
""" | |||
function build_output(modeldef, linenumbernode) | |||
args = modeldef[:args] | |||
args = transform_args(modeldef[:args]) | |||
kwargs = modeldef[:kwargs] |
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 this should probably be applied to keyword arguments as well?
kwargs = modeldef[:kwargs] | |
kwargs = transform_args(modeldef[:kwargs]) |
(not sure if it can be applied directly here in this way)
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.
Why? Do we care if we specialize on the kwargs?
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.
IIRC we store them in the same way as pos arguments in the model.
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.
So the Model
will generally still operate with DataType
s unless we apply the same fix to kwarga.
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.
No you're right 👍 Working on it now
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.
Added this 👍
Only question: do we make this a breaking release or not? @devmotion thoughts? Technically it's breaking so I am leaning towards this. |
Probably better to make this breaking release since it breaks Turing tests anyway |
I'd also make it a breaking release. |
It seems auto merging is quite fragile — it needs disabling and then re-enabling to fix unknown failures. |
Please let the author of the PR perform the merge @yebai ; in this case it was fine, but it's not always the case. |
See #596 for a description of the issue. Fix #596
This PR automates the approach suggested by @willtebbutt, making it so that
is effectively converted into the current
ensuring that
model.args
does not involveDataType
, leading to significant improvements in type-stability for both the evaluator and the constructor.`EDIT: Note that this change is a bit annoying as it does introduce "more magic" in DynamicPPL, but I'm personally happy with this for now as it technically fixes a bunch of type stability bugs. If we want to be explicit about what's happening, we can always just remove the magic at a later stage and tell the user to use
TypeWrap
instead ofType
going forward.