Merged
[fix](patch): 先加载 torchtitan.config,修复 CP 循环导入 (#5744) #1238
weijinyiAdd on 25 days ago
[fix](patch): 先加载 torchtitan.config,修复 CP 循环导入 (#5744) #1238
Merged
Total: 1 files changed+10-1
| @@ -3,6 +3,9 @@ | |||
| 3 | # This source code is licensed under the BSD-style license found in the | 3 | # 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 newer | 9 | # 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 stub | 11 | # 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, I001 | 33 | +# 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 | ||
| 31 | import torchtitan_npu.patches.torchtitan.distributed.checkpoint.filesystem # noqa: F401 | 40 | import torchtitan_npu.patches.torchtitan.distributed.checkpoint.filesystem # noqa: F401 |
| 32 | 41 | ||
| 33 | from . import observability # noqa: F401 | 42 | from . import observability # noqa: F401 |