ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] 
Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
URL: https://github.com/apache/incubator-mxnet/pull/11364#discussion_r229943760
 
 

 ##########
 File path: example/rnn-backends/word_lm/model.py
 ##########
 @@ -0,0 +1,152 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Module: model
+
+Description: This file creates the computation graph for training purposes.
+"""
+
+import mxnet as mx
+
+
+def rnn(bptt, vocab_size, num_embed, nhid,
+        num_layers, dropout, batch_size, tied, backend):
+    """
+    Creates the computation graph for training.
+    """
+    # 
==================================================================================================================
+    # Encoder
+    # 
==================================================================================================================
+
+    data = mx.sym.Variable('data')
+    weight = mx.sym.Variable("encoder_weight", init=mx.init.Uniform(0.1))
+    embed = mx.sym.Embedding(data=data, weight=weight, input_dim=vocab_size,
+                             output_dim=num_embed, name='embed')
+
+    outputs = mx.sym.Dropout(embed, p=dropout)
+
+    # 
==================================================================================================================
+    # RNN
+    # 
==================================================================================================================
+
+    # stacked rnn layers
+
+    # Given below is the original source code, which we do argue makes bad use 
of CuDNN-RNN
+    # as there is no need to slice each layer apart, please refer to the open 
issue on github @
+    #     https://github.com/apache/incubator-mxnet/issues/10304
+    # The throughput measurements reported by MXNet speedometer showed that
+    # there is around 10~20% increase in throughput after all the layers have 
been fused.
+    # The implementation also messed up with the order of cell and hidden 
state,
+    # because according to the state order specified in rnn_cell.py (+L682),
+    # cell state should appear AFTER hidden state in FusedRNNCell. However, 
this has zero effect
+    # on the final training results because they are both zero-initialized.
+
+    states = []
+    state_names = []
+
+    # for i in range(num_layers):
+    #     prefix = 'lstm_l%d_' % i
 
 Review comment:
   Previously when working on benchmarking, I noticed that there are 
inefficiencies in the original implementation of the word-level language 
modeling benchmark (as was discussed here: 
https://github.com/apache/incubator-mxnet/issues/10304#issuecomment-377031511). 
I therefore came up with my own implementation that achieves the same 
validation score on the same dataset. The commented code-block is used to show 
**how the original implementation and my implementation do the same thing 
algorithmically**.

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


With regards,
Apache Git Services

Reply via email to