Skip to content

Add missing Slice layout fallback check of stride=1.#10690

Merged
masahi merged 4 commits intoapache:mainfrom
lazycal:fix-slicelayout
Mar 24, 2022
Merged

Add missing Slice layout fallback check of stride=1.#10690
masahi merged 4 commits intoapache:mainfrom
lazycal:fix-slicelayout

Conversation

@lazycal
Copy link
Contributor

@lazycal lazycal commented Mar 19, 2022

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

if (strides.defined() && i < strides.size()) {
auto stride = strides[i];
// arbitrary stride is not supported
if (stride.defined() && stride->value != 1) {
return out_default;
}
}
. 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]` .

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

@github-actions github-actions bot requested a review from masahi March 19, 2022 19:52
@lazycal lazycal changed the title Add missing Slice layout fallback check. Add missing Slice layout fallback check of stride=1. Mar 19, 2022
@masahi
Copy link
Member

masahi commented Mar 19, 2022

The CI is having an flaky issue with i386, please wait until #10687 lands (or run more jobs until it succeeds)

@lazycal
Copy link
Contributor Author

lazycal commented Mar 23, 2022

Not sure what is going on with the CI. I thought my previous commit was stuck at some stage but now I saw a check there, but still I saw tvm-ci/pr-merge Expected — Waiting for status to be reported as one pending check. Could you take a look @masahi ?

@masahi masahi merged commit 82b6ea9 into apache:main Mar 24, 2022
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
* Add missing Slice layout fallback check.

* Fix lint

* jostle ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants