Skip to content

[REFACTOR][PYTHON] Consolidate backend autoload infra#19769

Open
tqchen wants to merge 4 commits into
apache:mainfrom
tqchen:tvm-consolidate-backend-autoload-infrastructure
Open

[REFACTOR][PYTHON] Consolidate backend autoload infra#19769
tqchen wants to merge 4 commits into
apache:mainfrom
tqchen:tvm-consolidate-backend-autoload-infrastructure

Conversation

@tqchen

@tqchen tqchen commented Jun 14, 2026

Copy link
Copy Markdown
Member

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_backends while preserving compatibility routes from the previous top-level helper and tvm.base.load_backend_libs.

  • Move backend runtime DSO loading into tvm.backend._autoload_backends
  • Route backend.load_all() through the backend autoload helper
  • Keep the previous top-level _autoload_backends module as a thin compatibility import

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.

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

tqchen added 3 commits June 14, 2026 19:26
Backend-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.
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.

1 participant