[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r229943448 ## 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: @Roshrini I am terribly sorry for the late response. I do not this it is appropriate for me to remove this part of the comments because they are used to show the discrepencies between the original word-level language modeling benchmark and the benchmark that I am using (i.e. it is deliberately left there for **comparison** purpose). 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
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r229943448 ## 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: @Roshrini I am terribly sorry for the late response. I do not this it is appropriate for me to remove this part of the comments because they are used to show the discrepencies between the original word language-modeling benchmark and the benchmark that I am using (i.e. it is deliberately left there for **comparison** purpose). 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
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r224534555 ## File path: src/operator/contrib/cu_open_lstm_rnn-inl.cuh ## @@ -0,0 +1,907 @@ +/* + * 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. + */ +/*! + * Copyright (c) 2018 by Contributors + * \file open_lstm_rnn-inl.cuh + * \brief LSTM RNN Open-Source CUDA Implementation + * \author Bojian (Jack) Zheng, Gennady Pekhimenko, Jeremy Appleyard + */ +#ifndef MXNET_OPERATOR_CONTRIB_CU_OPEN_LSTM_RNN_INL_CUH_ Review comment: @apeforest The reason why I start this file with `cu` is because `cu` is considered as the abbreviation for **CUDA** implementation (e.g., cuDNN, cuBLAS, cuSparse). 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
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r224286378 ## File path: src/operator/contrib/cu_open_lstm_rnn-inl.cuh ## @@ -0,0 +1,1125 @@ +/* + * 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. + */ +/*! + * Copyright (c) 2018 by Contributors + * \file open_lstm_rnn-inl.cuh + * \brief LSTM RNN Open-Source CUDA Implementation + * \author Bojian (Jack) Zheng, Gennady Pekhimenko, Jeremy Appleyard + */ +#ifndef MXNET_OPERATOR_CONTRIB_CU_OPEN_LSTM_RNN_INL_CUH_ +#define MXNET_OPERATOR_CONTRIB_CU_OPEN_LSTM_RNN_INL_CUH_ + +#include +#include +#include +#include +#include +#include +#include "./open_lstm_rnn-inl.h" +#include "./open_lstm_rnn_include/dropout.cuh" +#include "./open_lstm_rnn_include/lstm_cell.cuh" +#include "./open_lstm_rnn_include/cublas_matmul.h" +#include "./open_lstm_rnn_include/cublas_transpose.h" + +#define RE_CAST(ptr) reinterpret_cast < float * > (ptr) + +namespace mxnet { +namespace op { + +class CUOpenLSTMRNNOp : public Operator { + public: + explicit CUOpenLSTMRNNOp(OpenLSTMRNNParam param) { +this->param_ = param; initialized_ = false; + } + + ~CUOpenLSTMRNNOp() { +//= +// Free the allocated workspace memory. +//= +Storage::Get()->Free(m_data_T_major); +Storage::Get()->Free(m_data_T_major_grad); +Storage::Get()->Free(m_cell); +Storage::Get()->Free(m_hidden); +Storage::Get()->Free(m_i2h_workspace); +Storage::Get()->Free(m_h2h_workspace); +Storage::Get()->Free(m_i2h_grad_workspace); +Storage::Get()->Free(m_h2h_grad_workspace); +Storage::Get()->Free(m_linear_gates); +//= +// Destroy the cuBLAS handle. +//= +CUBLAS_CALL(cublasDestroy(m_cublas_handle)); +//= +// Free the workers (cudaStream and cudaEvent). +//= +for (unsigned layer_idx = 0; layer_idx < param_.num_layers; ++layer_idx) { + CUDA_CALL(cudaStreamDestroy(m_stream_i2h[layer_idx])); + m_stream_i2h[layer_idx] = NULL; + CUDA_CALL(cudaStreamDestroy(m_stream_h2h[layer_idx])); + m_stream_h2h[layer_idx] = NULL; +} +delete [] m_stream_i2h; m_stream_i2h = NULL; +delete [] m_stream_h2h; m_stream_h2h = NULL; +for (unsigned layer_idx = 0; layer_idx < param_.num_layers; ++layer_idx) { + for (unsigned seq_idx = 0; seq_idx < param_.seq_len; ++seq_idx) { +CUDA_CALL(cudaEventDestroy(m_event_i2h[layer_idx][seq_idx])); +m_event_i2h[layer_idx][seq_idx] = NULL; +CUDA_CALL(cudaEventDestroy(m_event_h2h[layer_idx][seq_idx])); +m_event_h2h[layer_idx][seq_idx] = NULL; + } + delete [] m_event_i2h[layer_idx]; m_event_i2h[layer_idx] = NULL; + delete [] m_event_h2h[layer_idx]; m_event_h2h[layer_idx] = NULL; +} +delete [] m_event_i2h; m_event_i2h = NULL; +delete [] m_event_h2h; m_event_h2h = NULL; +//= +// Destroy the cuRAND handle and associated workspace. +//= +if (param_.i_dp_prob != 0 && param_.num_layers > 1) { + CURAND_CALL(curandDestroyGenerator(m_rng)); + Storage::Get()->Free(m_i_dp_uniform_rv); + Storage::Get()->Free(m_i_dp_workspace); +} + } + + virtual void Forward(const OpContext , + const std::vector _data, + const std::vector , + const std::vector _data, + const std::vector _args) { +using namespace mshadow; + +//= +// IO Data +
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r224284934 ## File path: src/operator/contrib/open_lstm_rnn.cc ## @@ -0,0 +1,74 @@ +/* + * 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. + */ + +/*! + * Copyright (c) 2018 by Contributors + * \file open_lstm_rnn.cc + * \brief LSTM RNN Open-Source CUDA Implementation + * \author Bojian (Jack) Zheng, Gennady Pekhimenko + */ +#include "./open_lstm_rnn-inl.h" + +namespace mxnet { +namespace op { + +template <> +Operator *CreateOp(OpenLSTMRNNParam param, int dtype) { + LOG(FATAL) << "OpenLSTMRNN is only available for gpu at the moment."; + + Operator * op = nullptr; + + MSHADOW_REAL_TYPE_SWITCH(dtype, DType, Review comment: @apeforest This was written analogously with the [`cuDNN` implementation of LSTM RNN](https://github.com/apache/incubator-mxnet/blob/v0.12.0/src/operator/rnn.cc). 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
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r224284934 ## File path: src/operator/contrib/open_lstm_rnn.cc ## @@ -0,0 +1,74 @@ +/* + * 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. + */ + +/*! + * Copyright (c) 2018 by Contributors + * \file open_lstm_rnn.cc + * \brief LSTM RNN Open-Source CUDA Implementation + * \author Bojian (Jack) Zheng, Gennady Pekhimenko + */ +#include "./open_lstm_rnn-inl.h" + +namespace mxnet { +namespace op { + +template <> +Operator *CreateOp(OpenLSTMRNNParam param, int dtype) { + LOG(FATAL) << "OpenLSTMRNN is only available for gpu at the moment."; + + Operator * op = nullptr; + + MSHADOW_REAL_TYPE_SWITCH(dtype, DType, Review comment: @apeforest This was written analogously with the [`cuDNN` implementation of LSTM RNN](https://github.com/apache/incubator-mxnet/blob/v0.12.0/src/operator/rnn.cc). 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
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r224284822 ## File path: src/operator/contrib/open_lstm_rnn.cc ## @@ -0,0 +1,74 @@ +/* + * 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. + */ + +/*! + * Copyright (c) 2018 by Contributors + * \file open_lstm_rnn.cc + * \brief LSTM RNN Open-Source CUDA Implementation + * \author Bojian (Jack) Zheng, Gennady Pekhimenko + */ +#include "./open_lstm_rnn-inl.h" + +namespace mxnet { +namespace op { + +template <> +Operator *CreateOp(OpenLSTMRNNParam param, int dtype) { + LOG(FATAL) << "OpenLSTMRNN is only available for gpu at the moment."; + + Operator * op = nullptr; + + MSHADOW_REAL_TYPE_SWITCH(dtype, DType, Review comment: @apeforest This was written analogously with the [`cuDNN` implementation of LSTM RNN](https://github.com/apache/incubator-mxnet/blob/v0.12.0/src/operator/rnn.cc). 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
[GitHub] ArmageddonKnight commented on a change in pull request #11364: [MXNET-490] Added OpenLSTMRNN together with benchmarks and Tensorboard callback routines.
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_r199024323 ## File path: example/rnn-backends/bucketing/dataset/download_ptb.sh ## @@ -0,0 +1,27 @@ +#!/bin/sh +# 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. + +# This file downloads the PTB dataset. + +mkdir -p $(cd $(dirname $0) && pwd)/ptb + +cd $(cd $(dirname $0) && pwd)/ptb && \ Review comment: Thank you for your comments. I have made changes accordingly. 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