Skip to content

Commit 93447ba

Browse files
agron911meta-codesync[bot]
authored andcommitted
[Cherry-pick] Add env var to speed up backend detection in tree (#8046) (#566)
Summary: Cherry-picked from upstream OAI repository. Original Commit: 440a157 Original Author: Thomas Raoux Original Date: 2025-09-03 00:59:23 -0700 Original commit message: ``` Add env var to speed up backend detection in tree (#8046) ``` This PR was automatically cherry-picked from the upstream triton-lang/triton repository. Pull Request resolved: #566 Reviewed By: dshi7 Differential Revision: D85984069 Pulled By: agron911 fbshipit-source-id: 8e801bb1843913f40cef7f1ab06e9139225d80e1
1 parent e43d7a7 commit 93447ba

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

python/triton/backends/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib
2+
import os
23
import inspect
34
import sys
45
from dataclasses import dataclass
@@ -36,6 +37,24 @@ class Backend:
3637

3738
def _discover_backends() -> dict[str, Backend]:
3839
backends = dict()
40+
# Fast path: optionally skip entry point discovery (which can be slow) and
41+
# discover only in-tree backends under the `triton.backends` namespace.
42+
skip_entrypoints_env = os.environ.get("TRITON_BACKENDS_IN_TREE", "")
43+
44+
if skip_entrypoints_env == "1":
45+
root = os.path.dirname(__file__)
46+
for name in os.listdir(root):
47+
if not os.path.isdir(os.path.join(root, name)):
48+
continue
49+
if name.startswith('__'):
50+
continue
51+
compiler = importlib.import_module(f"triton.backends.{name}.compiler")
52+
driver = importlib.import_module(f"triton.backends.{name}.driver")
53+
backends[name] = Backend(_find_concrete_subclasses(compiler, BaseBackend),
54+
_find_concrete_subclasses(driver, DriverBase))
55+
return backends
56+
57+
# Default path: discover via entry points for out-of-tree/downstream plugins.
3958
for ep in entry_points().select(group="triton.backends"):
4059
compiler = importlib.import_module(f"{ep.value}.compiler")
4160
driver = importlib.import_module(f"{ep.value}.driver")

0 commit comments

Comments
 (0)