From c0ea11b15886b62ce7184bf9ab4a5e2502afe985 Mon Sep 17 00:00:00 2001
From: Kaixi Hou <kaixih@nvidia.com>
Date: Fri, 7 Jun 2019 10:16:34 -0700
Subject: [PATCH] added two api def files and solved some python format issues

---
 .../python/kernel_tests/cudnn_rnn_ops_test.py | 19 +++++-----
 .../api_def_CudnnRNNCanonicalToParamsV2.pbtxt | 36 +++++++++++++++++++
 .../api_def_CudnnRNNParamsToCanonicalV2.pbtxt | 36 +++++++++++++++++++
 3 files changed, 81 insertions(+), 10 deletions(-)
 create mode 100644 tensorflow/core/api_def/base_api/api_def_CudnnRNNCanonicalToParamsV2.pbtxt
 create mode 100644 tensorflow/core/api_def/base_api/api_def_CudnnRNNParamsToCanonicalV2.pbtxt

diff --git a/tensorflow/contrib/cudnn_rnn/python/kernel_tests/cudnn_rnn_ops_test.py b/tensorflow/contrib/cudnn_rnn/python/kernel_tests/cudnn_rnn_ops_test.py
index 2fc8268b8f4..e516ec8ce9b 100644
--- a/tensorflow/contrib/cudnn_rnn/python/kernel_tests/cudnn_rnn_ops_test.py
+++ b/tensorflow/contrib/cudnn_rnn/python/kernel_tests/cudnn_rnn_ops_test.py
@@ -208,16 +208,15 @@ def RunLSTM(sess,
 
   if is_training:
     if num_proj:
-      outputs, state_tuple, inp_grad, state_grad, wgrad, bgrad, pwgrad = \
-      sess.run([
-          outputs_op, state_tuple_op, inp_grad_op,
-          (hgrad_op, cgrad_op), wgrad_op, bgrad_op, pwgrad_op
-      ])
+      (outputs, state_tuple, inp_grad, state_grad, wgrad, bgrad,
+       pwgrad) = sess.run([
+           outputs_op, state_tuple_op, inp_grad_op,
+           (hgrad_op, cgrad_op), wgrad_op, bgrad_op, pwgrad_op])
       (cu_outputs, cu_state_tuple, cu_inp_grad, cu_state_grad, cu_wgrad,
        cu_bgrad, cu_pwgrad) = sess.run([
            cu_outputs_op, cu_state_tuple_op, cu_inp_grad_op,
-           (cu_hgrad_op, cu_cgrad_op), cu_wgrad_op, cu_bgrad_op, cu_pwgrad_op],
-           feed_dict={inputs: inputs_np} if dynamic_shape_input else None)
+           (cu_hgrad_op, cu_cgrad_op), cu_wgrad_op, cu_bgrad_op, cu_pwgrad_op
+       ], feed_dict={inputs: inputs_np} if dynamic_shape_input else None)
     else:
       outputs, state_tuple, inp_grad, state_grad, wgrad, bgrad = sess.run([
           outputs_op, state_tuple_op, inp_grad_op,
@@ -225,9 +224,9 @@ def RunLSTM(sess,
       (cu_outputs, cu_state_tuple, cu_inp_grad, cu_state_grad, cu_wgrad,
        cu_bgrad) = sess.run([
            cu_outputs_op, cu_state_tuple_op, cu_inp_grad_op,
-           (cu_hgrad_op, cu_cgrad_op), cu_wgrad_op, cu_bgrad_op],
-           feed_dict={inputs: inputs_np} if dynamic_shape_input else None)
-    
+           (cu_hgrad_op, cu_cgrad_op), cu_wgrad_op, cu_bgrad_op
+       ], feed_dict={inputs: inputs_np} if dynamic_shape_input else None)
+
     logging.vlog(1, "outputs: %s" % outputs)
     logging.vlog(1, "cu_outputs: %s" % cu_outputs)
     logging.vlog(1, "state_tuple: %s" % str(state_tuple))
diff --git a/tensorflow/core/api_def/base_api/api_def_CudnnRNNCanonicalToParamsV2.pbtxt b/tensorflow/core/api_def/base_api/api_def_CudnnRNNCanonicalToParamsV2.pbtxt
new file mode 100644
index 00000000000..cac3674c1ae
--- /dev/null
+++ b/tensorflow/core/api_def/base_api/api_def_CudnnRNNCanonicalToParamsV2.pbtxt
@@ -0,0 +1,36 @@
+op {
+  graph_op_name: "CudnnRNNCanonicalToParamsV2"
+  summary: "Converts CudnnRNN params from canonical form to usable form. It supports the projection in LSTM."
+  description: <<END
+Writes a set of weights into the opaque params buffer so they can be used in
+upcoming training or inferences.
+
+Note that the params buffer may not be compatible across different GPUs. So any
+save and restoration should be converted to and from the canonical weights and
+biases.
+
+num_layers: Specifies the number of layers in the RNN model.
+num_units: Specifies the size of the hidden state.
+input_size: Specifies the size of the input state.
+weights: the canonical form of weights that can be used for saving
+    and restoration. They are more likely to be compatible across different
+    generations.
+biases: the canonical form of biases that can be used for saving
+    and restoration. They are more likely to be compatible across different
+    generations.
+num_params_weigths: number of weight parameter matrix for all layers.
+num_params_biases: number of bias parameter vector for all layers.
+rnn_mode: Indicates the type of the RNN model.
+input_mode: Indicate whether there is a linear projection between the input and
+    The actual computation before the first layer. 'skip_input' is only allowed
+    when input_size == num_units; 'auto_select' implies 'skip_input' when
+    input_size == num_units; otherwise, it implies 'linear_input'.
+direction: Indicates whether a bidirectional model will be used.
+    dir = (direction == bidirectional) ? 2 : 1
+dropout: dropout probability. When set to 0., dropout is disabled.
+seed: the 1st part of a seed to initialize dropout.
+seed2: the 2nd part of a seed to initialize dropout.
+num_proj: The output dimensionality for the projection matrices. If None or 0,
+    no projection is performed.
+END
+}
diff --git a/tensorflow/core/api_def/base_api/api_def_CudnnRNNParamsToCanonicalV2.pbtxt b/tensorflow/core/api_def/base_api/api_def_CudnnRNNParamsToCanonicalV2.pbtxt
new file mode 100644
index 00000000000..aa51414ba23
--- /dev/null
+++ b/tensorflow/core/api_def/base_api/api_def_CudnnRNNParamsToCanonicalV2.pbtxt
@@ -0,0 +1,36 @@
+op {
+  graph_op_name: "CudnnRNNParamsToCanonicalV2"
+  summary: "Retrieves CudnnRNN params in canonical form. It supports the projection in LSTM."
+  description: <<END
+Retrieves a set of weights from the opaque params buffer that can be saved and
+restored in a way compatible with future runs.
+
+Note that the params buffer may not be compatible across different GPUs. So any
+save and restoration should be converted to and from the canonical weights and
+biases.
+
+num_layers: Specifies the number of layers in the RNN model.
+num_units: Specifies the size of the hidden state.
+input_size: Specifies the size of the input state.
+num_params_weigths: number of weight parameter matrix for all layers.
+num_params_biases: number of bias parameter vector for all layers.
+weights: the canonical form of weights that can be used for saving
+    and restoration. They are more likely to be compatible across different
+    generations.
+biases: the canonical form of biases that can be used for saving
+    and restoration. They are more likely to be compatible across different
+    generations.
+rnn_mode: Indicates the type of the RNN model.
+input_mode: Indicate whether there is a linear projection between the input and
+    The actual computation before the first layer. 'skip_input' is only allowed
+    when input_size == num_units; 'auto_select' implies 'skip_input' when
+    input_size == num_units; otherwise, it implies 'linear_input'.
+direction: Indicates whether a bidirectional model will be used.
+    dir = (direction == bidirectional) ? 2 : 1
+dropout: dropout probability. When set to 0., dropout is disabled.
+seed: the 1st part of a seed to initialize dropout.
+seed2: the 2nd part of a seed to initialize dropout.
+num_proj: The output dimensionality for the projection matrices. If None or 0,
+    no projection is performed.
+END
+}