Skip to content

Add entrypoint for flagos multi-backend plugin system - #3401

Open
lxd-cumt wants to merge 2 commits into
NVIDIA:mainfrom
lxd-cumt:backend_main
Open

Add entrypoint for flagos multi-backend plugin system#3401
lxd-cumt wants to merge 2 commits into
NVIDIA:mainfrom
lxd-cumt:backend_main

Conversation

@lxd-cumt

Copy link
Copy Markdown

FlagOS Proposal: Plugin Architecture & Device-Agnostic Abstraction for TransformerEngine

Plugin System: Initialization-time Backend Loading

We propose a plugin architecture where TransformerEngine (TE) loads backend implementations at initialization time via an explicit plugin interface, while the actual multi-backend plugins reside in a separate repository (TransformerEngine-Plugin-FL).

TransformerEngine-Plugin-FL: https://github.com/lxd-cumt/TransformerEngine-Plugin-FL

Proposed Design

  • TE defines a stable plugin API contract (operator signatures, quantization interfaces, communication primitives).
  • At load_framework_extension() time, if a plugin is present, TE dispatches backend calls through the plugin registry; otherwise it falls back to the native te implementation.
  • The TransformerEngine-Plugin-FL repository is independently installable and contains multiple backend implementations for diverse accelerators, and support more training scenarios.

@lxd-cumt
lxd-cumt requested a review from cyanguwa as a code owner August 19, 2026 08:11
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 19, 2026
Xianduo Li added 2 commits August 19, 2026 16:13
Port plugin system changes from backend_rc2.14:
- common/__init__.py: load plugin after framework extension init
- dot_product_attention.py: override FlashAttention and get_attention_backend when plugin is active

Signed-off-by: Xianduo Li <lixianduo@mail.nankai.edu.cn>
@greptile-apps

greptile-apps Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds initialization-time loading for an explicitly configured PyTorch backend plugin and allows that plugin to replace FlashAttention construction and attention-backend selection.

  • Loads the module named by NVTE_PLUGIN after initializing the native PyTorch extension, exposing the native extension through a transformer_engine_torch_nv alias.
  • Warns and restores the native extension when plugin initialization raises an exception.
  • Uses optional plugin-provided flash_attention and get_attention_backend exports in dot-product attention.

Confidence Score: 4/5

The PR appears safe to merge, with the non-blocking caveat that its new plugin configuration and interface contracts should be documented.

Native behavior is restored when plugin initialization fails, and no concrete incompatible plugin or security-boundary violation was established; the remaining issue is discoverability of the newly introduced public plugin contract.

Files Needing Attention: transformer_engine/common/init.py

Important Files Changed

Filename Overview
transformer_engine/common/init.py Adds memoized import-time plugin loading, a native-extension alias, and warning-based fallback; the new public configuration contract is not documented.
transformer_engine/pytorch/attention/dot_product_attention/dot_product_attention.py Replaces FlashAttention and backend selection with optional extension exports when plugin configuration is present.

Sequence Diagram

sequenceDiagram
  participant App
  participant TE as TransformerEngine
  participant Native as transformer_engine_torch
  participant Plugin as NVTE_PLUGIN module
  participant DPA as DotProductAttention
  App->>TE: import transformer_engine.pytorch
  TE->>Native: load native extension
  TE->>TE: register transformer_engine_torch_nv alias
  TE->>Plugin: import module and call load_plugins()
  alt plugin initialization succeeds
    Plugin-->>TE: install plugin stub/exports
    DPA->>Plugin: resolve flash_attention and get_attention_backend
  else plugin initialization fails
    TE->>TE: restore native extension
    TE-->>App: emit RuntimeWarning
  end
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' of https://github.co..." | Re-trigger Greptile

Comment on lines +198 to +206
_nvte_plugin = os.environ.get("NVTE_PLUGIN")
if _nvte_plugin and framework == "torch":
_original_module = sys.modules.get(module_name)
try:
# Register _nv alias BEFORE importing the plugin, because the
# plugin module may import transformer_engine_torch_nv at top level.
sys.modules[module_name + "_nv"] = solib
_plugin = importlib.import_module(_nvte_plugin)
_plugin.load_plugins()

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.

P2 Document the plugin API contract

NVTE_PLUGIN introduces a user-facing configuration interface, but the required load_plugins(), flash_attention, and get_attention_backend contracts are not documented. Plugin implementers must infer their signatures and return values from source, leaving incompatible implementations to fail through import-time warnings or attention-time exceptions.

Knowledge Base Used:

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ptrendx

ptrendx commented Aug 20, 2026

Copy link
Copy Markdown
Member

/te-ci pytorch

@ptrendx

ptrendx commented Aug 20, 2026

Copy link
Copy Markdown
Member

@lxd-cumt Please fix the lint issue (the one with too broad Exception catch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants