-
Notifications
You must be signed in to change notification settings - Fork 69
[fix] save dist checkpoint for MoE models #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+44
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,10 @@ | |
| from megatron.training.global_vars import get_args | ||
|
|
||
| from vime.utils import megatron_bridge_utils | ||
| from vime.utils.common import is_npu | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| try: | ||
| # Here we patch out the `validate_non_overlapping_shards_metadata` in both functions | ||
|
|
@@ -21,6 +25,7 @@ | |
| from torch.distributed._shard.sharded_tensor.shard import Shard | ||
| from torch.distributed._shard.sharded_tensor.utils import _parse_and_validate_remote_device | ||
| from torch.distributed._shard.sharding_spec.api import EnumerableShardingSpec | ||
| from torch.distributed.checkpoint import default_planner | ||
|
|
||
| def __post_init__(self): | ||
| pass | ||
|
|
@@ -86,10 +91,17 @@ def _init_from_local_shards_and_global_metadata( # type: ignore[override] | |
|
|
||
| ShardedTensor._init_from_local_shards_and_global_metadata = _init_from_local_shards_and_global_metadata | ||
|
|
||
| if is_npu() and hasattr(default_planner, "_validate_global_plan"): | ||
|
|
||
| def patched_validate_global_plan(global_plan, metadata): | ||
| logger.info("[Patch] Skipping validate_access_integrity") | ||
| return True | ||
|
|
||
| default_planner._validate_global_plan = patched_validate_global_plan | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This _validate_global_plan patch is NPU-specific but currently runs unconditionally in shared code, disabling the check on CUDA too. Please guard it with is_npu() |
||
| except ImportError: | ||
| pass | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| __all__ = ["save_checkpoint"] | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This disables
_validate_global_planfor every save/load, not just MoE.Please confirm it is still required after the megatron.patch alone, and paste the failing stack without this patch. Prefer scoping to MoE/experts (or documenting why a global bypass is unavoidable).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only skip the
_validate_sharding_for_keywhen the shardings contains the experts models.ERROR:
megatron.core.dist_checkpointing.core.CheckpointingException: Invalid access pattern for ShardedTensor(key='decoder.layers.mlp.experts.experts.linear_fc1.weight', dtype=torch.float16, local_shape=(768, 2048), glocal_shape=(48, 128, 6144, 2048), global_offset=(0, 0, 0, 0), axis_fragmentations=(48, 128, 8, 1), replica_id=(0, 0, 0), prepend_axis_num=2, allow_shape_mismatch=False, flattened_range=None): tensor([[[[1], [0], [0], ..., [0], [0], [0]], ..., [[0], [0], [0], ..., [0], [0], [1]]]], dtype=torch.int32)