[REFACTOR] Remove runtime/object.py shim and route Object via tvm_ffi#19440
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
spectrometerHBH
approved these changes
Apr 25, 2026
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).
cb0c605 to
a28ff02
Compare
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-side cleanup that drops the
python/tvm/runtime/object.pyshim androutes
tvm.runtime.Objectdirectly totvm_ffi.Object. Thetvm.runtime.Objectre-export is preserved (now a re-export oftvm_ffi.Object) so external callers keep working.The load-bearing
__object_repr__install — which wires TVM IR objectsup to the rich C++
ReprPrinterregistered throughinit_ffi_api("node", ...)— moves intopython/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 righttime (after
init_ffi_apiregisters the C++ printer)._ffi_node_api.AsRepritself is kept:tvm_ffi's default repr isprimitive (
ClassName(ptr)); TVM IR objects need the rich printerregistered via
init_ffi_api("node", ...).AsRepris what bridgesthat printer back into Python
repr(obj)and is also the runtime-onlyfallback when
libtvm.sois unavailable.The 7 in-tree importers of the deleted shim (plus one straggler in
runtime/disco/session.py) are switched to eitherfrom tvm.runtime import Objectorfrom tvm_ffi import Object,depending on which pattern the file already uses.
Test plan
python -c "import tvm; print(repr(tvm.IRModule({})))"producesTVMScript-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.