[REFACTOR][PYTHON] Consolidate derived_object into tvm.ir.utils#19630
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the location of the derived_object decorator, moving it from tvm.s_tir.meta_schedule.utils to tvm.s_tir.utils and updating all import references across the codebase. Additionally, it implements lazy loading for derived_object, visitor, and mutator in tvm/tirx/functor.py to resolve circular import issues. The reviewer feedback recommends introducing TYPE_CHECKING guards in tvm/tirx/functor.py to declare these lazily loaded attributes at the module level, ensuring static analysis tools and IDEs can resolve them properly while preserving their original docstrings.
derived_object was duplicated byte-for-byte across python/tvm/runtime/support.py and python/tvm/s_tir/meta_schedule/utils.py. The function is not a runtime feature and is used outside meta_schedule (tvm.relax, tvm.tirx). Move the single canonical definition into python/tvm/ir/utils.py. tvm.ir loads before tvm.tirx and tvm.s_tir, so eager top-level imports work from every consumer without load-order shenanigans. Rewrite all 25 caller imports (runtime/support importers, meta_schedule production sites, tests). Delete python/tvm/runtime/support.py and remove the duplicate from python/tvm/s_tir/meta_schedule/utils.py.
4b2da06 to
02e4019
Compare
tlopex
approved these changes
May 28, 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
derived_objectwas duplicated byte-for-byte acrosspython/tvm/runtime/support.pyandpython/tvm/s_tir/meta_schedule/utils.py. The function is not a runtime feature and is used outside meta_schedule (tvm.relax, tvm.tirx), so neither location was the right home.Move the single canonical definition into a new
python/tvm/ir/utils.py.tvm.irloads before bothtvm.tirxandtvm.s_tir, so eager top-level imports work from every consumer without load-order workarounds.Rewrite all 25 caller imports. Keep the better-typed
cls: type[T] -> type[T]signature from the runtime-side copy. After this changeruntime/support.pyis empty and is removed;meta_schedule/__init__.pydrops its now-dead re-export. No alias shims are left behind — callers update imports directly.