Add entrypoint for flagos multi-backend plugin system - #3401
Conversation
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>
…to backend_main
Greptile SummaryAdds initialization-time loading for an explicitly configured PyTorch backend plugin and allows that plugin to replace FlashAttention construction and attention-backend selection.
Confidence Score: 4/5The 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
Sequence DiagramsequenceDiagram
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
Reviews (1): Last reviewed commit: "Merge branch 'main' of https://github.co..." | Re-trigger Greptile |
| _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() |
There was a problem hiding this comment.
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!
|
/te-ci pytorch |
|
@lxd-cumt Please fix the lint issue (the one with too broad Exception catch). |
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
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.TransformerEngine-Plugin-FLrepository is independently installable and contains multiple backend implementations for diverse accelerators, and support more training scenarios.