Skip to content

Commit 727a116

Browse files
committed
add entrypoint for flagos multi-backend plugin system
1 parent 366798e commit 727a116

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

transformer_engine/common/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ def load_framework_extension(framework: str) -> None:
191191
sys.modules[module_name] = solib
192192
spec.loader.exec_module(solib)
193193

194+
# Plugin system: if NVTE_ENABLE_PLUGIN=1, let plugin stub take over
195+
# transformer_engine_torch and register original pybind as _nv for CUDA backend.
196+
if os.environ.get("NVTE_ENABLE_PLUGIN", "0") == "1":
197+
sys.modules[module_name + "_nv"] = solib
198+
try:
199+
from plugin import load_plugins
200+
load_plugins()
201+
except ImportError as e:
202+
print(f"[TE] NVTE_ENABLE_PLUGIN=1 but plugin import failed: {e}")
203+
194204

195205
def sanity_checks_for_pypi_installation() -> None:
196206
"""Ensure that package is installed correctly if using PyPI."""

transformer_engine/pytorch/attention/dot_product_attention/dot_product_attention.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@
148148
_dpa_fp8ds_reduce_amax = os.getenv("NVTE_DPA_FP8DS_REDUCE_AMAX", "1") == "1"
149149

150150

151+
# Plugin system: override FlashAttention and get_attention_backend if enabled
152+
if os.environ.get("NVTE_ENABLE_PLUGIN", "0") == "1":
153+
_FlashAttentionNative = FlashAttention
154+
FlashAttention = getattr(tex, "flash_attention", _FlashAttentionNative)
155+
dpa_utils._original_get_attention_backend = dpa_utils.get_attention_backend
156+
dpa_utils.get_attention_backend = tex.get_attention_backend
157+
158+
151159
__all__ = ["DotProductAttention"]
152160

153161

0 commit comments

Comments
 (0)