Skip to content

[REFACTOR] Remove runtime/object.py shim and route Object via tvm_ffi#19440

Merged
tqchen merged 1 commit into
apache:mainfrom
tqchen:remove-runtime-object-py
Apr 25, 2026
Merged

[REFACTOR] Remove runtime/object.py shim and route Object via tvm_ffi#19440
tqchen merged 1 commit into
apache:mainfrom
tqchen:remove-runtime-object-py

Conversation

@tqchen

@tqchen tqchen commented Apr 25, 2026

Copy link
Copy Markdown
Member

Summary

TVM-side cleanup that drops the python/tvm/runtime/object.py shim and
routes tvm.runtime.Object directly to tvm_ffi.Object. The
tvm.runtime.Object re-export is preserved (now a re-export of
tvm_ffi.Object) so external callers keep working.

The load-bearing __object_repr__ install — which wires TVM IR objects
up to the rich C++ ReprPrinter registered through
init_ffi_api("node", ...) — moves into python/tvm/runtime/_ffi_node_api.py.
That module is already imported as a side-effect-only module from
python/tvm/runtime/__init__.py, so the override fires at the right
time (after init_ffi_api registers the C++ printer).

_ffi_node_api.AsRepr itself is kept: tvm_ffi's default repr is
primitive (ClassName(ptr)); TVM IR objects need the rich printer
registered via init_ffi_api("node", ...). AsRepr is what bridges
that printer back into Python repr(obj) and is also the runtime-only
fallback when libtvm.so is unavailable.

The 7 in-tree importers of the deleted shim (plus one straggler in
runtime/disco/session.py) are switched to either
from tvm.runtime import Object or from tvm_ffi import Object,
depending on which pattern the file already uses.

Test plan

  • python -c "import tvm; print(repr(tvm.IRModule({})))" produces
    TVMScript-style output (rich repr preserved).
  • pytest tests/python/all-platform-minimal-test/ -x — 75 passed,
    77 skipped (matches baseline).
  • pytest tests/python/tirx-base/ -x — 273 passed, 2 skipped.
  • pre-commit run --files <changed files> — all hooks pass.
  • CI green.

@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 runtime by removing the python/tvm/runtime/object.py module and consolidating the Object class imports. The initialization logic for the object representation (object_repr) has been moved to python/tvm/runtime/_ffi_node_api.py, and multiple files have been updated to import Object directly from tvm.runtime or tvm_ffi. I have no feedback to provide.

Drop python/tvm/runtime/object.py and route tvm.runtime.Object directly
to tvm_ffi.Object. The load-bearing __object_repr__ install (which wires
TVM IR objects up to the rich C++ ReprPrinter registered through
init_ffi_api("node", ...)) moves into runtime/_ffi_node_api.py, which
is already imported as a side-effect-only module from runtime/__init__.py.

The remaining importers of the old shim are switched to
`from tvm.runtime import Object` (or `from tvm_ffi import Object` where
that matches the file's existing tvm_ffi imports).
@tqchen tqchen force-pushed the remove-runtime-object-py branch from cb0c605 to a28ff02 Compare April 25, 2026 15:08
@tqchen tqchen merged commit d883f50 into apache:main Apr 25, 2026
8 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