-
-
Notifications
You must be signed in to change notification settings - Fork 985
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
Params inside iarange #238
Comments
the other attitude to take is #alwaysamortize ; ) |
It seems pretty simple to write this as: with pyro.iarange("data", size, subsample_size) as ind:
ps = pyro.param("ps", Variable(torch.ones(size), requires_grad=True)).index_select(ind)
# ...do stuff with ps... |
I believe the only way to get this to work automatically is to add a notion of I'll remove this from the 0.2 milestone (if you don't mind). This will give us a chance to see how users adapt to other automatic dimension handling in e.g. enumeration. Given what we learn after 0.2 release, there may be a clear path to resolving this issue in Pyro 0.3. |
We can wait until after 0.2, but I do think this is a significant issue, both because it makes irange semantically diverge from iarange and because it messes up mean field guides. |
Here is a proposal for refactoring towards a more plate-friendly I think we could modify To correctly handle subsampling, we would need to give To account for global params, we could use various autonaming hacks. E.g. we could avoid expanding in @eb8680 @neerajprad @ngoodman WDYT? |
what if we add an abstract index argument to param (and sample)? ie something along the lines of that is, within an iteration the indices are just strings/numbers that get appended to the name. within a plate block the index is an object that tells us which dimension to expand along. if a param is created without and index it is treated as global. this by itself doesn't tell us what to do with subsampling, though as @eb8680 pointed out we should probably rethink that anyhow.... maybe @fritzo's suggestions is an answer? |
I like the idea of a more plate friendly param!
It should mostly be fine, but I hope that the cost doesn't add up as we do this every time the model is run. In any case, I think we can explore other ideas of exposing this information to
Given our existing use cases, it might be easier to add a kwarg to I have not thought through this, but I think this could also be extended to support iparam (e.g. by wrapping inside a plate with |
Ok, I've illustrated possible syntax changes in #1491 (based on #1486 ). The intent is to:
|
In addition to a For example, consider the case of SVI with vectorized There's fundamentally ambiguity in the identity of each broadcasting dimension, and moreover |
the current behavior of params created inside an
iarange
(aka vectorized map_data) is a bit nonsensical: a vector of params of lengthbatch_size
will be created and used on every iteration. this means that a param gets reused for whatever data point happens to be selected at that index in a batch. this comes up eg when there is a mean-field model for a local variable.(there is a reasonable work-around, by creating the vector of needed params globally, and only selecting from it in the iarange.)
a better behavior would be to automatically associate params to their index into the data tensor, pulling out the appropriate params for a given batch (and creating them as needed). it might be tricky to get this working, and especially to do it efficiently.
i'm flagging this as a low priority bug for now. we can think through a solution after launch.
The text was updated successfully, but these errors were encountered: