[REFACTOR][PYTHON] Consolidate backend autoload infra#19769
Conversation
Backend loading is easier to reason about when library discovery, in-tree backend hook loading, and out-of-tree entry point autoload all live under the backend namespace. This moves the implementations into tvm.backend._autoload_backends while preserving compatibility routes for the previous top-level autoload helper and tvm.base.load_backend_libs.
There was a problem hiding this comment.
Code Review
This pull request refactors TVM's backend autoloading infrastructure by consolidating the autoloading logic, builtin backend definitions, and library loading utilities into a new module python/tvm/backend/_autoload_backends.py. It updates references across python/tvm/__init__.py, python/tvm/backend/__init__.py, and python/tvm/base.py to use this new structure. Feedback on the changes suggests making the runtime_lib_path resolution more robust in load_backend_libs to handle cases where a directory path is passed instead of a file path, preventing potential silent failures.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| loaded_libs = _LOADED_LIBS | ||
|
|
||
| runtime_dir = Path(runtime_lib_path).resolve().parent |
There was a problem hiding this comment.
If runtime_lib_path is a directory rather than a file path, calling .parent will resolve to its parent directory, which can lead to silent failures when searching for backend runtime libraries.
We can make this more robust by checking if the path is a directory and using it directly if so.
path = Path(runtime_lib_path).resolve()
runtime_dir = path if path.is_dir() else path.parentBackend-specific target detection belongs with the backend hook registration path instead of a central target-side device map. This keeps CPU detection in the generic target module, lets backend hooks register their own device detectors, and removes the unused x86 SIMD lane global hook.
Summary
Backend loading is easier to maintain when native backend library discovery, in-tree backend Python hook loading, and out-of-tree entry point autoload are owned by the backend namespace. This PR consolidates those paths under
tvm.backend._autoload_backendswhile preserving compatibility routes from the previous top-level helper andtvm.base.load_backend_libs.tvm.backend._autoload_backendsbackend.load_all()through the backend autoload helper_autoload_backendsmodule as a thin compatibility import