Skip to content

Conversation

@Lunderberg
Copy link
Contributor

This is a fix for a bug introduced in #12904. Prior to then, an exception was raised when the transformation wouldn't be bijective over the transformed buffer's shape. The PR replaced the bijective check done as part of DetectIterMap with a check done on the returned padding_predicate. However, this check was not equivalent, and some transformations could erroneously apply, rather than raising an exception as being non-bijective.

This commit re-enables the bijectivity check in DetectIterMap, and adds a test case for this behavior.

This is a fix for a bug introduced in
apache#12904.  Prior to then, an
exception was raised when the transformation wouldn't be bijective
over the transformed buffer's shape.  The PR replaced the bijective
check done as part of `DetectIterMap` with a check done on the
returned `padding_predicate`.  However, this check was not equivalent,
and some transformations could erroneously apply, rather than
raising an exception as being non-bijective.

This commit re-enables the bijectivity check in `DetectIterMap`, and
adds a test case for this behavior.
Comment on lines +578 to +590
def test_non_divisible_transform_raises_error():
A = te.placeholder([1, 3, 8, 8])
B = te.compute(A.shape, lambda *indices: A[indices])
s = te.create_schedule(B.op)

transform = lambda n, c, h, w: [n, c // 4, h, w, c % 4]
# Error occurs here, because the transformation would introduce
# padding. Padded transforms are supported in TIR-based
# schedules.
with pytest.raises(tvm.TVMError):
s[B].transform_layout(transform)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Probably we can joint this test case with test_size_one_buffer? Just extend its testing parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, but I think it would make the test less readable as an example use case, specifically what behavior is being tested, because the desired behavior differs in each case. It would look something like below, but there's nothing to call attention to the fact that is_valid changes the expected behavior, and isn't just a parameter being used in the setup.

shape, transform, is_valid = tvm.testing.parameters(
    ([1, 8], lambda n, i: [i, n], True),
    ([1, 1, 8], lambda i, j, k: [j, te.AXIS_SEPARATOR, i, k], True),
    ([1, 1, 8], lambda i, j, k: [i, te.AXIS_SEPARATOR, j, k], True),
    ([1, 3, 8, 8], lambda i, j, k: [i, te.AXIS_SEPARATOR, j, k], False),
)


def test_transform_validity(shape, transform, is_valid):
    dtype = "int8"
    A = te.placeholder(shape, dtype, name="A")
    B = te.compute(
        shape=A.shape,
        fcompute=lambda *indices: A[indices].astype(dtype),
        name="B",
    )
    s = te.create_schedule(B.op)

    if is_valid:
        s[B].transform_layout(transform)
    else:
        with pytest.raises(tvm.TVMError):
            s[B].transform_layout(transform)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you. I agree.

@vinx13 vinx13 merged commit 493458e into apache:main Oct 14, 2022
@Lunderberg Lunderberg deleted the te_transform_layout_bijectivity branch October 14, 2022 18:10
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
This is a fix for a bug introduced in
apache#12904.  Prior to then, an
exception was raised when the transformation wouldn't be bijective
over the transformed buffer's shape.  The PR replaced the bijective
check done as part of `DetectIterMap` with a check done on the
returned `padding_predicate`.  However, this check was not equivalent,
and some transformations could erroneously apply, rather than
raising an exception as being non-bijective.

This commit re-enables the bijectivity check in `DetectIterMap`, and
adds a test case for this behavior.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
This is a fix for a bug introduced in
apache#12904.  Prior to then, an
exception was raised when the transformation wouldn't be bijective
over the transformed buffer's shape.  The PR replaced the bijective
check done as part of `DetectIterMap` with a check done on the
returned `padding_predicate`.  However, this check was not equivalent,
and some transformations could erroneously apply, rather than
raising an exception as being non-bijective.

This commit re-enables the bijectivity check in `DetectIterMap`, and
adds a test case for this behavior.
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.

3 participants