clone_replace
's share_inputs
doesn't consider RandomVariables
as inputs
#1157
Replies: 4 comments 3 replies
-
Could you print the graph in both cases using |
Beta Was this translation helpful? Give feedback.
-
I'll print Using normal_rv{0, (0, 0), floatX, False}.1 [id A] 'd'
|RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD74111F740>) [id B]
|TensorConstant{[]} [id C]
|TensorConstant{11} [id D]
|Reshape{1} [id E]
| |Elemwise{add,no_inplace} [id F]
| | |InplaceDimShuffle{x,0,1} [id G]
| | | |Elemwise{add,no_inplace} [id H]
| | | |InplaceDimShuffle{x,0} [id I]
| | | | |normal_rv{0, (0, 0), floatX, False}.1 [id J] 'a'
| | | | |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD74287C200>) [id K]
| | | | |TensorConstant{(1,) of 2} [id L]
| | | | |TensorConstant{11} [id M]
| | | | |TensorConstant{3} [id N]
| | | | |TensorConstant{0.01} [id O]
| | | |normal_rv{0, (0, 0), floatX, False}.1 [id P] 'b'
| | | |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD74287CAC0>) [id Q]
| | | |TensorConstant{(2,) of 2} [id R]
| | | |TensorConstant{11} [id S]
| | | |TensorConstant{1} [id T]
| | | |TensorConstant{0.01} [id U]
| | |Alloc [id V]
| | |TensorConstant{0.0} [id W]
| | |Subtensor{int64} [id X]
| | | |Shape [id Y]
| | | | |normal_rv{0, (0, 0), floatX, False}.1 [id Z] 'c'
| | | | |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD741104740>) [id BA]
| | | | |TensorConstant{(3,) of 2} [id BB]
| | | | |TensorConstant{11} [id BC]
| | | | |TensorConstant{100} [id BD]
| | | | |TensorConstant{0.01} [id BE]
| | | |ScalarConstant{0} [id BF]
| | |Subtensor{int64} [id BG]
| | | |Shape [id Y]
| | | |ScalarConstant{1} [id BH]
| | |Subtensor{int64} [id BI]
| | |Shape [id Y]
| | |ScalarConstant{2} [id BJ]
| |TensorConstant{(1,) of -1} [id BK]
|TensorConstant{0.01} [id BL] Using normal_rv{0, (0, 0), floatX, False}.1 [id A] 'd'
|RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD74350E040>) [id B]
|TensorConstant{[]} [id C]
|TensorConstant{11} [id D]
|Reshape{1} [id E]
| |Elemwise{add,no_inplace} [id F]
| | |InplaceDimShuffle{x,0,1} [id G]
| | | |Elemwise{add,no_inplace} [id H]
| | | |InplaceDimShuffle{x,0} [id I]
| | | | |normal_rv{0, (0, 0), floatX, False}.1 [id J] 'a'
| | | | |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD74111FE40>) [id K]
| | | | |TensorConstant{(1,) of 2} [id L]
| | | | |TensorConstant{11} [id M]
| | | | |TensorConstant{3} [id N]
| | | | |TensorConstant{0.01} [id O]
| | | |normal_rv{0, (0, 0), floatX, False}.1 [id P] 'b'
| | | |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD741104820>) [id Q]
| | | |TensorConstant{(2,) of 2} [id R]
| | | |TensorConstant{11} [id S]
| | | |TensorConstant{1} [id T]
| | | |TensorConstant{0.01} [id U]
| | |Alloc [id V]
| | |TensorConstant{0.0} [id W]
| | |Subtensor{int64} [id X]
| | | |Shape [id Y]
| | | | |normal_rv{0, (0, 0), floatX, False}.1 [id Z] 'c'
| | | | |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FD74287CBA0>) [id BA]
| | | | |TensorConstant{(3,) of 2} [id BB]
| | | | |TensorConstant{11} [id BC]
| | | | |TensorConstant{100} [id BD]
| | | | |TensorConstant{0.01} [id BE]
| | | |ScalarConstant{0} [id BF]
| | |Subtensor{int64} [id BG]
| | | |Shape [id Y]
| | | |ScalarConstant{1} [id BH]
| | |Subtensor{int64} [id BI]
| | |Shape [id Y]
| | |ScalarConstant{2} [id BJ]
| |TensorConstant{(1,) of -1} [id BK]
|TensorConstant{0.01} [id BL] |
Beta Was this translation helpful? Give feedback.
-
Furthermore, if I try to compile the function with a = at.random.normal(loc=3, scale=0.01, name="a", size=2)
b = at.random.normal(loc=1, scale=0.01, name="b", size=(2, 2))
c = at.random.normal(loc=100, scale=0.01, name="c", size=(2, 2, 2))
d = pm.Normal.dist(mu=(a + b + c).flatten(), sigma=0.01)
d.name = "d"
d_clone = aesara.graph.basic.clone_replace(
[d], replace={c: at.zeros(c.shape, dtype=c.dtype)}, share_inputs=True
)
f = aesara.function([a, b], d_clone) Traceback: UnusedInputError Traceback (most recent call last)
/tmp/ipykernel_21661/2516318076.py in <module>
7 [d], replace={c: at.zeros(c.shape, dtype=c.dtype)}, share_inputs=True
8 )
----> 9 f = aesara.function([a, b], d_clone)
~/anaconda3/lib/python3.9/site-packages/aesara/compile/function/__init__.py in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
315 # note: pfunc will also call orig_function -- orig_function is
316 # a choke point that all compilation must pass through
--> 317 fn = pfunc(
318 params=inputs,
319 outputs=outputs,
~/anaconda3/lib/python3.9/site-packages/aesara/compile/function/pfunc.py in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
361 )
362
--> 363 return orig_function(
364 inputs,
365 cloned_outputs,
~/anaconda3/lib/python3.9/site-packages/aesara/compile/function/types.py in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
1723 try:
1724 Maker = getattr(mode, "function_maker", FunctionMaker)
-> 1725 m = Maker(
1726 inputs,
1727 outputs,
~/anaconda3/lib/python3.9/site-packages/aesara/compile/function/types.py in __init__(self, inputs, outputs, mode, accept_inplace, function_builder, profile, on_unused_input, fgraph, output_keys, name)
1430
1431 # Check if some input variables are unused
-> 1432 self.check_unused_inputs(inputs, outputs, on_unused_input)
1433
1434 indices = [[input, None, [input]] for input in inputs]
~/anaconda3/lib/python3.9/site-packages/aesara/compile/function/types.py in check_unused_inputs(inputs, outputs, on_unused_input)
1371 )
1372 elif on_unused_input == "raise":
-> 1373 raise UnusedInputError(msg % (inputs.index(i), i.variable, err_msg))
1374 else:
1375 raise ValueError(
UnusedInputError: aesara.function was asked to create a function computing outputs given certain inputs, but the provided input variable at index 0 is not part of the computational graph needed to compute the outputs: a.
To make this error into a warning, you can pass the parameter on_unused_input='warn' to aesara.function. To disable it completely, use on_unused_input='ignore'. |
Beta Was this translation helpful? Give feedback.
-
The one thing I've been going over all this recently and planning some core graph changes that will preserve equivalence and identities at a much lower level (e.g. cache |
Beta Was this translation helpful? Give feedback.
-
Description of your problem or feature request
I have a biggish hierarchical model and I want to test an intervention where I force some of the random variables to be exactly equal to 0. There are many ways in which I can do this, but I tried to use
clone_replace
to replace the intervened random variables with zeros of the correct shape and dtype. I chose not to do this by settinggivens
when I compiled the function, because I actually want my function to output both conditions: with and without interventions.The problem I faced was that
clone_replace
made copies of the random variables that weren't being changed (the random generators and other constant inputs were not cloned because those were the graph inputs), and then when I compiled a function to draw samples, the intervention model resampled the cloned variables from their prior. Here's a minimal example:Please provide a minimal, self-contained, and reproducible example.
Which prints:
instead of being centered around zero.
If instead of using
clone_replace
I useclone_get_equiv
, I can put together something that works like I want it to:Which prints out
I understand now why variables
a
andb
are not shared after callingclone_replace
but I think that it would be useful to either:clone_replace
return the mapping between original and cloned nodesinputs
list toclone_replace
that indicates which nodes should be considered inputs to be shared.Versions and main components
python -c "import aesara; print(aesara.config)"
)Beta Was this translation helpful? Give feedback.
All reactions