Skip to content

[REFACTOR] Remove tvm.runtime.packed_func and container shims; route via tvm_ffi#19442

Merged
spectrometerHBH merged 2 commits into
apache:mainfrom
tqchen:remove-runtime-shims
Apr 25, 2026
Merged

[REFACTOR] Remove tvm.runtime.packed_func and container shims; route via tvm_ffi#19442
spectrometerHBH merged 2 commits into
apache:mainfrom
tqchen:remove-runtime-shims

Conversation

@tqchen

@tqchen tqchen commented Apr 25, 2026

Copy link
Copy Markdown
Member

Summary

  • Delete the three Python shim modules that re-exported tvm-ffi types under tvm.runtime / tvm.ir:
    python/tvm/runtime/packed_func.py, python/tvm/runtime/container.py, python/tvm/ir/container.py.
  • Drop the matching re-exports from tvm.runtime, tvm.ir, and tvm package init files, so
    tvm.runtime.PackedFunc, tvm.runtime.ShapeTuple, tvm.runtime.String, tvm.ir.Array,
    tvm.ir.Map, and tvm.container.Array no longer exist.
  • Migrate every productive caller, test, and tutorial to the canonical names: tvm_ffi.Function,
    tvm_ffi.Shape, tvm_ffi.core.String, tvm_ffi.Array, and tvm_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 run clean on touched files

…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`.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread python/tvm/relax/distributed/global_info.py
Comment thread python/tvm/s_tir/meta_schedule/arg_info.py Outdated
Comment thread python/tvm/runtime/_tensor.py
Comment thread python/tvm/runtime/_tensor.py
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 spectrometerHBH merged commit 9edd5bd into apache:main Apr 25, 2026
11 checks passed
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.

2 participants