[REFACTOR] Remove tvm.runtime.packed_func and container shims; route via tvm_ffi#19442
Merged
Merged
Conversation
…via tvm_ffi Delete the three Python shim modules that re-exported tvm-ffi types under the `tvm.runtime` and `tvm.ir` namespaces, and migrate every caller to import directly from `tvm_ffi`: - `python/tvm/runtime/packed_func.py` (re-exported `tvm_ffi.Function as PackedFunc`) - `python/tvm/runtime/container.py` (re-exported `tvm_ffi.Shape as ShapeTuple`, `tvm_ffi.core.String`) - `python/tvm/ir/container.py` (re-exported `tvm_ffi.Array, Map`) Also drop the corresponding re-exports from `tvm.runtime`, `tvm.ir`, and `tvm` package `__init__.py`s, so `tvm.runtime.PackedFunc`, `tvm.runtime.ShapeTuple`, `tvm.runtime.String`, `tvm.ir.Array`, `tvm.ir.Map`, and `tvm.container.Array` no longer exist. All productive callers, tests, and tutorials now reference the canonical names: `tvm_ffi.Function`, `tvm_ffi.Shape`, `tvm_ffi.core.String`, `tvm_ffi.Array`, and `tvm_ffi.Map`.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the TVM Python API by migrating core container types—including Array, Map, String, and Shape—and the Function interface (formerly PackedFunc) to the tvm_ffi package. The changes span documentation, core runtime logic, and extensive test suites to ensure consistent use of the new FFI-based types. Review feedback suggests simplifying several instances of Shape object initialization by leveraging the constructor's ability to handle sequences directly, thereby removing redundant type checks and list comprehensions.
Apply two Gemini medium-priority style suggestions on PR apache#19442: - python/tvm/relax/distributed/global_info.py: relax the type check from `isinstance(shape, list | tuple)` to `not isinstance(shape, Shape)`, covering any non-Shape sequence input. - python/tvm/s_tir/meta_schedule/arg_info.py: collapse the if/else block for `shape_tuple` into a single conditional expression. Two related suggestions for python/tvm/runtime/_tensor.py (drop the explicit `[int(dim) for dim in shape]` cast inside `_create_view` and `empty`) are intentionally NOT applied: tvm_ffi.Shape's constructor rejects non-Integral elements, while the documented input type is `Sequence[typing.SupportsInt]` (e.g. PrimExpr), so the int() cast is load-bearing.
spectrometerHBH
approved these changes
Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tvm.runtime/tvm.ir:python/tvm/runtime/packed_func.py,python/tvm/runtime/container.py,python/tvm/ir/container.py.tvm.runtime,tvm.ir, andtvmpackage init files, sotvm.runtime.PackedFunc,tvm.runtime.ShapeTuple,tvm.runtime.String,tvm.ir.Array,tvm.ir.Map, andtvm.container.Arrayno longer exist.tvm_ffi.Function,tvm_ffi.Shape,tvm_ffi.core.String,tvm_ffi.Array, andtvm_ffi.Map.Test plan
pytest tests/python/all-platform-minimal-test(75 passed, 77 skipped)pytest tests/python/runtime/test_runtime_container.py tests/python/all-platform-minimal-test/test_runtime_packed_func.py(20 passed)pytest tests/python/ir/test_node_reflection.py tests/python/ir/test_container_structural_equal.py(32 passed)pytest tests/python/relax/test_vm_build.py tests/python/relax/test_vm_execbuilder.py tests/python/relax/test_vm_codegen_only.py(125 passed, 2 xfailed)pytest tests/python/relax/test_runtime_builtin.py tests/python/relax/test_op_misc.py(19 passed)pytest tests/python/target/test_target_target.py(37 passed, 3 skipped)pre-commit runclean on touched files