singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [singa] dcslin commented on a change in pull request #662: CUDNN LSTM
Date Sat, 11 Apr 2020 03:01:41 GMT
dcslin commented on a change in pull request #662: CUDNN LSTM
URL: https://github.com/apache/singa/pull/662#discussion_r407008958
 
 

 ##########
 File path: python/singa/autograd.py
 ##########
 @@ -3239,95 +3239,176 @@ def __init__(
             bidirectional (bool): If True, becomes a bidirectional RNN. 
                 Default: False
         """
-        self.nonlinearity = nonlinearity
-
-        Wx_shape = (input_size, hidden_size)
-        self.Wx = []
-        for i in range(4):
-            w = Tensor(shape=Wx_shape, requires_grad=True, stores_grad=True)
-            w.gaussian(0.0, 1.0)
-            self.Wx.append(w)
-
-        Wh_shape = (hidden_size, hidden_size)
-        self.Wh = []
-        for i in range(4):
-            w = Tensor(shape=Wh_shape, requires_grad=True, stores_grad=True)
-            w.gaussian(0.0, 1.0)
-            self.Wh.append(w)
-
-        Bx_shape = (hidden_size,)
-        self.Bx = []
-        for i in range(4):
-            b = Tensor(shape=Bx_shape, requires_grad=True, stores_grad=True)
-            b.set_value(0.0)
-            self.Bx.append(b)
-
-        self.Bh = []
-        for i in range(4):
-            b = Tensor(shape=Bx_shape, requires_grad=True, stores_grad=True)
-            b.set_value(0.0)
-            self.Bh.append(b)
-
-        self.params = self.Wx + self.Wh + self.Bx + self.Bh
+        self.backend = backend
+        if backend == "singa":
+            self.nonlinearity = nonlinearity
+
+            Wx_shape = (input_size, hidden_size)
+            self.Wx = []
+            for i in range(4):
+                w = Tensor(shape=Wx_shape, requires_grad=True, stores_grad=True)
+                w.gaussian(0.0, 1.0)
+                self.Wx.append(w)
+
+            Wh_shape = (hidden_size, hidden_size)
+            self.Wh = []
+            for i in range(4):
+                w = Tensor(shape=Wh_shape, requires_grad=True, stores_grad=True)
+                w.gaussian(0.0, 1.0)
+                self.Wh.append(w)
+
+            Bx_shape = (hidden_size,)
+            self.Bx = []
+            for i in range(4):
+                b = Tensor(shape=Bx_shape, requires_grad=True, stores_grad=True)
+                b.set_value(0.0)
+                self.Bx.append(b)
+
+            self.Bh = []
+            for i in range(4):
+                b = Tensor(shape=Bx_shape, requires_grad=True, stores_grad=True)
+                b.set_value(0.0)
+                self.Bh.append(b)
+
+            self.params = self.Wx + self.Wh + self.Bx + self.Bh
+        elif backend == "cudnn":
+            if not singa.USE_CUDA:
+                raise Exception("Could not use cudnn without cuda compiled.\n")
+            if not inputs:
+                raise Exception("Input is required for init cudnn LSTM.\n")
 
 Review comment:
   this is similar to c++ operation conv handle constructor that requires input for constructing
cudnn desc.

----------------------------------------------------------------
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