singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [singa] nudles commented on a change in pull request #662: CUDNN LSTM
Date Sun, 12 Apr 2020 03:02:24 GMT
nudles commented on a change in pull request #662: CUDNN LSTM
URL: https://github.com/apache/singa/pull/662#discussion_r407138223
 
 

 ##########
 File path: python/singa/autograd.py
 ##########
 @@ -3330,6 +3330,94 @@ def step_forward(self, x, h, c, Wx, Wh, Bx, Bh):
         return hout, cout
 
 
+class _RNN(Operation):
+    """ RNN operation with c++ backend
+    """
+    def __init__(self, handle):
+        assert singa.USE_CUDA is True, "Not able to run without CUDA"
+        super(_RNN, self).__init__()
+        self.handle = handle
+
+    def forward(self, x, W):
+        # TODO: CPU forward
+
+        # GPU forward
+        if training:
+            y = singa.GpuRNNForwardTraining(x, W, self.handle)
+            self.inputs = (x, W, y)
+        else:
+            y = singa.GpuRNNForwardInference(x, W, self.handle)
+
+        return y
+
+    def backward(self, dy):
+        assert training is True and hasattr(
+            self, "inputs"), "Please set training as True before do BP. "
+
+        # TODO: CPU backward
+
+        # GPU backward
+        dx = singa.GpuRNNBackwardx(self.inputs[2], dy, self.inputs[1], self.handle)
+        dW = singa.GpuRNNBackwardW(self.inputs[0], self.inputs[2], self.handle)
+        return dx, dW
+
+class RNN_direct(Layer):
 
 Review comment:
   let's unify all the rnn implementation in this way
   
   ```python
   def RNN(hidden_size, num_layers=1, dropout=0.0, direction='one', return_seq=False, return_state=False,
alg='lstm', backend='cudnn') :
      if backend == 'cudnn':
         reutrn CudnnRNN(hidden_size, num_layers, dropout, direction, mode)
      if backend == 'native':
        if mode == 'lstm':
         return LSTM()
        elif mode == 'vanilla':
          return VanillaRNN()
        ....
   ```
   
   All rnn classes inherit 
   ```python
   class RNNBase(Layer):
      def __init__(self, hidden_size, num_layers=1, dropout=0.0, direction='one', return_seq=False,
return_state=False, alg='lstm')
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

Mime
View raw message