From 553e91ccb5af1d4e005d0410d202b8f64535efdf Mon Sep 17 00:00:00 2001 From: Anai-Guo Date: Sat, 12 Sep 2026 12:23:02 -0700 Subject: [PATCH] [Test] Restore shadowed duplicate test functions in relax/runtime tests Several test modules define the same test function name twice. The second definition rebinds the module-level name, so pytest only collects the later one and the earlier test silently never runs. File-level `# ruff: noqa: F811` headers were hiding the lint signal. - test_expr.py: rename the second test_match_cast to test_match_cast_json_roundtrip; update the restored first test from the removed MatchCast.pattern field to MatchCast.ty.shape. - test_ast_printer.py: rename the first test_shape_expr to test_shape_expr_symbolic; ShapeExpr now requires int64 symbolic vars, so update the vars and expected printout accordingly. - test_runtime_nd_array.py: the second test_1d_view_of_first_half_of_1d_arr views the second half via relative_byte_offset; rename it to test_1d_view_of_second_half_of_1d_arr (matching the 2d variant). - test_transform_gradient_checkpoint.py: the second test_checkpoint_dag is a truncated copy without the Expected module or the assert_structural_equal check, and it was the one being collected. Remove it so the full test runs. - test_analysis.py / test_analysis_well_formed.py: remove byte-identical second copies of test_reshape_pattern_reject_reduction and test_incomplete_ty_must_be_consistent. Drop F811 from the file-level noqa headers that no longer need it. Co-Authored-By: Claude Opus 5 (1M context) --- tests/python/relax/test_analysis.py | 15 +----------- .../python/relax/test_analysis_well_formed.py | 23 +----------------- tests/python/relax/test_ast_printer.py | 12 +++++----- tests/python/relax/test_expr.py | 11 ++++----- .../test_transform_gradient_checkpoint.py | 24 +------------------ tests/python/runtime/test_runtime_nd_array.py | 3 +-- 6 files changed, 15 insertions(+), 73 deletions(-) diff --git a/tests/python/relax/test_analysis.py b/tests/python/relax/test_analysis.py index 66c0a581fa81..57c9f0d8b999 100644 --- a/tests/python/relax/test_analysis.py +++ b/tests/python/relax/test_analysis.py @@ -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 @@ -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() diff --git a/tests/python/relax/test_analysis_well_formed.py b/tests/python/relax/test_analysis_well_formed.py index 23752550c9f1..d54899c0d3cd 100644 --- a/tests/python/relax/test_analysis_well_formed.py +++ b/tests/python/relax/test_analysis_well_formed.py @@ -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 @@ -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() diff --git a/tests/python/relax/test_ast_printer.py b/tests/python/relax/test_ast_printer.py index 2477dcdabde8..dc1997ab7968 100644 --- a/tests/python/relax/test_ast_printer.py +++ b/tests/python/relax/test_ast_printer.py @@ -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 @@ -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(): diff --git a/tests/python/relax/test_expr.py b/tests/python/relax/test_expr.py index fc53813afed2..85559caf0fec 100644 --- a/tests/python/relax/test_expr.py +++ b/tests/python/relax/test_expr.py @@ -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 @@ -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") = @@ -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") diff --git a/tests/python/relax/test_transform_gradient_checkpoint.py b/tests/python/relax/test_transform_gradient_checkpoint.py index 5ab76f8b410b..0cbebb3b5786 100644 --- a/tests/python/relax/test_transform_gradient_checkpoint.py +++ b/tests/python/relax/test_transform_gradient_checkpoint.py @@ -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 @@ -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 diff --git a/tests/python/runtime/test_runtime_nd_array.py b/tests/python/runtime/test_runtime_nd_array.py index e85c89fb22df..9eb80314b6a6 100644 --- a/tests/python/runtime/test_runtime_nd_array.py +++ b/tests/python/runtime/test_runtime_nd_array.py @@ -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 @@ -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)