Hzfengsy commented on code in PR #17599:
URL: https://github.com/apache/tvm/pull/17599#discussion_r1929557617


##########
python/tvm/relax/transform/optimize_batchnorm.py:
##########
@@ -0,0 +1,103 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local
+"""Relax Optimize Batchnorm to fold it into previous Conv pass."""

Review Comment:
   If I understand correctly, this pass aims to fuse batchnorm into the conv2d 
as what relay does. 
   
   If so, you can call `DecomposeOpsForInference` before `FuseOps` and 
`FuseTIR`, which have the same function as this pass



##########
src/relax/op/tensor/binary.cc:
##########
@@ -157,15 +157,21 @@ InferLayoutOutput InferLayoutBinaryEwise(const Call& call,
 
   Optional<ShapeExpr> shape1 = 
GetRef<ShapeExpr>(x1_sinfo->shape.as<ShapeExprNode>());
   Optional<ShapeExpr> shape2 = 
GetRef<ShapeExpr>(x2_sinfo->shape.as<ShapeExprNode>());
+
   // Lets handle sub indexing as long as primal dims are matching
-  if (layout1->layout.ndim_primal() == layout2->layout.ndim_primal()) {
-    if ((layout1->layout.ndim() >= layout2->layout.ndim()) && 
shape2.defined()) {
-      if (CanProveLayoutTransform(layout2->layout, layout1->layout, 
shape2.value()->values)) {
-        return InferLayoutOutput({layout1, layout1}, {layout1}, 
Attrs(call->attrs));
-      }
-    } else if (shape1.defined()) {
-      if (CanProveLayoutTransform(layout1->layout, layout2->layout, 
shape1.value()->values)) {
-        return InferLayoutOutput({layout2, layout2}, {layout2}, 
Attrs(call->attrs));
+  if ((layout1->layout.ndim() != layout1->layout.ndim_primal()) ||

Review Comment:
   I'm sorry that I cannot understand the changes. Could you please write 
simple example for each case?



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to