junrushao1994 commented on issue #16188: symbol.contrib.cond does not support 
some built-in operators
URL: 
https://github.com/apache/incubator-mxnet/issues/16188#issuecomment-532882599
 
 
   A workaround would be:
   
   ```python
   import mxnet as mx
   from mxnet import nd, autograd, gluon
   
   class MLP(gluon.HybridBlock):
       def __init__(self, **kwargs):
           super(MLP, self).__init__(**kwargs)
           with self.name_scope():
               self.dense1 = gluon.nn.Dense(1, in_units=1)
   
       def hybrid_forward(self, F, x, zero):
           # `zero` is an ndarray that contains only zero, so `round(x) + 
relu(zero)` is always `round(x)`
           cond_out = F.contrib.cond(F.ones(1) == F.ones(1), lambda: 
self.dense1(x), lambda: F.round(x) + F.relu(zero))
           return cond_out
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to