chrishkchris commented on a change in pull request #515: SINGA-474 Add gemm 
operator
URL: https://github.com/apache/incubator-singa/pull/515#discussion_r314934800
 
 

 ##########
 File path: python/singa/autograd.py
 ##########
 @@ -2316,3 +2315,37 @@ def backward(self, dy):
 def max(a,b):
     return Max()(a,b)[0]
 
+class GEMM(Operation):
+    def __init__(self, alpha, beta, transA, transB):
+        self.alpha = alpha
+        self.beta = beta
+        self.transA = transA
+        self.transB = transB
+        super(GEMM, self).__init__()
+
+    def forward(self, A, B, C):
+        if self.transA:
+            A = singa.DefaultTranspose(A)
+        if self.transB:
+            B = singa.DefaultTranspose(B)
+        if training:
+            self.A = A
+            self.B = B
+        
+        singa.MultWithScale(self.alpha, A, B, self.beta, C)
+        return C
+
+    def backward(self, dY):
+        dC = singa.MultFloat(dY, self.beta)
 
 Review comment:
   Is the backward the same when transA and transB =1 or 0?

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


With regards,
Apache Git Services

Reply via email to