piiswrong commented on a change in pull request #11482: make gluon rnn layers hybrid blocks URL: https://github.com/apache/incubator-mxnet/pull/11482#discussion_r199273220
########## File path: python/mxnet/gluon/rnn/rnn_layer.py ########## @@ -173,67 +177,63 @@ def begin_state(self, batch_size=0, func=ndarray.zeros, **kwargs): states.append(func(name='%sh0_%d'%(self.prefix, i), **info)) return states - def forward(self, inputs, states=None): - batch_size = inputs.shape[self._layout.find('N')] + def hybrid_forward(self, F, inputs, states=None, **kwargs): + if F is ndarray: + batch_size = inputs.shape[self._layout.find('N')] + if self._input_size == 0: + for i in range(self._dir): + self.i2h_weight[i].shape = (self._gates*self._hidden_size, inputs.shape[2]) + self.i2h_weight[i]._finish_deferred_init() skip_states = states is None if skip_states: - states = self.begin_state(batch_size, ctx=inputs.context) - if isinstance(states, ndarray.NDArray): + if F is ndarray: + states = self.begin_state(batch_size, ctx=inputs.context) + else: + states = self.begin_state(0, func=symbol.zeros) + if isinstance(states, (ndarray.NDArray, symbol.Symbol)): Review comment: (ndarray.NDArray, symbol.Symbol) -> tensor_types ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services