Skip to content

[REFACTOR][PYTHON] Consolidate derived_object into tvm.ir.utils#19630

Merged
tlopex merged 1 commit into
apache:mainfrom
tqchen:tvm-consolidate-derived-object
May 28, 2026
Merged

[REFACTOR][PYTHON] Consolidate derived_object into tvm.ir.utils#19630
tlopex merged 1 commit into
apache:mainfrom
tqchen:tvm-consolidate-derived-object

Conversation

@tqchen
Copy link
Copy Markdown
Member

@tqchen tqchen commented May 27, 2026

Summary

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), so neither location was the right home.

Move the single canonical definition into a new python/tvm/ir/utils.py. tvm.ir loads before both tvm.tirx and tvm.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 change runtime/support.py is empty and is removed; meta_schedule/__init__.py drops its now-dead re-export. No alias shims are left behind — callers update imports directly.

Copy link
Copy Markdown
Contributor

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

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

Comment thread python/tvm/tirx/functor.py
Comment thread python/tvm/tirx/functor.py Outdated
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.
@tqchen tqchen force-pushed the tvm-consolidate-derived-object branch from 4b2da06 to 02e4019 Compare May 27, 2026 22:59
@tqchen tqchen changed the title [REFACTOR][PYTHON] Consolidate derived_object into tvm.s_tir.utils [REFACTOR][PYTHON] Consolidate derived_object into tvm.ir.utils May 27, 2026
@tlopex tlopex merged commit 61ae85b into apache:main May 28, 2026
11 of 12 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