-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
pass names from RV dims to change_rv_size #5931
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
pass names from RV dims to change_rv_size #5931
Conversation
- adds argument new_size_dims to change_rv_size in aesaraf.py - tests if dims is None and wraps in tuple if RV has no dim - creates new_size_name by adding dim name and decorations - passes new_size_name as name argument to at.as_tensor method
@@ -180,9 +187,13 @@ def change_rv_size( | |||
size = shape[: len(shape) - rv_node.op.ndim_supp] | |||
new_size = tuple(new_size) + tuple(size) | |||
|
|||
# create the name of the RV's resizing tensor | |||
# TODO: add information where the dim is coming from (obseverd, prior, ...) |
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.
Is this todo going to be implemented in this PR or is this for later?
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.
yes, I think it would be helpful. Just wanted to make sure I'm on the right track before I spend more time on it
Thanks much for the pr! |
Codecov Report
@@ Coverage Diff @@
## main #5931 +/- ##
==========================================
- Coverage 89.53% 88.60% -0.93%
==========================================
Files 73 73
Lines 13267 13270 +3
==========================================
- Hits 11878 11758 -120
- Misses 1389 1512 +123
|
@@ -145,6 +145,7 @@ def convert_observed_data(data): | |||
def change_rv_size( | |||
rv: TensorVariable, | |||
new_size: PotentialShapeType, | |||
new_size_dims: Optional[tuple] = (None,), |
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.
The name info should not be handled by this function. I think somewhere in the model we create constants or shared variables for dim sizes and there is where we should set the names.
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.
Could you give me a hint roughly where this should be? Before or after the call to change_rv_size?
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.
Could be done here where the dims variables are created:
Lines 1146 to 1149 in be048a4
if mutable: | |
length = aesara.shared(length) | |
else: | |
length = aesara.tensor.constant(length) |
Both constants and shared variables accept names during construction.
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.
@ricardoV94, I looked into it and when I set the names in the suggested lines, I receive only the following output from dprint:
normal_rv{0, (0, 0), floatX, False}.1 [id A] 'x'
|RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7F99BD4B6960>) [id B]
|TensorConstant{(1,) of 5} [id C]
|TensorConstant{11} [id D]
|TensorConstant{0} [id E]
|TensorConstant{1.0} [id F]
only after passing the name to new_size in aesaraf.py::change_rv_size, I get the change
Line 185 in be048a4
new_size = at.as_tensor(new_size, ndim=1, dtype="int64") |
new_size = at.as_tensor(new_size, ndim=1, dtype="int64", name=new_size[0].name)
normal_rv{0, (0, 0), floatX, False}.1 [id A] 'x'
|RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FAD2928A960>) [id B]
|cities_dim{(1,) of 5} [id C]
|TensorConstant{11} [id D]
|TensorConstant{0} [id E]
|TensorConstant{1.0} [id F]
If this is okay, I'll implement the changes in this PR
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 PR added a name for the mutable case, but not the constant one: f45ca4a, I think adding it to the constant is all that's needed.
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, I will try to give it another go in this week
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.
@ricardoV94, I'm dancing around this PR for quite a bit now, but I'm not finding the time to do it. In the beginning of next year I would have more time, but if it bothers you to have an open PR for such a long time or someone else takes over, I won't mind if I don't get to finish it.
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 worries. The original issue lost some of it's relevance when we switched from defaulting resizable dims to constant dims. It's still nice but not urgent by any means. Feel free to come back to it whenever you find the time.
This PR should now be a bit more straightforward due to #6063 Dims will now always be used when shape is not provided. |
Hi folks, I was interested in this so I took a look with the latest codebase. As @flo-schu was finding, it's not sufficient to simply add the dim name to the call to Lines 1066 to 1069 in e1d36ca
Somewhere along the RV creation call stack, the name of the Variable holding dim length gets lost. I believe this is actually happening in With shared variables, the call to Using the following model, with pm.Model() as m:
mutable = True
d2 = pm.Data("data1", range(5), dims="d1", mutable=mutable)
d1 = pm.Data("data2", range(7), dims="d2", mutable=mutable)
x = pm.Normal("x", dims=("d1", "d2")) Before that line in normalize_size_parameter,
and after,
With pymc patched as described above to pass along name to
to
So, what to do? |
N.B. the tensorconstant name gets disappeared even if there is only one dim, a la >>> pt.as_tensor_variable((pt.constant(5, name="disappears"),)).name
None Because normalize_size_parameter will always receive a tuple. A couple naive thoughts include:
|
@covertg thanks for investigating. This issue was more relevant before when all dims used SharedVariable, and hence names were preserved. With TensorConstant's PyTensor is very liberal and happy to return you objects that aren't linked to the original ones, as you found out. I think we can simply close the PR and issue. It was a nice to have, but doesn't seem worth any further trouble at this point. |
@canyon289 to resolve #5669, I have made some small changes mainly to aesaraf.py to include the dim names in the new_size tensor (6585f90)
This solves the issue mainly and
test_model
runs without errors. There are a few things that probably need to be addressed.change_rv_size
need to be tested more rigorously?the name
changes of the PR