Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions tests/python/relax/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ruff: noqa: F811, F841
# ruff: noqa: F841


import pytest
Expand Down Expand Up @@ -834,18 +834,5 @@ def reduction(A: T.Buffer((4, 4), "float32"), B: T.Buffer((4,), "float32")):
assert not has_reshape_pattern(reduction)


def test_reshape_pattern_reject_reduction():
@T.prim_func(s_tir=True)
def reduction(A: T.Buffer((4, 4), "float32"), B: T.Buffer((4,), "float32")):
for i0, i1 in T.grid(4, 4):
with T.sblock("identity"):
vi0, vi1 = T.axis.remap("SR", [i0, i1])
with T.init():
B[vi0] = T.float32(0)
B[vi0] = B[vi0] + A[vi0, vi1]

assert not has_reshape_pattern(reduction)


if __name__ == "__main__":
tvm.testing.main()
23 changes: 1 addition & 22 deletions tests/python/relax/test_analysis_well_formed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ruff: noqa: F811, RUF005
# ruff: noqa: RUF005

import pytest

Expand Down Expand Up @@ -1455,26 +1455,5 @@ def main(
rx.analysis.well_formed(Module)


def test_incomplete_ty_must_be_consistent():
"""Type annotations must be accurate

Even though Type annotation may be less specific, the
information that they do contain must be correct.

"""

@I.ir_module(check_well_formed=False, s_tir=True)
class Module:
@R.function
def main(
A: R.Tensor(shape=[128, 32], dtype="float32"),
B: R.Tensor(shape=[128, 32], dtype="float32"),
):
C: R.Tensor(ndim=3) = R.add(A, B)
return C

assert not rx.analysis.check_well_formed(Module)


if __name__ == "__main__":
tvm.testing.main()
12 changes: 6 additions & 6 deletions tests/python/relax/test_ast_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ruff: noqa: F811, F841
# ruff: noqa: F841
import re
from functools import partial

Expand Down Expand Up @@ -194,15 +194,15 @@ def test_seq_expr() -> None:
assert "body=" in seqe_str


def test_shape_expr() -> None:
m = tirx.Var("m", ty="int32")
n = tirx.Var("n", ty="int32")
def test_shape_expr_symbolic() -> None:
m = tirx.Var("m", ty="int64")
n = tirx.Var("n", ty="int64")
s = rx.ShapeExpr([m, n])
s_str = dump_ast(s)
assert s_str.startswith("ShapeExpr(")
assert "values=" in s_str
assert "Expr(value=`m: int32`)" in s_str
assert "Expr(value=`n: int32`)" in s_str
assert "Expr(value=`m`)" in s_str
assert "Expr(value=`n`)" in s_str


def test_func():
Expand Down
11 changes: 5 additions & 6 deletions tests/python/relax/test_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ruff: noqa: F811
import numpy as np
import pytest
import tvm_ffi
Expand Down Expand Up @@ -160,8 +159,8 @@ def test_match_cast() -> None:
var = rx.Var("v0", R.Shape())
b0 = rx.MatchCast(var, shape, R.Tensor([m, n], "int32"))
assert b0.value == shape
assert b0.pattern[0] == m
assert b0.pattern[1] == n
assert b0.ty.shape[0].same_as(m)
assert b0.ty.shape[1].same_as(n)
assert b0.var is not None

# var1: R.Tensor((m, n), "float32") =
Expand All @@ -171,12 +170,12 @@ def test_match_cast() -> None:
var = rx.Var("v1", R.Tensor([m, n], "float32"))
b1 = rx.MatchCast(var, value, R.Tensor([m, n], "float32"))
assert b1.value == value
assert b1.pattern[0] == m
assert b1.pattern[1] == n
assert b1.ty.shape[0].same_as(m)
assert b1.ty.shape[1].same_as(n)
assert b1.var is not None


def test_match_cast() -> None:
def test_match_cast_json_roundtrip() -> None:
m = tirx.Var("m", ty="int64")
n = tirx.Var("n", ty="int64")
ivalue = rx.Var("input_value")
Expand Down
24 changes: 1 addition & 23 deletions tests/python/relax/test_transform_gradient_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ruff: noqa: E501, F811
# ruff: noqa: E501
"""Unit tests for gradient with checkpointing."""

import tvm
Expand Down Expand Up @@ -693,28 +693,6 @@ def main(x: R.Tensor((3, 3), "float32")) -> R.Tensor((3, 3), "float32"):
assert_structural_equal(bb.get(), Expected)


def test_checkpoint_dag():
"""Comp. graph is a DAG with only one output. Here we only test the simple case: comp. graph
is a sequence of sub-graphs, and the checkpoints are the intersections of connected
subgraphs."""

def func(x):
return x * relax.const(2, "float32") * relax.const(2, "float32")

bb = BlockBuilder()
x = relax.Var("x", relax.TensorType((3, 3), "float32"))
with bb.function("main", [x]):
with bb.dataflow():
lv1 = bb.emit(nn.checkpoint(func, x))
lv2 = bb.emit(x * lv1)
lv3 = bb.emit(nn.checkpoint(func, lv2))
lv4 = bb.emit(lv2 * lv3)
lv5 = bb.emit(nn.checkpoint(func, lv4))
lv6 = bb.emit(lv4 * lv5)
gv = bb.emit_output(relax.op.sum(lv6))
bb.emit_func_output(gv)


def test_checkpoint_with_intermediate_require_grads():
def func(x):
return x * x * x
Expand Down
3 changes: 1 addition & 2 deletions tests/python/runtime/test_runtime_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ruff: noqa: F811

import numpy as np
import pytest
Expand Down Expand Up @@ -45,7 +44,7 @@ def test_1d_view_of_first_half_of_1d_arr():
np.testing.assert_equal(tvm_output.numpy(), np_expected)


def test_1d_view_of_first_half_of_1d_arr():
def test_1d_view_of_second_half_of_1d_arr():
"""Subset returned by Tensor::CreateView may have a byte offset"""
np_input = np.arange(1024, dtype="int32")
tvm_input = tvm.runtime.tensor(np_input)
Expand Down
Loading