Repository navigation
[dist_moe] Defer optional backend imports - #5066
Merged
Merged
Conversation
The Dist-MoE integration imported the standalone backend while defining its module and config types. This made otherwise generic TorchTitan imports fail once another feature referenced the integration classes. Route backend symbol access through a cached lazy module. Postponed annotations and deferred MXFP8 defaults keep the integration importable, while selecting Dist-MoE still reports the focused installation error and preserves failures from dependencies inside an installed backend. Test Plan: taskset -c 0-7 pytest tests/unit_tests/cpu/test_optional_imports.py tests/unit_tests/cpu/test_transforms.py tests/unit_tests/cpu/test_dist_moe.py -q -k 'not runtime_passes_per_slot_capacity_to_annex and not dist_moe_671b_recipe_topology' Test Plan: env SKIP=pyrefly-check pre-commit run --files tests/unit_tests/cpu/test_optional_imports.py torchtitan/models/common/dist_moe/_optional.py torchtitan/models/common/dist_moe/mxfp8.py torchtitan/models/common/dist_moe/routed_experts.py torchtitan/models/common/dist_moe/runtime.py torchtitan/config/transform/dist_moe.py
jinsooihm
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
October 5, 2026 18:26
fegin
requested changes
Oct 5, 2026
fegin
left a comment
Contributor
There was a problem hiding this comment.
Will the type checking work on a machine without dist_moe? For example, the type checking for lora.py
| @@ -0,0 +1,40 @@ | |||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |||
Contributor
There was a problem hiding this comment.
Merge this file into dist_moe/__init__.py.
Contributor
Author
|
@fegin |
Keep the optional backend proxy next to the Dist-MoE package exports. Define it before the intentionally late child-module imports so those modules can safely read the proxy from the partially initialized package. Test Plan: taskset -c 0-7 pytest tests/unit_tests/cpu/test_optional_imports.py tests/unit_tests/cpu/test_transforms.py tests/unit_tests/cpu/test_dist_moe.py -q -k 'not runtime_passes_per_slot_capacity_to_annex and not dist_moe_671b_recipe_topology' Test Plan: env SKIP=pyrefly-check pre-commit run --files torchtitan/models/common/dist_moe/__init__.py torchtitan/models/common/dist_moe/mxfp8.py torchtitan/models/common/dist_moe/routed_experts.py torchtitan/models/common/dist_moe/runtime.py torchtitan/config/transform/dist_moe.py
fegin
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Dist-MoE integration imported the standalone backend while defining its module and config types. This made otherwise generic TorchTitan imports fail once another feature referenced the integration classes.
Especially problematic for defining relations for transforms #4995, #5007.
Route backend symbol access through a cached lazy module. Postponed annotations and deferred MXFP8 defaults keep the integration importable, while selecting Dist-MoE still reports the focused installation error and preserves failures from dependencies inside an installed backend.
Test Plan: taskset -c 0-7 pytest tests/unit_tests/cpu/test_optional_imports.py tests/unit_tests/cpu/test_transforms.py tests/unit_tests/cpu/test_dist_moe.py -q -k 'not runtime_passes_per_slot_capacity_to_annex and not dist_moe_671b_recipe_topology'
Test Plan: env SKIP=pyrefly-check pre-commit run --files tests/unit_tests/cpu/test_optional_imports.py torchtitan/models/common/dist_moe/_optional.py torchtitan/models/common/dist_moe/mxfp8.py torchtitan/models/common/dist_moe/routed_experts.py torchtitan/models/common/dist_moe/runtime.py torchtitan/config/transform/dist_moe.py