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 2018/10/28 13:27:53 UTC

[GitHub] juliusshufan commented on a change in pull request #12893: Dummy-data based benchmarking script for Gluon RNN-API

juliusshufan commented on a change in pull request #12893: Dummy-data based benchmarking script for Gluon RNN-API
URL: https://github.com/apache/incubator-mxnet/pull/12893#discussion_r228748587
 
 

 ##########
 File path: benchmark/python/gluon/benchmark_gluon_rnn.py
 ##########
 @@ -0,0 +1,221 @@
+# 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.
+
+import mxnet as mx
+import mxnet.gluon as gluon
+import time
+import logging
+import sys
+import argparse
+from mxnet.gluon import nn, rnn
+
+parser = argparse.ArgumentParser(description='Gluon RNN Benchmarking.')
+parser.add_argument('--num-layer', type=int, default=1,
+                    help='The number of layers of the RNN model')
+parser.add_argument('--layout', type=str, default='TNC',
+                    help='The layout of the input shape, can be either TNC or NTC.')
+parser.add_argument('--specify-shape', type=str,
+                    help='Specify the input shape, format batchsize, time-step, embed-size, hidden-size.')
+parser.add_argument('--cell-type', type=str, default='lstm',
+                    help='RNN cell type, can be either lstm, gru or all to cover both.')
+parser.add_argument('--unfuse', action='store_true', default=False,
+                    help='Unfuse the RNN layer to stacked RNN cell instead.') 
+parser.add_argument('--latency', action='store_true', default=False,
+                    help='Measursing the latency, batchsize will be set to 1.')
+parser.add_argument('--train', action='store_true', default=False,
+                    help='Run backward benchmark.')
+parser.add_argument('--dropout', type=float, default=0)
+parser.add_argument('--gpu', action='store_true', default=False)
+parser.add_argument('--no-hybridize', action='store_true', default=False)
+parser.add_argument('--bidirection', action='store_true', default=False)
+
+opt = parser.parse_args()
+logging.basicConfig(level=logging.INFO)
+
+#[bs, sequence length, embedding size, hidden size]
+input_shape_list = [[64,15,500,500],
+   [64,20,500,500],
+   [64,25,500,500],
+   [64,30,500,500],
+   [64,35,500,500],
+   [64,40,500,500],
+   [64,45,500,500],
+   [64,50,500,500],
+   [16,25,512,512],
+   [32,25,512,512],
+   [64,25,512,512],
+   [128,25,512,512],
+   [16,25,1024,1024],
+   [32,25,1024,1024],
+   [64,25,1024,1024],
+   [128,25,1024,1024],
+   [16,25,2048,2048],
+   [32,25,2048,2048],
+   [64,25,2048,2048],
+   [128,25,2048,2048],
+   [16,25,4096,4096],
+   [32,25,4096,4096],
+   [64,25,4096,4096],
+   [128,25,4096,4096]]
+
+rnncell_type = ['lstm', 'gru', 'all']
+input_layout = ['TNC', 'NTC']
+
+if not opt.gpu:
+    ctx = mx.cpu()
+else:
+    ctx = mx.gpu(0)
+
+dropout = opt.dropout
+bidirection = opt.bidirection
+unfuse = opt.unfuse
+celltype = opt.cell_type
+
+dry_run = 20
+num_iter = 100
+
+def get_rnn_layer(input_shape, num_layer, cell_type, dropout=0, bidirection=False):
+    hidden_size = input_shape[3]
+    embedding_size = input_shape[2]
+    if cell_type == 'lstm':
+        rnn_layer = rnn.LSTM(hidden_size, num_layer, dropout=dropout,
+                             bidirectional=bidirection, input_size=embedding_size,
+                             prefix='_lstm_layer')
+    elif cell_type == 'gru':
+        rnn_layer = rnn.GRU(hidden_size, num_layer, dropout=dropout,
+                            bidirectional=bidirection, input_size=embedding_size,
+                            prefix='_gru_layer')
+    return rnn_layer
+
+
+def rnn_cell_score(input_shape, cell_type, ctx, num_layer, dropout=0, bidirection=False, layout='TNC', unfuse=False, hybridize=True, is_train=False):
+    bs = input_shape[0]
+    seq_len = input_shape[1]
+    embedding_size = input_shape[2]
+    hidden_size = input_shape[3]
+    rnn_layer = get_rnn_layer(input_shape, num_layer, cell_type, dropout, bidirection)
+    input_data = mx.sym.Variable('data')
 
 Review comment:
   Thanks for review, the RNN layer/cell is called from Gluon RNN API, as the symbolic mode is assumed to have the best perf, and after hybridize, I use the symbolic input for benchmarking.
   Thanks.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services