-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[TE] Raise error for non-bijective transformation #12926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TE] Raise error for non-bijective transformation #12926
Conversation
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.
| 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) | ||
|
|
||
|
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)There was a problem hiding this comment.
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.
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.
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.
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
DetectIterMapwith a check done on the returnedpadding_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.