Merged
[fix](patch): 先加载 torchtitan.config,修复 CP 循环导入 (#5744) #1238
[fix](patch): 先加载 torchtitan.config,修复 CP 循环导入 (#5744) #1238
Merged
weijinyiAdd on 25 days ago
Total: 1 files changed+10-1
@@ -3,6 +3,9 @@
3# This source code is licensed under the BSD-style license found in the3# This source code is licensed under the BSD-style license found in the
4# LICENSE file in the root directory of this source tree.4# LICENSE file in the root directory of this source tree.
5 5 
6+# The import order below is the patch activation order, not isort's.
7+# ruff: noqa: I001
8+ 
6# torch 2.14 CI compatibility: upstream torchtitan 0.4.0 imports this newer9# torch 2.14 CI compatibility: upstream torchtitan 0.4.0 imports this newer
7# pipelining symbol when ``torchtitan.models.common.dist_moe.runtime`` loads.10# pipelining symbol when ``torchtitan.models.common.dist_moe.runtime`` loads.
8# The NPU eager path never runs pipeline parallel, so install a fail-fast stub11# The NPU eager path never runs pipeline parallel, so install a fail-fast stub
@@ -27,7 +30,13 @@ if not hasattr(_pipelining, "PipelineStageInfo"):
27 _pipelining.PipelineStageInfo = _PipelineStageInfo # pyrefly: ignore [missing-attribute]30 _pipelining.PipelineStageInfo = _PipelineStageInfo # pyrefly: ignore [missing-attribute]
28 31 
29 32 
30-from .components import checkpointer, metrics, optimizer # noqa: F401, I00133+# Upstream #5744: 0.4.0's ``torchtitan.config`` re-exports ``ParallelismConfig``,
34+# so a module that imports ``torchtitan.distributed.context_parallel`` first
35+# re-enters the half-initialized CP module. Loading the package here makes the
36+# entry order stop mattering. Drop it when the pin carries #5744.
37+import torchtitan.config # noqa: F401
38+ 
39+from .components import checkpointer, metrics, optimizer # noqa: F401
31import torchtitan_npu.patches.torchtitan.distributed.checkpoint.filesystem # noqa: F40140import torchtitan_npu.patches.torchtitan.distributed.checkpoint.filesystem # noqa: F401
32 41 
33from . import observability # noqa: F40142from . import observability # noqa: F401