monklof commented on a change in pull request #7496:
URL: https://github.com/apache/tvm/pull/7496#discussion_r586076343



##########
File path: python/tvm/topi/nn/batch_matmul.py
##########
@@ -61,9 +62,17 @@ def batch_matmul(x, y, oshape=None, 
auto_scheduler_rewritten_layout=""):
     _, M, K = x.shape
     k = te.reduce_axis((0, K), name="k")
     if oshape is None:
-        assert XB == YB or XB == 1 or YB == 1, "batch dimension doesn't match"
-        assert x_shape[2] == y_shape[2], "shapes of x and y is inconsistent"
-        batch = te.max(XB, YB)
+        if isinstance(XB, int) and isinstance(YB, int):
+            assert XB == YB or XB == 1 or YB == 1, "batch dimension doesn't 
match"
+            batch = max(XB, YB)
+        elif isinstance(XB, tir.expr.Var):
+            batch = XB
+        else:
+            batch = YB

Review comment:
       I agree that my implementation here is incomplete, the basic principle 
is: one of XB and YB should be 1, and we choose the another as `batch`,
   
   But it is a little complicated here since XB/YB can be unknown at compile 
time:
   1. if XB and YB are both `int`, one of them should be 1, and we choose the 
bigger one as `batch` at compile time.
   2. if either or both them are `Var`, we actually should choose `batch` and 
do validation at runtime, may be we should use `TIR`'s `IfThenElse` and 
`AssertStmt` to complete the logic here.
   
   In my case, one of them is `var` and another is `1`, so I coded as above.
   
   Thanks for reminding, maybe we should implement it as strict as possible?




----------------------------------------------------------------
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:
[email protected]


Reply via email to