-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Remove size from distribution API #5754
Comments
Big agreement, users know shape already so why add a subtly new thing. |
Agree hiding size would help make things much more sane, especially because as examples proliferate if we have size and shape some people will use size, others will use shape, and with a split API itll cause recurring confusion. Very similar to how matplotlib as both |
This is a smart decision. Size can be left available for advanced users as an attribute, but no need to have it in the public API. |
Anyone wants to open a PR to this effect? |
Great idea, share with power users that its possible in a subtle way without confusing everyone else |
Hi, I am happy to work on this task. |
Thanks! Its yours for the taking |
I wouldn't like us to hide
>>> pm.draw(pm.MvNormal.dist(mu=np.zeros(5), cov=np.eye(5), shape=(3,))).shape
(5,)
>>> pm.draw(pm.MvNormal.dist(mu=np.zeros(1), cov=np.eye(1), shape=(3,))).shape
(1,)
>>> pm.draw(pm.Multinomial.dist(n=5, p=[0.1, 0.3, 0.6], shape=(5, 100))).shape
(5, 3) Furthermore, if you want to mimic the behavior of >>> pm.draw(pm.MvNormal.dist(mu=np.zeros((5, 1)), cov=[[1.]], shape=(3, 2, ...))).shape
(3, 2, 5, 1)
The only weird scenario is with time series distributions where the support can't be inferred from the distribution parameters, and needs to be specified using |
@lucianopaz You raise good points. If |
Also worth considering that we can add import aesara.tensor as at
import pymc as pm
x = pm.MvNormal.dist(mu=np.zeros(3), cov=np.eye(3), shape=(5,))
x = at.specify_shape(x, (5,))
pm.draw(x) # AssertionError: SpecifyShape: dim 0 of input has shape 3, expected 5. These asserts would most likely be constant folded during graph compilation so they won't pose any burden. The downside of this is that the outputs would no longer be pure Hopefully we will one day overcome this limitation (not only related to SpecifyShape, but also other cases like indexing, transposing, or doing transformations, the sort of thing that Aeppl focuses on), but it's an immediate downside if we were to add |
There are arguments to be made for either continuing with |
I feel we can convert to
Questions are if we should then actually add deprecation warnings for shape. We could probably add pretty smart ones that show exactly how the code needs to be changed. |
To be specific my vote is to remove one if possible. I trust the team to know which one i better to keep, and which one is better to "hide" |
I vote to recommend one or the other with a smart So smooth backwards compatibile update, followed by clear migration path. Which one is better? That's hard. (And the reason why IMO we should keep both until 4.1.0.) @lucianopaz brought up good arguments in favor of Note that We'd have to rethink Should this block 4.0.0? If I didn't have to write my thesis and could take a 3 week vacation to refactor this stuff (for the fourth time) together with two of you I'd say yes. The implementation we have right now is at least coherent. Also, the |
Right, the discussions we had back then @michaelosthege are coming back to me. One big motivator for keeping with shape/dims is that it's explicit, while
vs (if we made
(example says there are 5 correlated schools and 3 predictors/regressors). Although reading it now it doesn't seem so bad. But then there seems to be an inconsistency with pm.draw(pm.Normal.dist(mu=[0, 1, 2], size=(5, 3))).shape
>>> (5, 3)
pm.draw(pm.Normal.dist(mu=[0, 1, 2], shape=(5, 3))).shape
>>> (5, 3) So implied dimensions are only ignored when |
Hi, My opinion is that we should keep Why? because I am an amateur, and my knowledge about Besides, I am also not smart, and not good at thinking in a high-dimentional space or symbolic way, so I prefer When I start to use
So these are ideas that I think will help normal users:
Can we use Also, here we only mention about Maybe a good way is to explicitly list all the distributions and their possible usecases (how they are constructed or used). From that we can have a bigger picture to decide. PS. I wrote that |
I second the thought of keeping/maintaining Coming back to the example that @twiecki shared:
instead of
I would like to extend the question from @danhphan Can we use dims to explicitly specify different types of shape? If not, can we support working with dims to explicitly specify different types of shape? And to answer: Also, is the ndim_support = (event shape + batch shape )? |
ndim_supp is event dimensionality not shape. Tells you whether it's a scalar or vector but not how large |
I agree with @michaelosthege: keep both, deprecate shape and have a migration guide. The fact that dims behaves similarly to shape isn’t too bad, because dims can be used to label dimensions and set coordinate labels for post processing, not just to resize a random variable. |
Do we agree to keep both for 4.0.0 ? Because then we could move this issue to the 4.1.0 milestone. I feel like for experienced users But I fully agree with @danhphan in that the However, IMO, adding Starting with a 0-centered prior, and having observed >2 years of discussion on this topic, our posterior is still not clearly on one side. Maybe there's just a really tiny effect size? What's our uncertainty about...?
I'd say we have a pretty good estimate of the regret for 1-3:
But for 4-5 there's known regret + high uncertainty
Let's minimize our expected regret. |
Great points @michaelosthege. If indeed So I think we should teach |
I don't think that keeping one for "naive users" one for "experts" is any good. We still need to keep both in mind in the codebase, and most examples of code that users will see outside of perhaps the official documentation will be written by "experts" anyway. We will still have to think about what combinations of things we want to maintain, e.g., do we allow for ellipsis with size, or keep only with shape? |
Hi, Instead of discussing on what users may prefer between We have a strong community on discourse, so we can create a survey of 5 to 10 questions, and make a pin post on PyMC discourse, and ask for the community's opinions on this. Some questions like (we can discuss more on the details of what we will ask later if you think it is a suitable approach):
At the end of the day, the users are the ones who use these functions/APIs. So they are like the This will also give us more insights to make a more data-driven decision :) |
Had a great chat with @ricardoV94 and here's where I'm at. Pros of shape:
Pros of size:
In the past, For me the pros of So my (updated) proposal is to remove the |
Hi, should we proceed this? I add a couple of distributions that has
|
The biggest change is that size should no longer be accepted in the internal pymc/pymc/distributions/distribution.py Line 301 in 00d4372
pymc/pymc/distributions/distribution.py Line 346 in 00d4372
pymc/pymc/distributions/distribution.py Lines 348 to 350 in 00d4372
Then all the tests that make use of size and are not creating Finally the existing document on creating distributions will have to be updated to explain that PyMC distributions only accept shape, but the underlying RandomVariables or other methods that are dispatched on created RVs such as |
Removing it from the signature doesn't mean that it's no longer accepted - it can still be in the The internal code, like the
They wouldn't fail, because they'd just be passing another IMO we shouldn't make our life harder than need be. Remember that we currently have an implementation that's working fine on the technical level! |
Sure it's harder, but otherwise we will end up maintaining the two ways indefinitely. It will never be as easy as today, but also this issue does not need to be a blocker for V4. The decision was the important thing to get done quickly. |
We can put a FutureWarning just for 4.0 |
@pymc-devs/dev-core Rereading the discussion here it is not clear whether the consensus was towards:
I don't think anything is gained from 1). It will put a higher burden on reviewing official docs and eventually discourse questions related to size/shape and code that works with one and not the other will start to emerge. In the codebase we will have to keep expecting both sources of information at all stages prior to Again, I don't think this issue needs to be a blocker, but a clear decision between 1) and 2) should probably be done now. |
I vote for 2. |
I voted for 1. Whoopsie. We didn't have consensus after all. Shall we have a separate videocall to lay out & discuss the pros/cons and options? I have the feeling that we're all open to changing our opinion (and many of us did that multiple times in this thread) --- we just want to make the right decision. |
@michaelosthege What are the pros of having an undocumented feature that we need to continue to test and support? |
In pymc/pymc/distributions/distribution.py Lines 228 to 230 in 00d4372
In the pymc/pymc/distributions/distribution.py Lines 302 to 317 in 00d4372
So we "support" forwarding any kwargs to Aesara and their behavior is, of course, documented by Aesara. |
What's the problem with explicitly not allowing size to pass through? Since we have an alternative parameter that is slightly different than the one used by Aesara it seems fine to intercept |
I am not that opposed to That's one reason why I think we shouldn't at high development cost break something that works fine. The recommendation/warning mentioned above can always become a |
@michaelosthege If you really want to go back to that discussion (I was hoping we were past that), can you refute the logic in #5754 (comment)? |
From those points I just don't conclude that we should forbid the use of That's why in my comment right below yours I wrote
I should have been more explicit, because apparently we had a different understanding of what it means to "remove the size kwarg". I was and am in favor of removing |
The codebase can be changed. This issue is about what is best in the long term, mostly regarding user experience. I don't think having two formats is good for users. One should be superior by whatever tiny margin and that's the one we should offer users. There's plenty as is to confuse users about PyMC API. Soft-rules like hiding things and "making sure" not to mention size in official docs will only increase the burden on devs, and still it will get out there and confuse users. For example, just the other day someone was asking on the Discourse if they should be using |
I caught up with @michaelosthege offline. We both agree that The question of whether we want to completely remove @ricardoV94: How much work would it be to remove |
Actually can we pause here? This issue is titled "remove size from distribution API". It seems we have reached a conclusion which is yes. If there needs to be another discussion on whether size needs to be removed on from the codebase may we open another issue for that scope just so we can separate out differing decisions (and means we reach to get there? If my first sentence is wrong then by all means keep discussing Size and API in this issue. |
We have not reached consensus on whether "removing" means to actively prevent passing it at all, or just removing one line from the signature. The difference is massive! |
100% agree the scope is massive discussion which is why I'm glad this is being split up between user API and internal API/functionality. Given the PR here https://github.com/pymc-devs/pymc/pull/5788/files it seems that we've codified the user API portion which is great! Now we can debate internally but users won't be so affected, which also helps get to the 4.0.0 release. Ill now get out of the way now so the very informed folks can discuss. Thanks @michaelosthege and @twiecki for discussing the nuances and the experts here being so engaged. |
Talked to @ricardoV94 and I think we are all aligned. The plan is to do two things:
|
Closing this to move discussion over to the other ones. |
* Remove size from .dist() signature Closes #5754 * Align (Half)Flat signatures with superclass * Don't mention size in the docstring Co-authored-by: Ricardo Vieira <[email protected]> * Revert changes in `rng_fn` signatures Co-authored-by: Ricardo Vieira <[email protected]> Co-authored-by: Ricardo Vieira <[email protected]>
This was brought up in the last meeting, the question is whether there's any benefit in introducing size as a new parameter to our distributions. Size is simply
shape[:-ndim_supp]
so it's pretty easy for us to convert a user provided shape to size which Aesara RandomVariables use and will keep using internally.We should decide this before we release V4. For some context on the distinction see this WIP PR #5746
For a more involved example where we are converting from shape/dims/observed to size, take a look at these PRs #5743 and #5690
The text was updated successfully, but these errors were encountered: