Skip to content

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

Merged
ptrendx merged 4 commits into
NVIDIA:mainfrom
lxd-cumt:backend_main
Sep 9, 2026
Merged

ptrendx merged 4 commits into
NVIDIA:mainfrom
lxd-cumt:backend_main

Conversation

@lxd-cumt

Copy link
Copy Markdown
Contributor

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

RetriggerView in GreptileConfidence Score: 5/5

The changes since the previous review appear safe to merge, with only the existing non-blocking API-documentation concern remaining.

Summary

  • Loads the module named by NVTE_PLUGIN during PyTorch extension initialization.
  • Preserves the native extension under a _nv alias and rolls back module aliases when plugin initialization fails.
  • Dispatches supported attention operations through plugin-provided implementations, with native fallbacks.
  • The latest revision only adds the appropriate pylint suppression to the intentionally broad plugin-initialization exception handler.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Load native framework extension] --> B{Framework is torch and NVTE_PLUGIN is set?}
    B -->|No| C[Use native TransformerEngine extension]
    B -->|Yes| D[Register native extension under _nv alias]
    D --> E[Import configured plugin module]
    E --> F[Call load_plugins]
    F --> G{Plugin exposes attention overrides?}
    G -->|Yes| H[Install FlashAttention and backend-selection overrides]
    G -->|No| C
    E -->|Initialization fails| I[Remove alias and restore native module]
    F -->|Initialization fails| I
    I --> J[Emit RuntimeWarning]
Loading

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 previously approved these changes Aug 20, 2026
@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).

ptrendx and others added 2 commits September 8, 2026 14:25
Signed-off-by: Przemyslaw Tredak <ptrendx@gmail.com>
@ptrendx

ptrendx commented Sep 8, 2026

Copy link
Copy Markdown
Member

/te-ci pytorch

@ptrendx
ptrendx merged commit 7c6fa59 into NVIDIA:main Sep 9, 2026
23 of 28 checks passed
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