-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Can't sample a model after resizing an RV #4918
Comments
If the random variables in a model are changed, then their corresponding initial values need to be updated. You can use Otherwise, you're reusing a It would be great if the step methods were stateless, but that's not the case—nor is it a necessary design choice for v4. If you want to open a ticket for that, it would be welcome; otherwise, this issue should be closed. Likewise, if there's an issue with |
The statefulness of step methods has nothing to do with this issue. I changed the example above accordingly.
I don't want to open a ticket for that right now and this issue has nothing to do with it, so there's no reason to close it because of an unrelated quirk.
Sure, but in the example above the user did not manually specify |
It has literally everything to do with it, because it prevents PyMC from working even after the initial value problem is fixed.
Can you demonstrate that this example will work without doing anything about the
All right, so is this issue about documentation? It seems like it's about an issue you faced while attempting to do something specific, one for which you were provided an explanation and a succinct solution that only involves pre-existing features. |
@brandonwillard As it seems to also break with instantiating a new sampler, do you think it's about requiring to set a new initvalue? Just from an API stand-point I think this use-case would be great to support and not require updating an init-value specifically. |
No, it's just that those step method instances hold state, and part of that state includes the old size of the updated model variable. In other words, it's the design of the step method instances that's the problem. If they were made stateless in the relevant way, this wouldn't be an issue.
No matter what, the initial values need to be updated when a model variable's shape is changed. That's the issue, and there's no avoiding it. If we want to automate that—when possible—that's fine. For instance, Such automations will end up being rather context dependent, because, for example, adding that automation to We should focus on making it easy to update/set initial values, and making people aware of the need to do that. When the former is covered, we can also make it easier to implement some of these automations using the same machinery. |
But when we create a new step method (like the updated code above does) we get a new state.
I think that would make sense. 99% of changes to the shape of the model will come through |
Yes, and that should fix that problem and allow the entire example to work after addressing the invalid initial values caused by changing the shape of The things we need to work on could involve, for example, automating downstream init value changes, and those should be possible to do via the existing resources (e.g. |
so two things need to happen: 1. update the initval, 2. update the state of the sampler (e.g. by reinstantiating) which is tied to the model shape. |
To me it still sounds a lot more straightforward to draw/evaluate/numerify initial values when they are accessed, rather than when they're set. I proposed that here and here and in the description of this issue. I'm sorry, maybe I misunderstood something that was already mentioned in the discussion, or am missing insight on incompatibilities, but so far I am only aware of counterarguments along the lines of:
whereas on the pro side I see
Unless someone already knows about a dead end, why not just try and implement it? |
If you're advocating for some form of lazy evaluation, that's not a relevant implementation detail at this stage, nor does it provide any sort of functionality that couldn't be accomplished using a non-lazy approach. Aside from that, it sounds like you're just saying "recompute initial values when they (might) need to be recomputed", and that's just restating the solution we've been talking about this whole time.
You're going to need to evaluate graphs in a topologically sound order no matter what, but, more importantly, the approaches you're implicitly comparing are not clear. What exactly is complex and how does whatever you're proposing solve that? Better yet, how is it you can get away with not recalculating initial values in topological order? The only relevant points made in this issue were
If you don't like
These links and this issue's description are broad statements that—at best—imply the production of new initial values when they're needed. Yes, that's the basic idea, but you don't need to rephrase it so that it sounds like you have a particular solution with distinct advantages, or that the problem is actually something else. Likewise, it doesn't help to have issues that say things like "Can't do X" when "X" actually can be done, but you would like it to be done differently, or be associated with a "proposal" of yours (vague or otherwise).
Once again, what exactly are you comparing with those counter-arguments and pros? You've only listed some broad complains, limitations, and features/desires with no concrete connections to any specific proposals. Your mention of Regardless, Otherwise, it seems like you're forgetting that we're still constrained by v3 requirements and designs, and that your overly general proposals neglect to address any of this. For instance, do you know why the initial values are attached to the |
I'm still a bit confused here, but what I gather what we all agree on: A mechanism that resets the initval when I'm still, however, not clear on why even this needs to be done. If default initvals were symbolic and tied to the shape of the RV, resizing the RV should automatically resize its initval, no? I clearly don't know the implementation but maybe someone could confirm that "currently default initvals are not symbolic and the reason for that is X." |
That's the case indeed. What happens when you add a new RV to a model is that it will compile a function to compute a new I don't know if there is any clear advantage to this "eager" initval computation as opposed to creating a large function that computes all the initvals at once whenever that's needed. |
Closing in favor of #4924. |
Description
First of all this is not a regression w.r.t. PyMC3
v3
, since model resizing did not even work to begin with.But with the new RandomVariable based model graphs, the size of an RV is no longer cut in stone and we're promoting that as a new feature, so users might try it and run into this issue.
I'm opening this so it's documented.
Here's a minimal example:
Traceback
Why this happens
The initial values are eagerly set/drawn/evaluated to numeric
ndarray
s and stored in themodel.initial_values
dictionary.If the corresponding RV changes its size later on, the initial value is not updated.
Potential solutions
We could prefer to keep track of symbolic initial values (or None) and only evaluate/draw them at the start of sampling.
User-provided numeric initial values would still restrict the RV to its initial size, of course, but it should fix most use cases.
Versions and main components
main
(also on 725d798, so no it is not because of latestinitval
changes)The text was updated successfully, but these errors were encountered: