lazycal opened a new pull request #10690:
URL: https://github.com/apache/tvm/pull/10690


   When doing layout optimization for slice, if `start` or `end` are divisibly 
by the pack factor and `stride=1`, a `layout_transform` can be saved. However, 
previous code only checks `stride=1` when `axes` is not specified, as in 
https://github.com/apache/tvm/blob/2fc7d16e99cf1d1df148e8db03296409916bd134/src/relay/op/tensor/transform.cc#L2735-L2741.
 This PR adds the same check to the other branch. 
   
   The following model can trigger this bug with error message ``...In 
particular `Tensor[(4, 1, 1, 1), float32]` does not match `Tensor[(4, 3, 1, 1), 
float32]` ``.
   
   ```python
   import tvm
   from tvm import relay
   import numpy as np
   from tvm.relay import testing
   
   x = relay.var("data", shape=(4, 12, 1, 1), dtype="float32")
   O, I, H, W = 9, 12, 1, 1
   conv_out = relay.nn.conv2d(
       x,
       relay.const(np.ones([O, I, H, W], dtype="float32")),
       strides=[1, 1],
       padding=0,
       channels=O,
       kernel_size=[H, W],
   )
   bias_out = relay.nn.bias_add(
       conv_out, relay.const(np.ones([O], dtype="float32")))
   y = relay.strided_slice(bias_out, begin=[3], end=[6], strides=[3], axes=[1])
   
   mod, _ = testing.create_workload(y)
   with tvm.transform.PassContext(opt_level=3):
       with tvm.target.Target("llvm"):
           mod = relay.transform.CanonicalizeOps()(mod)
           mod = relay.transform.AlterOpLayout()(mod)
   ```
   
   cc @masahi 


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