You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2021/02/26 07:19:03 UTC
[GitHub] [incubator-mxnet] feevos edited a comment on pull request #18403: Gluon.probability
feevos edited a comment on pull request #18403:
URL: https://github.com/apache/incubator-mxnet/pull/18403#issuecomment-786459914
Hi, thank you VERY much for your contribution!!!!!
I have noticed an issue, and am not sure if this is a bug or not (so as to submit a report). Currently, in the return statement of forward I cannot have a model hybridized and return an object of a distribution. For example, in the VAE code from the mystery_demo, if I want to return the predictions as well as the distribution that I used to get the reconstruction, I get an error when my model is hybridized.
Example
```python
import mxnet as mx
mx.npx.set_np()
from mxnet.gluon import HybridBlock
import mxnet.gluon.probability as mgp
class SimpleNet(HybridBlock):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def forward(self,input):
mu=0.0
scale=1.
return input, mgp.Normal(mu,scale)
net = SimpleNet()
net.initialize()
net.hybridize() # <=========== if hybridized code exits with error
xx = mx.np.random.rand(3,5)
out = net(xx)
```
error:
```python
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-9e229665d8a2> in <module>
----> 1 out = net(xx)
~/Software/incubator-mxnet/python/mxnet/gluon/block.py in __call__(self, x, *args)
1645
1646 with x.ctx:
-> 1647 return self._call_cached_op(x, *args)
1648
1649 def forward(self, x, *args):
~/Software/incubator-mxnet/python/mxnet/gluon/block.py in _call_cached_op(self, *args)
1263 def _call_cached_op(self, *args):
1264 if self._cached_op is None:
-> 1265 self._build_cache(*args)
1266
1267 if self._first_forward and self._partition_if_dynamic:
~/Software/incubator-mxnet/python/mxnet/gluon/block.py in _build_cache(self, update_graph, *args)
1136
1137 def _build_cache(self, *args, update_graph=True):
-> 1138 data, out = self._get_graph(*args)
1139 data_names = {data.name: i for i, data in enumerate(data)}
1140 params = {p.var().name: p for p in self.collect_params().values()}
~/Software/incubator-mxnet/python/mxnet/gluon/block.py in _get_graph(self, *args)
1132 return self._get_graph_v1(*args)
1133 else: # Gluon 2 based on deferred compute mode
-> 1134 return self._get_graph_v2(*args)
1135 return self._cached_graph
1136
~/Software/incubator-mxnet/python/mxnet/gluon/block.py in _get_graph_v2(self, *args)
1122 with autograd.pause(), dc.context():
1123 out = super().__call__(*args)
-> 1124 flatten_out, self._out_format = _flatten(out, "output")
1125 symbol_outputs = dc.get_symbol(flatten_out, sym_cls=type(symbol_inputs[0]))
1126 self._cached_graph = symbol_inputs, symbol_outputs
~/Software/incubator-mxnet/python/mxnet/gluon/block.py in _flatten(args, inout_str)
151 fmts = []
152 for i in args:
--> 153 arg, fmt = _flatten(i, inout_str)
154 flat.extend(arg)
155 fmts.append(fmt)
~/Software/incubator-mxnet/python/mxnet/gluon/block.py in _flatten(args, inout_str)
144
145 if not isinstance(args, (list, tuple)):
--> 146 raise ValueError("When hybridized, the input of HybridBlock {}"
147 " must be (nested) list of Symbol"
148 " or NDArray, "
ValueError: When hybridized, the input of HybridBlock output must be (nested) list of Symbol or NDArray, but got Normal(loc: size (), scale: size (), F: mxnet.ndarray, event_dim: 0) of type <class 'mxnet.gluon.probability.distributions.normal.Normal'>
```
Regards
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org