Skip to content

Commit 61ae85b

Browse files
authored
[REFACTOR][PYTHON] Consolidate derived_object into tvm.ir.utils (#19630)
## 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.
1 parent 23db01f commit 61ae85b

24 files changed

Lines changed: 43 additions & 204 deletions

python/tvm/contrib/hexagon/meta_schedule.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import tvm
2424
from tvm.driver import build as tvm_build
2525
from tvm.ir.module import IRModule
26+
from tvm.ir.utils import derived_object
2627
from tvm.runtime import Module, Tensor
2728
from tvm.s_tir.meta_schedule.builder import LocalBuilder
2829
from tvm.s_tir.meta_schedule.runner import (
@@ -36,7 +37,7 @@
3637
default_alloc_argument,
3738
default_run_evaluator,
3839
)
39-
from tvm.s_tir.meta_schedule.utils import cpu_count, derived_object
40+
from tvm.s_tir.meta_schedule.utils import cpu_count
4041
from tvm.s_tir.transform import RemoveWeightLayoutRewriteBlock
4142
from tvm.support.popen_pool import PopenPoolExecutor
4243
from tvm.target import Target
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
18-
"""Runtime support infra of TVM."""
17+
"""Utilities shared across TVM IR packages."""
1918

2019
from typing import TypeVar
2120

python/tvm/relax/expr_functor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import tvm_ffi
2424

2525
from tvm.ir import Op
26+
from tvm.ir.utils import derived_object
2627
from tvm.runtime import Object
27-
from tvm.runtime.support import derived_object
2828

2929
from ..ir.module import IRModule
3030
from . import _ffi_api

python/tvm/s_tir/meta_schedule/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@
5353
from .tir_integration import tune_tir
5454
from .tune import tune_tasks
5555
from .tune_context import TuneContext
56-
from .utils import derived_object
5756
from .post_optimization import post_opt

python/tvm/s_tir/meta_schedule/builder/local_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
from tvm_ffi import register_global_func
2626

2727
from tvm.ir import IRModule
28+
from tvm.ir.utils import derived_object
2829
from tvm.runtime import Module, Tensor, load_param_dict, save_param_dict
2930
from tvm.support.popen_pool import MapResult, PopenPoolExecutor, StatusKind
3031
from tvm.target import Target
3132

3233
from ..logging import get_logger
33-
from ..utils import cpu_count, derived_object, get_global_func_with_default_on_worker
34+
from ..utils import cpu_count, get_global_func_with_default_on_worker
3435
from .builder import BuilderInput, BuilderResult, PyBuilder
3536

3637
logger = get_logger(__name__) # pylint: disable=invalid-name

python/tvm/s_tir/meta_schedule/cost_model/mlp_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import torch # type: ignore
3333

3434
import tvm
35+
from tvm.ir.utils import derived_object
3536
from tvm.support.tar import tar, untar
3637

3738
from ....runtime import Tensor
@@ -43,7 +44,7 @@
4344
from ..runner import RunnerResult
4445
from ..search_strategy import MeasureCandidate
4546
from ..tune_context import TuneContext
46-
from ..utils import derived_object, shash2hex
47+
from ..utils import shash2hex
4748

4849
logger = get_logger("mlp_model") # pylint: disable=invalid-name
4950

python/tvm/s_tir/meta_schedule/cost_model/random_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
Random cost model
1919
"""
2020

21+
from tvm.ir.utils import derived_object
22+
2123
from ..cost_model import PyCostModel
2224
from ..runner import RunnerResult
2325
from ..search_strategy import MeasureCandidate
2426
from ..tune_context import TuneContext
25-
from ..utils import derived_object # type: ignore
2627

2728

2829
@derived_object

python/tvm/s_tir/meta_schedule/cost_model/xgb_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import numpy as np # type: ignore
2727

28+
from tvm.ir.utils import derived_object
2829
from tvm.support.tar import tar, untar
2930

3031
from ....runtime import Tensor
@@ -33,7 +34,7 @@
3334
from ..logging import get_logger
3435
from ..runner import RunnerResult
3536
from ..search_strategy import MeasureCandidate
36-
from ..utils import cpu_count, derived_object, shash2hex
37+
from ..utils import cpu_count, shash2hex
3738
from .metric import max_curve
3839

3940
if TYPE_CHECKING:

python/tvm/s_tir/meta_schedule/feature_extractor/random_feature_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import numpy as np # type: ignore
2020

2121
import tvm.runtime
22+
from tvm.ir.utils import derived_object
2223

2324
from ..feature_extractor import PyFeatureExtractor
2425
from ..search_strategy import MeasureCandidate
2526
from ..tune_context import TuneContext
26-
from ..utils import derived_object
2727

2828

2929
@derived_object

python/tvm/s_tir/meta_schedule/runner/local_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
from contextlib import contextmanager
2323

2424
import tvm
25+
from tvm.ir.utils import derived_object
2526
from tvm.support.popen_pool import PopenPoolExecutor
2627

2728
from ....runtime import Device, Module
2829
from ..logging import get_logger
2930
from ..profiler import Profiler
30-
from ..utils import derived_object, get_global_func_with_default_on_worker
31+
from ..utils import get_global_func_with_default_on_worker
3132
from .config import EvaluatorConfig
3233
from .runner import PyRunner, PyRunnerFuture, RunnerFuture, RunnerInput, RunnerResult
3334
from .utils import (

0 commit comments

Comments
 (0)